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')
|
@Post('test-push')
|
||||||
@HttpCode(HttpStatus.OK)
|
@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' })
|
@ApiResponse({ status: 200, description: 'Test notification sent' })
|
||||||
async sendTestPush(@CurrentUser('id') userId: string) {
|
async sendTestPush(
|
||||||
await this.notificationsService.sendTestPushNotification(userId);
|
@Body() dto: { userId: string; title?: string; body?: string },
|
||||||
|
) {
|
||||||
|
await this.notificationsService.sendTestPushNotification(
|
||||||
|
dto.userId,
|
||||||
|
dto.title,
|
||||||
|
dto.body,
|
||||||
|
);
|
||||||
return { message: 'Test push notification sent' };
|
return { message: 'Test push notification sent' };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -323,6 +323,23 @@ export class NotificationsService implements OnModuleInit {
|
|||||||
body: payload.body,
|
body: payload.body,
|
||||||
},
|
},
|
||||||
data: payload.data || {},
|
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: {
|
webpush: {
|
||||||
fcmOptions: {
|
fcmOptions: {
|
||||||
link: payload.data?.link || '/',
|
link: payload.data?.link || '/',
|
||||||
@@ -375,7 +392,11 @@ export class NotificationsService implements OnModuleInit {
|
|||||||
// TEST PUSH NOTIFICATION
|
// 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({
|
const user = await this.prisma.user.findUnique({
|
||||||
where: { id: userId },
|
where: { id: userId },
|
||||||
select: { fcmTokens: true },
|
select: { fcmTokens: true },
|
||||||
@@ -393,8 +414,8 @@ export class NotificationsService implements OnModuleInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await this.sendPushNotification(userId, user, {
|
await this.sendPushNotification(userId, user, {
|
||||||
title: 'Test Notification 🔔',
|
title: title || 'Test Notification 🔔',
|
||||||
body: 'This is a test push notification from RE-Quest!',
|
body: body || 'This is a test push notification from RE-Quest!',
|
||||||
data: { type: 'test', link: '/' },
|
data: { type: 'test', link: '/' },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user