mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-16 12:33:17 +00:00
add error handling for db calls
This commit is contained in:
@@ -21,8 +21,9 @@ export class UsersService {
|
||||
return await this.usersRepository.deleteUserById(id)
|
||||
}
|
||||
|
||||
async deleteAllUsers(): Promise<boolean> {
|
||||
return await this.usersRepository.deleteAllUsers()
|
||||
async deleteAllUsers(): Promise<{ deleted: number }> {
|
||||
const deleted = await this.usersRepository.deleteAllUsers()
|
||||
return { deleted }
|
||||
}
|
||||
|
||||
public async sendConfirmationEmail({
|
||||
@@ -42,6 +43,27 @@ export class UsersService {
|
||||
html: `<b>Hello ${name}!</b><br/>Please confirm your email by clicking on the link below:<br/><a href="http://localhost:3000/confirm-email/${verificationToken}">Confirm email</a>`,
|
||||
subject: 'E-mail confirmation',
|
||||
})
|
||||
} catch (e) {
|
||||
this.logger.error(e?.message || e)
|
||||
}
|
||||
}
|
||||
|
||||
public async sendPasswordRecoveryEmail({
|
||||
email,
|
||||
name,
|
||||
passwordRecoveryToken,
|
||||
}: {
|
||||
email: string
|
||||
name: string
|
||||
passwordRecoveryToken: string
|
||||
}) {
|
||||
try {
|
||||
await this.emailService.sendMail({
|
||||
from: 'Andrii <andrii@andrii.es>',
|
||||
to: email,
|
||||
html: `<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} `,
|
||||
subject: 'Password recovery',
|
||||
})
|
||||
} catch (e) {
|
||||
this.logger.error(e)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user