mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-17 12:33:22 +00:00
fix: correct type for maxCardsCount and minCardsCount
fix: correct default html for password recovery
This commit is contained in:
@@ -1,15 +1,20 @@
|
|||||||
import { ApiHideProperty } from '@nestjs/swagger'
|
import { ApiHideProperty } from '@nestjs/swagger'
|
||||||
import { IsUUID } from 'class-validator'
|
import { Type } from 'class-transformer'
|
||||||
|
import { IsNumber, IsOptional, IsUUID } from 'class-validator'
|
||||||
|
|
||||||
import { PaginationDto } from '../../../infrastructure/common/pagination/pagination.dto'
|
import { PaginationDto } from '../../../infrastructure/common/pagination/pagination.dto'
|
||||||
import { IsOptionalOrEmptyString, IsOrderBy } from '../../../infrastructure/decorators'
|
import { IsOptionalOrEmptyString, IsOrderBy } from '../../../infrastructure/decorators'
|
||||||
|
|
||||||
export class GetAllDecksDto extends PaginationDto {
|
export class GetAllDecksDto extends PaginationDto {
|
||||||
@IsOptionalOrEmptyString()
|
@IsOptional()
|
||||||
minCardsCount?: string
|
@Type(() => Number)
|
||||||
|
@IsNumber()
|
||||||
|
minCardsCount?: number
|
||||||
|
|
||||||
@IsOptionalOrEmptyString()
|
@IsOptional()
|
||||||
maxCardsCount?: string
|
@Type(() => Number)
|
||||||
|
@IsNumber()
|
||||||
|
maxCardsCount?: number
|
||||||
|
|
||||||
/** Search by deck name */
|
/** Search by deck name */
|
||||||
@IsOptionalOrEmptyString()
|
@IsOptionalOrEmptyString()
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ import { UsersRepository } from '../infrastructure/users.repository'
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UsersService {
|
export class UsersService {
|
||||||
constructor(private usersRepository: UsersRepository, private emailService: MailerService) {}
|
constructor(
|
||||||
|
private usersRepository: UsersRepository,
|
||||||
|
private emailService: MailerService
|
||||||
|
) {}
|
||||||
|
|
||||||
private logger = new Logger(UsersService.name)
|
private logger = new Logger(UsersService.name)
|
||||||
|
|
||||||
@@ -32,7 +35,7 @@ export class UsersService {
|
|||||||
email,
|
email,
|
||||||
name,
|
name,
|
||||||
verificationToken,
|
verificationToken,
|
||||||
html = `<b>Hello, ##name##!</b><br/>Please confirm your email by clicking on the link below:<br/><a href="http://localhost:3000/confirm-email/##token##">Confirm email</a>. If it doesn't work, copy and paste the following link in your browser:<br/>http://localhost:3000/confirm-email/##token##`,
|
html,
|
||||||
subject = 'E-mail confirmation',
|
subject = 'E-mail confirmation',
|
||||||
}: {
|
}: {
|
||||||
email: string
|
email: string
|
||||||
@@ -41,7 +44,11 @@ export class UsersService {
|
|||||||
html?: string
|
html?: string
|
||||||
subject?: string
|
subject?: string
|
||||||
}) {
|
}) {
|
||||||
const htmlFinal = html.replaceAll('##token##', verificationToken)?.replaceAll('##name##', name)
|
const htmlFinal = this.prepareHtml(
|
||||||
|
html ?? this.defaultConfirmationHtml,
|
||||||
|
name,
|
||||||
|
verificationToken
|
||||||
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.emailService.sendMail({
|
await this.emailService.sendMail({
|
||||||
@@ -70,9 +77,11 @@ export class UsersService {
|
|||||||
subject?: string
|
subject?: string
|
||||||
passwordRecoveryToken: string
|
passwordRecoveryToken: string
|
||||||
}) {
|
}) {
|
||||||
const htmlFinal =
|
const htmlFinal = this.prepareHtml(
|
||||||
html?.replace('##token##', passwordRecoveryToken)?.replace('##name##', name) ||
|
html ?? this.defaultRecoveryHtml,
|
||||||
`<b>Hello ${name}!</b><br/>To recover your password follow this link:<br/><a href="http://localhost:3000/confirm-email/${passwordRecoveryToken}">Confirm email</a>. If it doesn't work, copy and paste the following link in your browser:<br/>http://localhost:3000/confirm-email/${passwordRecoveryToken} `
|
name,
|
||||||
|
passwordRecoveryToken
|
||||||
|
)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.emailService.sendMail({
|
await this.emailService.sendMail({
|
||||||
@@ -91,4 +100,28 @@ export class UsersService {
|
|||||||
public async generateHash(password: string) {
|
public async generateHash(password: string) {
|
||||||
return await bcrypt.hash(password, 10)
|
return await bcrypt.hash(password, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private prepareHtml(html: string, name: string, token: string) {
|
||||||
|
return html.replaceAll('##token##', token)?.replaceAll('##name##', name)
|
||||||
|
}
|
||||||
|
|
||||||
|
private defaultConfirmationHtml = `
|
||||||
|
<b>Hello, ##name##!</b>
|
||||||
|
<br/>
|
||||||
|
Please confirm your email by clicking on the link below:
|
||||||
|
<br/>
|
||||||
|
<a href="http://localhost:3000/confirm-email/##token##">Confirm email</a>.
|
||||||
|
If it doesn't work, copy and paste the following link in your browser:
|
||||||
|
<br/>
|
||||||
|
http://localhost:3000/confirm-email/##token##`
|
||||||
|
|
||||||
|
private defaultRecoveryHtml = `
|
||||||
|
<b>Hello, ##name##!</b>
|
||||||
|
<br/>
|
||||||
|
To recover your password follow the link below:
|
||||||
|
<br/>
|
||||||
|
<a href="http://localhost:3000/recover-password/##token##">Recover password</a>.
|
||||||
|
If it doesn't work, copy and paste the following link in your browser:
|
||||||
|
<br/>
|
||||||
|
http://localhost:3000/recover-password/##token##`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user