From c1fa1f4aab6c10bba010f2d5d5b53e94bf18de7b Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Thu, 5 Mar 2026 05:41:43 +0530 Subject: [PATCH] feat: Dynamically set notification action URLs based on user role and specify agent network link for connection requests. --- src/notifications/notifications.service.ts | 26 ++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/notifications/notifications.service.ts b/src/notifications/notifications.service.ts index e6d5615..cda52e5 100644 --- a/src/notifications/notifications.service.ts +++ b/src/notifications/notifications.service.ts @@ -328,6 +328,18 @@ export class NotificationsService implements OnModuleInit { // EVENT LISTENERS // ========================================== + /** + * Resolve role-based route prefix for a user. + * Agents use /agent/..., regular users use /user/... + */ + private async getRoutePrefix(userId: string): Promise { + const user = await this.prisma.user.findUnique({ + where: { id: userId }, + select: { role: true }, + }); + return user?.role === 'AGENT' ? '/agent' : '/user'; + } + @OnEvent('notification.message') async handleMessageNotification(event: { recipientUserId: string; @@ -335,17 +347,20 @@ export class NotificationsService implements OnModuleInit { messagePreview: string; conversationId: string; }) { + const prefix = await this.getRoutePrefix(event.recipientUserId); + const actionUrl = `${prefix}/message?conversation=${event.conversationId}`; + await this.createAndSendNotification( event.recipientUserId, 'message', `New message from ${event.senderName}`, event.messagePreview || 'You have a new message', 'message_updates', - `/messages?conversation=${event.conversationId}`, + actionUrl, { type: 'message', conversationId: event.conversationId, - link: `/messages?conversation=${event.conversationId}`, + link: actionUrl, }, ); } @@ -356,17 +371,20 @@ export class NotificationsService implements OnModuleInit { senderName: string; connectionRequestId: string; }) { + // Connection requests are always sent to agents + const actionUrl = '/agent/network'; + await this.createAndSendNotification( event.recipientUserId, 'request', 'New Connection Request', `${event.senderName} wants to connect with you`, 'new_lead_alerts', - '/dashboard/connections', + actionUrl, { type: 'connection_request', connectionRequestId: event.connectionRequestId, - link: '/dashboard/connections', + link: actionUrl, }, ); }