Skip to content

Commit 5d0ec09

Browse files
committed
fix: email subject & text
1 parent 3deb49c commit 5d0ec09

File tree

1 file changed

+61
-12
lines changed

1 file changed

+61
-12
lines changed

backend/src/project-management/project-management.service.ts

Lines changed: 61 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -415,19 +415,26 @@ export class ProjectManagementService {
415415
}>,
416416
userId: string
417417
) {
418-
const exists = await prisma.task.findUnique({ where: { id } });
418+
const exists: any = await prisma.task.findUnique({ where: { id } });
419+
const data: any = exists;
419420
if (!exists) throw new NotFoundException("Task not found");
421+
const updatedAt = exists.updatedAt;
422+
const status = exists.status;
423+
const priority = exists.priority;
424+
const description = exists.description;
425+
const startDate = exists.description;
426+
const dueDate = exists.dueDate;
427+
const assigneeId = exists.assigneeId;
428+
420429
let project: any = null;
421430
// validate projectId if present and not null (null means detach project)
422-
if (
423-
typeof payload.projectId !== "undefined" &&
424-
payload.projectId !== null
425-
) {
431+
if (typeof exists.projectId !== "undefined" && exists.projectId !== null) {
426432
project = await prisma.project.findUnique({
427-
where: { id: payload.projectId },
433+
where: { id: exists.projectId },
428434
});
429435
if (!project) throw new NotFoundException("Project not found");
430436
}
437+
console.log(project);
431438
let assignee: any = null;
432439
// validate assignee if present and not null
433440
if (
@@ -439,10 +446,15 @@ export class ProjectManagementService {
439446
});
440447
if (!m) throw new NotFoundException("Assignee not found");
441448
assignee = m;
449+
} else if (data.assigneeId !== "undefined" && data.assigneeId !== null) {
450+
const m = await prisma.teamMember.findUnique({
451+
where: { id: data.assigneeId },
452+
});
453+
if (!m) throw new NotFoundException("Assignee not found");
454+
assignee = m;
442455
}
443456

444457
// build clean data object with allowed fields only
445-
const data: any = {};
446458
if (typeof payload.title !== "undefined") data.title = payload.title;
447459
if (typeof payload.description !== "undefined")
448460
data.description = payload.description;
@@ -496,8 +508,45 @@ export class ProjectManagementService {
496508
const format = (d: any) =>
497509
d ? new Date(d).toLocaleDateString("en-US") : "—";
498510

511+
let emailTitle = `➕ New Task Created`;
512+
let emailDescription = `➕ A new task has been created on <strong>${projectName}</strong>.`;
513+
if (updatedAt) {
514+
emailTitle = `📝 Task Updated`;
515+
emailDescription = `📝 A task has been updated on <strong>${projectName}</strong>.`;
516+
}
517+
518+
if (status !== data.status) {
519+
emailTitle = `➡️ Task Moved To ${data.status}`;
520+
emailDescription = `➡️ A task has been moved to ${data.status} on <strong>${projectName}</strong>.`;
521+
}
522+
523+
if (priority !== data.priority) {
524+
emailTitle = `⚡ Task Priority Changed To ${data.priority}`;
525+
emailDescription = `⚡ A task priority has been changed to ${data.priority} on <strong>${projectName}</strong>.`;
526+
}
527+
528+
if (description !== data.description) {
529+
emailTitle = `📝 Task Description has Changed`;
530+
emailDescription = `📝 A task description has been changed on <strong>${projectName}</strong>.`;
531+
}
532+
533+
if (startDate !== data.startDate) {
534+
emailTitle = `📅 Task Start date has Changed To ${data.startDate}`;
535+
emailDescription = `📅 A task Task Start date has been changed to ${data.startDate} on <strong>${projectName}</strong>.`;
536+
}
537+
538+
if (dueDate !== data.dueDate) {
539+
emailTitle = `📅 Task Due date has Changed To ${data.dueDate}`;
540+
emailDescription = `📅 A task Due date has been changed to ${data.dueDate} on <strong>${projectName}</strong>.`;
541+
}
542+
543+
if (assigneeId !== data.assigneeId) {
544+
emailTitle = `👤 Task Assignee has Changed`;
545+
emailDescription = `👤 A task Assignee has been changed on <strong>${projectName}</strong>.`;
546+
}
547+
499548
const textMsg = `
500-
A new task has been created on CommitFlow
549+
${emailDescription}
501550
502551
Task Title:
503552
${updated.title}
@@ -520,8 +569,8 @@ export class ProjectManagementService {
520569

521570
const htmlMsg = `
522571
<div style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
523-
<h2 style="margin-bottom: 8px;">📝 New Task Created</h2>
524-
<p>A new task has been created on <strong>CommitFlow</strong>.</p>
572+
<h2 style="margin-bottom: 8px;">${emailTitle}</h2>
573+
<p>${emailDescription}</p>
525574
526575
<div style="padding: 14px 18px; background: #f8f9fa; border-radius: 10px; margin: 20px 0;">
527576
<p style="margin: 0; font-size: 15px;">
@@ -558,12 +607,12 @@ export class ProjectManagementService {
558607
</p>
559608
</div>
560609
`;
561-
610+
console.log(textMsg);
562611
// KIRIM EMAIL
563612
for (const recipient of toEmails) {
564613
await this.email.sendMail({
565614
to: recipient ?? "[email protected]",
566-
subject: "New Task Created | CommitFlow",
615+
subject: `${emailTitle} | CommitFlow`,
567616
text: textMsg,
568617
html: htmlMsg,
569618
});

0 commit comments

Comments
 (0)