Skip to content

Commit e721e35

Browse files
committed
fix: send email to all team member when commenting
1 parent c37f25e commit e721e35

File tree

1 file changed

+93
-0
lines changed

1 file changed

+93
-0
lines changed

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

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,99 @@ export class ProjectManagementService {
696696
attachments: payload.attachments ?? undefined,
697697
},
698698
});
699+
700+
//send email to team members
701+
const p = await prisma.project.findFirst({
702+
where: { id: task.projectId ?? "", isTrash: false },
703+
});
704+
705+
if (!p) throw new NotFoundException("Project not found");
706+
707+
//send email to team members
708+
const teams = await prisma.teamMember.findMany({
709+
where: { workspaceId: p.workspaceId ?? "", isTrash: false },
710+
select: { email: true },
711+
});
712+
713+
const toEmails = teams.map((t) => t.email?.trim()).filter(Boolean);
714+
715+
if (toEmails.length === 0) throw new Error("No recipient emails found");
716+
717+
const projectName = p.name;
718+
const taskName = task.title;
719+
const author = payload.author;
720+
const body = payload.body;
721+
722+
const textMsg = `
723+
💬 New Comment!
724+
725+
Project Name:
726+
${projectName}
727+
728+
Task Name:
729+
${taskName}
730+
731+
Author:
732+
${author}
733+
734+
Comment:
735+
${body}
736+
737+
You are receiving this notification because you are part of the workspace team.
738+
739+
Regards,
740+
CommitFlow Team
741+
`;
742+
743+
const htmlMsg = `
744+
<div style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
745+
<h2 style="margin-bottom: 8px;">💬 New Comment!</h2>
746+
747+
<div style="padding: 12px 16px; background: #f8f9fa; border-radius: 8px; margin: 20px 0;">
748+
<p style="margin: 0; font-size: 15px;">
749+
<strong>Project Name:</strong><br>
750+
${projectName}
751+
</p>
752+
753+
<p style="margin-top: 12px; font-size: 15px;">
754+
<strong>Task Name:</strong><br>
755+
${taskName}
756+
</p>
757+
758+
<p style="margin-top: 12px; font-size: 15px;">
759+
<strong>Author:</strong><br>
760+
${author}
761+
</p>
762+
763+
<p style="margin-top: 12px; font-size: 15px;">
764+
<strong>Comment:</strong><br>
765+
${body}
766+
</p>
767+
</div>
768+
769+
<p>You are receiving this because you are a member of this workspace.</p>
770+
771+
<p style="margin-top: 24px; font-size: 14px; color: #666;">
772+
— CommitFlow Team
773+
</p>
774+
</div>
775+
`;
776+
777+
for (const recipient of toEmails) {
778+
try {
779+
await this.email.sendMail({
780+
to: recipient ?? "[email protected]",
781+
subject: "💬 New Comment | CommitFlow",
782+
text: textMsg,
783+
html: htmlMsg,
784+
});
785+
} catch (error) {
786+
logger.error(error);
787+
}
788+
789+
await new Promise((r) => setTimeout(r, 200));
790+
}
791+
699792
return {
700793
...c,
701794
createdAt: c.createdAt?.toISOString(),

0 commit comments

Comments
 (0)