feat: Add Android and APNS notification options and allow specifying target user, title, and body for test push notifications.
This commit is contained in:
@@ -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' };
|
||||
}
|
||||
|
||||
|
||||
@@ -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<void> {
|
||||
async sendTestPushNotification(
|
||||
userId: string,
|
||||
title?: string,
|
||||
body?: string,
|
||||
): Promise<void> {
|
||||
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: '/' },
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user