|
1 | | -import { BadRequestException, Injectable } from '@nestjs/common'; |
| 1 | +import { BadRequestException, Injectable, Logger } from '@nestjs/common'; |
2 | 2 | import { InjectRepository } from '@nestjs/typeorm'; |
3 | 3 | import { Cohort } from '@/entities/cohort.entity'; |
4 | 4 | import { Repository } from 'typeorm'; |
@@ -26,10 +26,11 @@ import { CohortWaitlist } from '@/entities/cohort-waitlist.entity'; |
26 | 26 | import { APITask } from '@/entities/api-task.entity'; |
27 | 27 | import { TaskType } from '@/task-processor/task.enums'; |
28 | 28 | import { MailService } from '@/mail/mail.service'; |
29 | | -import { formatDate } from '@/utils/data.utils'; |
30 | 29 |
|
31 | 30 | @Injectable() |
32 | 31 | export class CohortsService { |
| 32 | + private readonly logger = new Logger(CohortsService.name); |
| 33 | + |
33 | 34 | private readonly masteringBitcoinDiscordRoleId: string; |
34 | 35 | private readonly learningBitcoinFromCommandLineDiscordRoleId: string; |
35 | 36 | private readonly programmingBitcoinDiscordRoleId: string; |
@@ -444,14 +445,21 @@ export class CohortsService { |
444 | 445 | user.name || user.discordGlobalName || user.discordUserName; |
445 | 446 | const classroomUrl = cohort.weeks[0]?.classroomUrl || undefined; |
446 | 447 |
|
447 | | - await this.mailService.sendCohortJoiningConfirmationEmail( |
448 | | - user.email, |
449 | | - userName, |
450 | | - cohort.type, |
451 | | - cohort.startDate, |
452 | | - cohort.endDate, |
453 | | - classroomUrl, |
454 | | - ); |
| 448 | + try { |
| 449 | + await this.mailService.sendCohortJoiningConfirmationEmail( |
| 450 | + user.email, |
| 451 | + userName, |
| 452 | + cohort.type, |
| 453 | + cohort.startDate, |
| 454 | + cohort.endDate, |
| 455 | + classroomUrl, |
| 456 | + ); |
| 457 | + } catch (error) { |
| 458 | + this.logger.error( |
| 459 | + `Failed to send cohort joining confirmation email to user ${user.id}: ${error.message}`, |
| 460 | + error.stack, |
| 461 | + ); |
| 462 | + } |
455 | 463 | } |
456 | 464 |
|
457 | 465 | async joinCohortWaitlist( |
@@ -482,12 +490,19 @@ export class CohortsService { |
482 | 490 |
|
483 | 491 | await this.cohortWaitlistRepository.save(waitlistEntry); |
484 | 492 |
|
485 | | - // Send welcome email to the user |
486 | | - await this.mailService.sendWelcomeToWaitlistEmail( |
487 | | - user.email, |
488 | | - user.name || user.discordGlobalName || user.discordUserName, |
489 | | - body.type, |
490 | | - ); |
| 493 | + try { |
| 494 | + // Send welcome email to the user |
| 495 | + await this.mailService.sendWelcomeToWaitlistEmail( |
| 496 | + user.email, |
| 497 | + user.name || user.discordGlobalName || user.discordUserName, |
| 498 | + body.type, |
| 499 | + ); |
| 500 | + } catch (error) { |
| 501 | + this.logger.error( |
| 502 | + `Failed to send welcome to waitlist email to user ${user.id}: ${error.message}`, |
| 503 | + error.stack, |
| 504 | + ); |
| 505 | + } |
491 | 506 | } |
492 | 507 |
|
493 | 508 | async getUserWaitlist(user: User): Promise<UserCohortWaitlistResponseDto> { |
|
0 commit comments