From 924b03f459e37a6cfa3256163bb54eadab2a80ae Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Thu, 26 Mar 2026 11:22:30 +0530 Subject: [PATCH] feat: Implement endpoint and service method for sending test push notifications. --- src/notifications/notifications.controller.ts | 13 ++++++++ src/notifications/notifications.service.ts | 30 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/notifications/notifications.controller.ts b/src/notifications/notifications.controller.ts index 2479fe3..2fa86a8 100644 --- a/src/notifications/notifications.controller.ts +++ b/src/notifications/notifications.controller.ts @@ -85,6 +85,19 @@ export class NotificationsController { return null; } + // ========================================== + // TEST PUSH NOTIFICATION + // ========================================== + + @Post('test-push') + @HttpCode(HttpStatus.OK) + @ApiOperation({ summary: 'Send a test push notification to the current user' }) + @ApiResponse({ status: 200, description: 'Test notification sent' }) + async sendTestPush(@CurrentUser('id') userId: string) { + await this.notificationsService.sendTestPushNotification(userId); + return { message: 'Test push notification sent' }; + } + // ========================================== // FCM TOKEN MANAGEMENT // ========================================== diff --git a/src/notifications/notifications.service.ts b/src/notifications/notifications.service.ts index 82f97ec..a93b7a8 100644 --- a/src/notifications/notifications.service.ts +++ b/src/notifications/notifications.service.ts @@ -371,6 +371,36 @@ export class NotificationsService implements OnModuleInit { } } + // ========================================== + // TEST PUSH NOTIFICATION + // ========================================== + + async sendTestPushNotification(userId: string): Promise { + const user = await this.prisma.user.findUnique({ + where: { id: userId }, + select: { fcmTokens: true }, + }); + + if (!user) { + this.logger.warn(`Test push: user ${userId} not found`); + return; + } + + const tokens = this.parseFcmTokens(user.fcmTokens); + if (tokens.length === 0) { + this.logger.warn(`Test push: no FCM tokens for user ${userId}`); + return; + } + + await this.sendPushNotification(userId, user, { + title: 'Test Notification 🔔', + body: 'This is a test push notification from RE-Quest!', + data: { type: 'test', link: '/' }, + }); + + this.logger.log(`Test push notification sent to user ${userId}`); + } + // ========================================== // EVENT LISTENERS // ==========================================