feat: Dynamically set notification action URLs based on user role and specify agent network link for connection requests.
This commit is contained in:
@@ -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<string> {
|
||||
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,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user