feat: Implement endpoint and service method for sending test push notifications.
This commit is contained in:
@@ -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