mention feature added

This commit is contained in:
laxmanhalaki 2025-11-10 20:11:24 +05:30
parent 8c7965e469
commit 54ecae5b7b
2 changed files with 42 additions and 1 deletions

View File

@ -40,7 +40,17 @@ export class WorkNoteController {
const payload = req.body?.payload ? JSON.parse(req.body.payload) : (req.body || {});
const files = (req.files as any[])?.map(f => ({ path: f.path, originalname: f.originalname, mimetype: f.mimetype, size: f.size })) || [];
const note = await workNoteService.create(requestId, user, payload, files);
// Extract mentions from payload (sent by frontend)
const mentions = payload.mentions || [];
const workNotePayload = {
message: payload.message,
isPriority: payload.isPriority,
parentNoteId: payload.parentNoteId,
mentionedUsers: mentions // Pass mentioned user IDs to service
};
const note = await workNoteService.create(requestId, user, workNotePayload, files);
res.status(201).json({ success: true, data: note });
}
}

View File

@ -2,7 +2,9 @@ import { Op } from 'sequelize';
import { WorkNote } from '@models/WorkNote';
import { WorkNoteAttachment } from '@models/WorkNoteAttachment';
import { Participant } from '@models/Participant';
import { WorkflowRequest } from '@models/WorkflowRequest';
import { activityService } from './activity.service';
import { notificationService } from './notification.service';
import logger from '@utils/logger';
export class WorkNoteService {
@ -144,6 +146,35 @@ export class WorkNoteService {
}
} catch (e) { logger.warn('Realtime emit failed (not initialized)'); }
// Send notifications to mentioned users
if (payload.mentionedUsers && Array.isArray(payload.mentionedUsers) && payload.mentionedUsers.length > 0) {
try {
// Get workflow details for request number and title
const workflow = await WorkflowRequest.findOne({ where: { requestId } });
const requestNumber = (workflow as any)?.requestNumber || requestId;
const requestTitle = (workflow as any)?.title || 'Request';
logger.info(`[WorkNote] Sending mention notifications to ${payload.mentionedUsers.length} users`);
await notificationService.sendToUsers(
payload.mentionedUsers,
{
title: '💬 Mentioned in Work Note',
body: `${user.name || 'Someone'} mentioned you in ${requestNumber}: "${payload.message.substring(0, 50)}${payload.message.length > 50 ? '...' : ''}"`,
requestId,
requestNumber,
url: `/request/${requestNumber}`,
type: 'mention'
}
);
logger.info(`[WorkNote] Mention notifications sent successfully`);
} catch (notifyError) {
logger.error('[WorkNote] Failed to send mention notifications:', notifyError);
// Don't fail the work note creation if notifications fail
}
}
return { ...note, attachments };
}