-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathprojectCreationNotification.ts
More file actions
77 lines (69 loc) · 2.33 KB
/
projectCreationNotification.ts
File metadata and controls
77 lines (69 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { notificationService } from "../notificationService";
import { getUserByIdQuery } from "../../utils/user.utils";
import { frontEndUrl } from "../../config/constants";
import { EMAIL_TEMPLATES } from "../../constants/emailTemplates";
import {
logProcessing,
logSuccess,
logFailure,
} from "../../utils/logger/logHelper";
export interface ProjectCreatedNotificationData {
projectId: number;
projectName: string;
adminId: number;
}
/**
* Send project creation notification to project admin
*/
export const sendProjectCreatedNotification = async (
data: ProjectCreatedNotificationData
): Promise<void> => {
logProcessing({
description: `Sending project creation notification for project: ${data.projectName}`,
functionName: "sendProjectCreatedNotification",
fileName: "projectCreationNotification.ts",
});
try {
// Get admin user details
const adminUser = await getUserByIdQuery(data.adminId);
if (!adminUser) {
throw new Error(`Admin user not found with ID: ${data.adminId}`);
}
// Validate admin user email
if (!adminUser.email || adminUser.email.trim() === '') {
throw new Error(`Admin user email is missing or invalid for user ID: ${data.adminId}`);
}
// Construct project URL
const projectUrl = `${frontEndUrl}/project-view?projectId=${data.projectId}`;
// Prepare template data
const templateData = {
project_name: data.projectName,
admin_name: adminUser.name,
project_url: projectUrl,
};
// Send the email using core notification service
// Template alias: project.created.admin
const subject = `${data.projectName} is created in VerifyWise`;
await notificationService.sendEmailWithTemplate(
adminUser.email,
subject,
EMAIL_TEMPLATES.PROJECT_CREATED_ADMIN,
templateData
);
await logSuccess({
eventType: "Create",
description: `Project creation notification sent to ${adminUser.email}`,
functionName: "sendProjectCreatedNotification",
fileName: "projectCreationNotification.ts",
});
} catch (error) {
await logFailure({
eventType: "Create",
description: `Failed to send project creation notification`,
functionName: "sendProjectCreatedNotification",
fileName: "projectCreationNotification.ts",
error: error as Error,
});
throw error;
}
};