feat: Implement endpoint and service method for sending test push notifications.
This commit is contained in:
@@ -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
|
||||
// ==========================================
|
||||
|
||||
@@ -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
|
||||
// ==========================================
|
||||
|
||||
Reference in New Issue
Block a user