Skip to content

Commit

Permalink
worked on the eslint issues (#117)
Browse files Browse the repository at this point in the history
Signed-off-by: Nishad <[email protected]>
  • Loading branch information
nishad-ayanworks authored and KulkarniShashank committed Sep 10, 2024
1 parent 2e9e15e commit 0f8131c
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 2 deletions.
28 changes: 28 additions & 0 deletions apps/api-gateway/src/ecosystem/dtos/send-invitation.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ApiExtraModels, ApiProperty } from '@nestjs/swagger';
import { IsArray, IsEmail, IsNotEmpty, IsString, ValidateNested } from 'class-validator';
import { Transform, Type } from 'class-transformer';

import { trim } from '@credebl/common/cast.helper';

@ApiExtraModels()
export class EcosystemInvitationDto {

@ApiProperty({ example: '[email protected]' })
@IsEmail()
@Transform(({ value }) => trim(value))
@IsNotEmpty({ message: 'Please provide valid email' })
@IsString({ message: 'email should be string' })
email: string;

}

@ApiExtraModels()
export class BulkEcosystemInvitationDto {

@ApiProperty({ type: [EcosystemInvitationDto] })
@IsArray()
@ValidateNested({ each: true })
@Type(() => EcosystemInvitationDto)
invitations: EcosystemInvitationDto[];
ecosystemId: string;
}
33 changes: 33 additions & 0 deletions apps/api-gateway/src/ecosystem/ecosystem.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,38 @@ export class EcosystemController {
return res.status(HttpStatus.CREATED).json(finalResponse);
}


/**
*
* @param bulkInvitationDto
* @param ecosystemId
* @param user
* @param res
* @returns Ecosystem invitation send details
*/
@Post('/:ecosystemId/invitations')
@ApiOperation({
summary: 'Send ecosystem invitation',
description: 'Send ecosystem invitation'
})
@ApiResponse({ status: 201, description: 'Success', type: ApiResponseDto })
@UseGuards(AuthGuard('jwt'))
@ApiBearerAuth()
async createInvitation(@Body() bulkInvitationDto: BulkEcosystemInvitationDto, @Param('ecosystemId') ecosystemId: string, @User() user: user, @Res() res: Response): Promise<Response> {

bulkInvitationDto.ecosystemId = ecosystemId;
await this.ecosystemService.createInvitation(bulkInvitationDto, String(user.id));

const finalResponse: IResponseType = {
statusCode: HttpStatus.CREATED,
message: ResponseMessages.ecosystem.success.createInvitation
};

return res.status(HttpStatus.CREATED).json(finalResponse);

}


@Put('/:ecosystemId/')
@ApiOperation({ summary: 'Edit ecosystem', description: 'Edit existing ecosystem' })
@ApiResponse({ status: 201, description: 'Success', type: ApiResponseDto })
Expand All @@ -113,4 +145,5 @@ export class EcosystemController {
};
return res.status(HttpStatus.CREATED).json(finalResponse);
}

}
13 changes: 13 additions & 0 deletions apps/api-gateway/src/ecosystem/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,18 @@ export class EcosystemService extends BaseService {
async getAllEcosystem(): Promise<{ response: object }> {
return this.sendNats(this.serviceProxy, 'get-all-ecosystem', '');
}


/**
*
* @param bulkInvitationDto
* @param userId
* @returns
*/
async createInvitation(bulkInvitationDto: BulkEcosystemInvitationDto, userId: string): Promise<object> {
const payload = { bulkInvitationDto, userId };
return this.sendNats(this.serviceProxy, 'send-ecosystem-invitation', payload);
}


}
12 changes: 12 additions & 0 deletions apps/ecosystem/dtos/send-invitation.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ApiExtraModels } from '@nestjs/swagger';

@ApiExtraModels()
export class SendInvitationDto {
email: string;
}

@ApiExtraModels()
export class BulkSendInvitationDto {
invitations: SendInvitationDto[];
ecosystemId: string;
}
6 changes: 6 additions & 0 deletions apps/ecosystem/enums/ecosystem.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ export enum EcosystemRoles {

export enum EcosystemOrgStatus {
ACTIVE = 'ACTIVE'
}

export enum EcosystemInvitationStatus {
ACCEPTED = 'accepted',
REJECTED = 'rejected',
PENDING = 'pending'
}
14 changes: 14 additions & 0 deletions apps/ecosystem/src/ecosystem.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Controller, Logger } from '@nestjs/common';
import { MessagePattern } from '@nestjs/microservices';
import { EcosystemService } from './ecosystem.service';
import { Body } from '@nestjs/common';
import { BulkSendInvitationDto } from '../dtos/send-invitation.dto';

@Controller()
export class EcosystemController {
Expand Down Expand Up @@ -39,5 +40,18 @@ export class EcosystemController {
async getAllEcosystems(): Promise<object> {
return this.ecosystemService.getAllEcosystem();
}


/**
*
* @param payload
* @returns Sent ecosystem invitations status
*/
@MessagePattern({ cmd: 'send-ecosystem-invitation' })
async createInvitation(
@Body() payload: { bulkInvitationDto: BulkSendInvitationDto; userId: string }
): Promise<string> {
return this.ecosystemService.createInvitation(payload.bulkInvitationDto, payload.userId);
}

}
5 changes: 3 additions & 2 deletions apps/ecosystem/src/ecosystem.repository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Injectable, InternalServerErrorException, Logger } from '@nestjs/common';
import { PrismaService } from '@credebl/prisma-service';
import { ecosystem } from '@prisma/client';
import {EcosystemOrgStatus, EcosystemRoles} from '../enums/ecosystem.enum';
// eslint-disable-next-line camelcase
import { ecosystem, ecosystem_invitations } from '@prisma/client';
import {EcosystemInvitationStatus, EcosystemOrgStatus, EcosystemRoles} from '../enums/ecosystem.enum';
// eslint-disable-next-line camelcase
@Injectable()
export class EcosystemRepository {
Expand Down
92 changes: 92 additions & 0 deletions apps/ecosystem/src/ecosystem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,96 @@ export class EcosystemService {
}
return getAllEcosystemDetails;
}


/**
*
* @param bulkInvitationDto
* @param userId
* @returns
*/
async createInvitation(bulkInvitationDto: BulkSendInvitationDto, userId: string): Promise<string> {
const { invitations, ecosystemId } = bulkInvitationDto;

try {
const ecosystemDetails = await this.ecosystemRepository.getEcosystemDetails(ecosystemId);

for (const invitation of invitations) {
const { email } = invitation;

const isInvitationExist = await this.checkInvitationExist(email, ecosystemId);

if (!isInvitationExist) {
await this.ecosystemRepository.createSendInvitation(email, ecosystemId, userId);

try {
await this.sendInviteEmailTemplate(email, ecosystemDetails.name);
} catch (error) {
throw new InternalServerErrorException(ResponseMessages.user.error.emailSend);
}
}
}
return ResponseMessages.ecosystem.success.createInvitation;
} catch (error) {
this.logger.error(`In send Invitation : ${JSON.stringify(error)}`);
throw new RpcException(error.response ? error.response : error);
}
}


/**
*
* @param email
* @param ecosystemId
* @returns Returns boolean status for invitation
*/
async checkInvitationExist(
email: string,
ecosystemId: string
): Promise<boolean> {
try {

const query = {
email,
ecosystemId
};

const invitations = await this.ecosystemRepository.getEcosystemInvitations(query);

if (0 < invitations.length) {
return true;
}
return false;
} catch (error) {
throw new RpcException(error.response ? error.response : error);
}
}

/**
*
* @param email
* @param ecosystemName
* @returns Send invitation mail
*/
async sendInviteEmailTemplate(
email: string,
ecosystemName: string
): Promise<boolean> {
const platformConfigData = await this.prisma.platform_config.findMany();

const urlEmailTemplate = new EcosystemInviteTemplate();
const emailData = new EmailDto();
emailData.emailFrom = platformConfigData[0].emailFrom;
emailData.emailTo = email;
emailData.emailSubject = `${process.env.PLATFORM_NAME} Platform: Invitation`;

emailData.emailHtml = await urlEmailTemplate.sendInviteEmailTemplate(email, ecosystemName);

//Email is sent to user for the verification through emailData
const isEmailSent = await sendEmail(emailData);

return isEmailSent;
}


}
66 changes: 66 additions & 0 deletions apps/ecosystem/templates/EcosystemInviteTemplate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
export class EcosystemInviteTemplate {

public sendInviteEmailTemplate(
email: string,
ecosystemName: string
): string {

const validUrl = `${process.env.FRONT_END_URL}/authentication/sign-in`;

const message = `You have been invited to join the ecosystem so please log in and accept the ecosystem “INVITATION” and participate in the ecosystem`;
const year: number = new Date().getFullYear();

return `<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body style="margin: 0px; padding:0px; background-color:#F9F9F9;">
<div style="margin: auto; width: 40%; padding: 20px 30px; background-color: #FFFFFF; display:block; word-break: break-word;">
<div style="font-family: Montserrat; font-style: normal; font-weight: 500;
font-size: 15px; line-height: 24px;color: #5E5873;">
<p style="margin-top:0px">
Hello ${email},
</p>
<p>
Congratulations!
Your have been successfully invited to join.
<ul style="color:#005EFF; padding-left:10px; font-family: Montserrat;font-style: normal;
font-weight: normal;font-size: 14px;line-height: 21px;">
<li>Ecosystem: ${ecosystemName}</li>
</ul>
${message}
<ul style="color:#005EFF; padding-left:10px; font-family: Montserrat;font-style: normal;
font-weight: normal;font-size: 14px;line-height: 21px;">
<li>Platform Link: <a href="${validUrl}">${validUrl}</a></li>
</ul>
<div style="text-align: center; padding-bottom: 20px;">
<a href="${validUrl}"
style="padding: 10px 20px 10px 20px;color: #fff;background: #1F4EAD;border-radius: 5px;text-decoration: none;">
INVITATION
</a>
</div>
<p>In case you need any assistance to access your account, please contact <a href="https://credebl.in/"
target="_blank">CREDEBL Platform</a>
</p>
<hr style="border-top:1px solid #e8e8e8" />
<footer style="padding-top: 20px;">
<p style="margin-top: 2px;">
&reg; CREDEBL ${year}, Powered by Blockster Labs. All Rights Reserved.
</p>
</footer>
</div>
</div>
</body>
</html>`;

}


}

0 comments on commit 0f8131c

Please sign in to comment.