From 0abfa51ed95891cdeb18c61cfe0054a170d972b2 Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Fri, 27 Mar 2026 14:49:46 +0530 Subject: [PATCH] feat: Add Android and APNS notification options and allow specifying target user, title, and body for test push notifications. --- src/notifications/notifications.controller.ts | 12 ++++++--- src/notifications/notifications.service.ts | 27 ++++++++++++++++--- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/notifications/notifications.controller.ts b/src/notifications/notifications.controller.ts index 2fa86a8..3debac0 100644 --- a/src/notifications/notifications.controller.ts +++ b/src/notifications/notifications.controller.ts @@ -91,10 +91,16 @@ export class NotificationsController { @Post('test-push') @HttpCode(HttpStatus.OK) - @ApiOperation({ summary: 'Send a test push notification to the current user' }) + @ApiOperation({ summary: 'Send a test push notification to a specific user (Admin)' }) @ApiResponse({ status: 200, description: 'Test notification sent' }) - async sendTestPush(@CurrentUser('id') userId: string) { - await this.notificationsService.sendTestPushNotification(userId); + async sendTestPush( + @Body() dto: { userId: string; title?: string; body?: string }, + ) { + await this.notificationsService.sendTestPushNotification( + dto.userId, + dto.title, + dto.body, + ); return { message: 'Test push notification sent' }; } diff --git a/src/notifications/notifications.service.ts b/src/notifications/notifications.service.ts index a93b7a8..e849909 100644 --- a/src/notifications/notifications.service.ts +++ b/src/notifications/notifications.service.ts @@ -323,6 +323,23 @@ export class NotificationsService implements OnModuleInit { body: payload.body, }, data: payload.data || {}, + android: { + priority: 'high', + notification: { + channelId: 'high_importance_channel', + priority: 'high', + defaultSound: true, + defaultVibrateTimings: true, + }, + }, + apns: { + payload: { + aps: { + sound: 'default', + badge: 1, + }, + }, + }, webpush: { fcmOptions: { link: payload.data?.link || '/', @@ -375,7 +392,11 @@ export class NotificationsService implements OnModuleInit { // TEST PUSH NOTIFICATION // ========================================== - async sendTestPushNotification(userId: string): Promise { + async sendTestPushNotification( + userId: string, + title?: string, + body?: string, + ): Promise { const user = await this.prisma.user.findUnique({ where: { id: userId }, select: { fcmTokens: true }, @@ -393,8 +414,8 @@ export class NotificationsService implements OnModuleInit { } await this.sendPushNotification(userId, user, { - title: 'Test Notification 🔔', - body: 'This is a test push notification from RE-Quest!', + title: title || 'Test Notification 🔔', + body: body || 'This is a test push notification from RE-Quest!', data: { type: 'test', link: '/' }, });