feat: Implement endpoint and service method for sending test push notifications.

This commit is contained in:
pradeepkumar
2026-03-26 11:22:30 +05:30
parent ddc9c0caaa
commit 924b03f459
2 changed files with 43 additions and 0 deletions

View File

@@ -85,6 +85,19 @@ export class NotificationsController {
return null; 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 // FCM TOKEN MANAGEMENT
// ========================================== // ==========================================

View File

@@ -371,6 +371,36 @@ export class NotificationsService implements OnModuleInit {
} }
} }
// ==========================================
// TEST PUSH NOTIFICATION
// ==========================================
async sendTestPushNotification(userId: string): Promise<void> {
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 // EVENT LISTENERS
// ========================================== // ==========================================