diff --git a/apps/api/src/modules/archived-notifications/archived-notifications.controller.ts b/apps/api/src/modules/archived-notifications/archived-notifications.controller.ts index 9310d76a..acc78ac1 100644 --- a/apps/api/src/modules/archived-notifications/archived-notifications.controller.ts +++ b/apps/api/src/modules/archived-notifications/archived-notifications.controller.ts @@ -1,12 +1,27 @@ -import { Controller, Post } from '@nestjs/common'; +import { Controller, HttpException, Logger, Post } from '@nestjs/common'; import { ArchivedNotificationsService } from './archived-notifications.service'; @Controller('archived-notifications') export class ArchivedNotificationsController { - constructor(private readonly archivedNotificationService: ArchivedNotificationsService) {} + constructor( + private readonly archivedNotificationService: ArchivedNotificationsService, + private logger: Logger, + ) {} @Post('archive') async addNotificationsToQueue(): Promise { - this.archivedNotificationService.archiveCompletedNotificationsCron(); + try { + this.logger.debug('Archiving completed notifications...'); + await this.archivedNotificationService.archiveCompletedNotificationsCron(); + this.logger.log('Notifications archived successfully.'); + } catch (error) { + if (error instanceof HttpException) { + throw error; + } + + this.logger.error('Error while archiving notifications'); + this.logger.error(JSON.stringify(error, ['message', 'stack'], 2)); + throw error; + } } }