Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions apps/api-gateway/src/user/dto/create-user.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, IsOptional, IsString, IsUrl, MaxLength } from 'class-validator';
import { ApiHideProperty, ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsBoolean, IsEmail, IsNotEmpty, IsOptional, IsString, IsUrl, MaxLength } from 'class-validator';
import { toLowerCase, trim } from '@credebl/common/cast.helper';

import { Transform } from 'class-transformer';
Expand Down Expand Up @@ -38,4 +38,9 @@ export class UserEmailVerificationDto {
@IsString({ message: 'clientAlias should be string' })
@Transform(({ value }) => trim(value))
clientAlias?: string;

@ApiHideProperty()
@IsOptional()
@IsBoolean({ message: 'isDefaultVerified should be boolean' })
isDefaultVerified: boolean = false;
}
31 changes: 18 additions & 13 deletions apps/user/src/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class UserService {

async sendVerificationMail(userEmailVerification: ISendVerificationEmail): Promise<user> {
try {
const { email, brandLogoUrl, platformName, clientAlias } = userEmailVerification;
const { email, brandLogoUrl, platformName, clientAlias, isDefaultVerified } = userEmailVerification;

if ('PROD' === process.env.PLATFORM_PROFILE_MODE) {
// eslint-disable-next-line prefer-destructuring
Expand Down Expand Up @@ -150,27 +150,32 @@ export class UserService {
if (!redirectUrl) {
throw new NotFoundException(ResponseMessages.user.error.redirectUrlNotFound);
}

sendVerificationMail = await this.sendEmailForVerification({
email,
verificationCode: verifyCode,
redirectUrl,
clientId: clientDetails.clientId,
brandLogoUrl,
platformName,
redirectTo: clientDetails.domain,
clientAlias
});
if (!isDefaultVerified) {
sendVerificationMail = await this.sendEmailForVerification({
email,
verificationCode: verifyCode,
redirectUrl,
clientId: clientDetails.clientId,
brandLogoUrl,
platformName,
redirectTo: clientDetails.domain,
clientAlias
});
}
} catch (error) {
throw new InternalServerErrorException(ResponseMessages.user.error.emailSend);
}

if (sendVerificationMail) {
if (sendVerificationMail || isDefaultVerified) {
const uniqueUsername = await this.createUsername(email, verifyCode);
userEmailVerification.username = uniqueUsername;
userEmailVerification.clientId = clientDetails.clientId;
userEmailVerification.clientSecret = clientDetails.clientSecret;
const resUser = await this.userRepository.createUser(userEmailVerification, verifyCode);
if (isDefaultVerified) {
this.logger.debug('In isDefaultVerified block');
await this.verifyEmail({ email, verificationCode: verifyCode });
}
return resUser;
}
} catch (error) {
Expand Down
1 change: 1 addition & 0 deletions libs/common/src/interfaces/user.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface ISendVerificationEmail {
platformName?: string;
redirectTo?: string;
clientAlias?: string;
isDefaultVerified?: boolean;
}

export interface IClientDetailsSSO {
Expand Down