feat: Dynamically set notification action URLs based on user role and specify agent network link for connection requests.

This commit is contained in:
pradeepkumar
2026-03-05 05:41:43 +05:30
parent 87671ce8b6
commit c1fa1f4aab

View File

@@ -328,6 +328,18 @@ export class NotificationsService implements OnModuleInit {
// EVENT LISTENERS // EVENT LISTENERS
// ========================================== // ==========================================
/**
* Resolve role-based route prefix for a user.
* Agents use /agent/..., regular users use /user/...
*/
private async getRoutePrefix(userId: string): Promise<string> {
const user = await this.prisma.user.findUnique({
where: { id: userId },
select: { role: true },
});
return user?.role === 'AGENT' ? '/agent' : '/user';
}
@OnEvent('notification.message') @OnEvent('notification.message')
async handleMessageNotification(event: { async handleMessageNotification(event: {
recipientUserId: string; recipientUserId: string;
@@ -335,17 +347,20 @@ export class NotificationsService implements OnModuleInit {
messagePreview: string; messagePreview: string;
conversationId: string; conversationId: string;
}) { }) {
const prefix = await this.getRoutePrefix(event.recipientUserId);
const actionUrl = `${prefix}/message?conversation=${event.conversationId}`;
await this.createAndSendNotification( await this.createAndSendNotification(
event.recipientUserId, event.recipientUserId,
'message', 'message',
`New message from ${event.senderName}`, `New message from ${event.senderName}`,
event.messagePreview || 'You have a new message', event.messagePreview || 'You have a new message',
'message_updates', 'message_updates',
`/messages?conversation=${event.conversationId}`, actionUrl,
{ {
type: 'message', type: 'message',
conversationId: event.conversationId, conversationId: event.conversationId,
link: `/messages?conversation=${event.conversationId}`, link: actionUrl,
}, },
); );
} }
@@ -356,17 +371,20 @@ export class NotificationsService implements OnModuleInit {
senderName: string; senderName: string;
connectionRequestId: string; connectionRequestId: string;
}) { }) {
// Connection requests are always sent to agents
const actionUrl = '/agent/network';
await this.createAndSendNotification( await this.createAndSendNotification(
event.recipientUserId, event.recipientUserId,
'request', 'request',
'New Connection Request', 'New Connection Request',
`${event.senderName} wants to connect with you`, `${event.senderName} wants to connect with you`,
'new_lead_alerts', 'new_lead_alerts',
'/dashboard/connections', actionUrl,
{ {
type: 'connection_request', type: 'connection_request',
connectionRequestId: event.connectionRequestId, connectionRequestId: event.connectionRequestId,
link: '/dashboard/connections', link: actionUrl,
}, },
); );
} }