@oneuptime/common 7.0.4007 → 7.0.4019
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Server/Services/OnCallDutyPolicyEscalationRuleScheduleService.ts +243 -0
- package/Server/Services/OnCallDutyPolicyEscalationRuleService.ts +46 -0
- package/Server/Services/OnCallDutyPolicyEscalationRuleTeamService.ts +237 -0
- package/Server/Services/OnCallDutyPolicyEscalationRuleUserService.ts +210 -0
- package/Server/Services/OnCallDutyPolicyScheduleService.ts +392 -14
- package/Server/Services/UserNotificationSettingService.ts +114 -237
- package/Server/Services/UserService.ts +21 -0
- package/Server/Utils/Workspace/Slack/Actions/Alert.ts +2 -2
- package/Server/Utils/Workspace/Slack/Actions/Incident.ts +3 -3
- package/Types/Email/EmailTemplateType.ts +6 -0
- package/Types/NotificationSetting/NotificationSettingEventType.ts +7 -0
- package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleScheduleService.js +170 -0
- package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleScheduleService.js.map +1 -1
- package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleService.js +40 -0
- package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleService.js.map +1 -1
- package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleTeamService.js +170 -0
- package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleTeamService.js.map +1 -1
- package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleUserService.js +152 -0
- package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleUserService.js.map +1 -1
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleService.js +266 -10
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleService.js.map +1 -1
- package/build/dist/Server/Services/UserNotificationSettingService.js +35 -202
- package/build/dist/Server/Services/UserNotificationSettingService.js.map +1 -1
- package/build/dist/Server/Services/UserService.js +17 -0
- package/build/dist/Server/Services/UserService.js.map +1 -1
- package/build/dist/Server/Utils/Workspace/Slack/Actions/Alert.js +2 -2
- package/build/dist/Server/Utils/Workspace/Slack/Actions/Incident.js +3 -3
- package/build/dist/Types/Email/EmailTemplateType.js +5 -0
- package/build/dist/Types/Email/EmailTemplateType.js.map +1 -1
- package/build/dist/Types/NotificationSetting/NotificationSettingEventType.js +6 -0
- package/build/dist/Types/NotificationSetting/NotificationSettingEventType.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,10 +1,253 @@
|
|
|
1
|
+
import BadDataException from "../../Types/Exception/BadDataException";
|
|
2
|
+
import ObjectID from "../../Types/ObjectID";
|
|
3
|
+
import { OnCreate, OnDelete } from "../Types/Database/Hooks";
|
|
1
4
|
import DatabaseService from "./DatabaseService";
|
|
2
5
|
import Model from "Common/Models/DatabaseModels/OnCallDutyPolicyEscalationRuleSchedule";
|
|
6
|
+
import Dictionary from "../../Types/Dictionary";
|
|
7
|
+
import OnCallDutyPolicyService from "./OnCallDutyPolicyService";
|
|
8
|
+
import EmailTemplateType from "../../Types/Email/EmailTemplateType";
|
|
9
|
+
import { EmailEnvelope } from "../../Types/Email/EmailMessage";
|
|
10
|
+
import { SMSMessage } from "../../Types/SMS/SMS";
|
|
11
|
+
import UserNotificationSettingService from "./UserNotificationSettingService";
|
|
12
|
+
import NotificationSettingEventType from "../../Types/NotificationSetting/NotificationSettingEventType";
|
|
13
|
+
import { CallRequestMessage } from "../../Types/Call/CallRequest";
|
|
14
|
+
import DeleteBy from "../Types/Database/DeleteBy";
|
|
15
|
+
import { LIMIT_PER_PROJECT } from "../../Types/Database/LimitMax";
|
|
16
|
+
import OnCallDutyPolicyScheduleService from "./OnCallDutyPolicyScheduleService";
|
|
3
17
|
|
|
4
18
|
export class Service extends DatabaseService<Model> {
|
|
5
19
|
public constructor() {
|
|
6
20
|
super(Model);
|
|
7
21
|
}
|
|
22
|
+
|
|
23
|
+
protected override async onCreateSuccess(
|
|
24
|
+
_onCreate: OnCreate<Model>,
|
|
25
|
+
createdItem: Model,
|
|
26
|
+
): Promise<Model> {
|
|
27
|
+
const createdItemId: ObjectID = createdItem.id!;
|
|
28
|
+
|
|
29
|
+
if (!createdItemId) {
|
|
30
|
+
throw new BadDataException("Created item does not have an ID");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const createdModel: Model | null = await this.findOneById({
|
|
34
|
+
id: createdItemId,
|
|
35
|
+
select: {
|
|
36
|
+
projectId: true,
|
|
37
|
+
onCallDutyPolicyScheduleId: true,
|
|
38
|
+
onCallDutyPolicySchedule: {
|
|
39
|
+
name: true,
|
|
40
|
+
},
|
|
41
|
+
onCallDutyPolicyEscalationRule: {
|
|
42
|
+
name: true,
|
|
43
|
+
_id: true,
|
|
44
|
+
order: true,
|
|
45
|
+
},
|
|
46
|
+
onCallDutyPolicy: {
|
|
47
|
+
name: true,
|
|
48
|
+
_id: true,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
props: {
|
|
52
|
+
isRoot: true,
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
if (!createdModel) {
|
|
57
|
+
throw new BadDataException("Created item does not have an ID");
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (!createdModel.onCallDutyPolicyScheduleId) {
|
|
61
|
+
throw new BadDataException(
|
|
62
|
+
"Created item does not have a onCallDutyPolicyScheduleId",
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// send notification to the new current user.
|
|
67
|
+
|
|
68
|
+
const userOnSchedule: ObjectID | null =
|
|
69
|
+
await OnCallDutyPolicyScheduleService.getCurrentUserIdInSchedule(
|
|
70
|
+
createdModel.onCallDutyPolicyScheduleId,
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
if (!userOnSchedule) {
|
|
74
|
+
return createdItem;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const scheduleName: string =
|
|
78
|
+
createdModel.onCallDutyPolicySchedule?.name || "No name provided";
|
|
79
|
+
|
|
80
|
+
const sendEmailToUserId: ObjectID | undefined | null = userOnSchedule;
|
|
81
|
+
|
|
82
|
+
if (!sendEmailToUserId) {
|
|
83
|
+
return createdItem;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (!createdModel) {
|
|
87
|
+
return createdItem;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const vars: Dictionary<string> = {
|
|
91
|
+
onCallPolicyName:
|
|
92
|
+
createdModel.onCallDutyPolicy?.name || "No name provided",
|
|
93
|
+
escalationRuleName:
|
|
94
|
+
createdModel.onCallDutyPolicyEscalationRule?.name || "No name provided",
|
|
95
|
+
escalationRuleOrder:
|
|
96
|
+
createdModel.onCallDutyPolicyEscalationRule?.order?.toString() ||
|
|
97
|
+
"No order provided",
|
|
98
|
+
reason: "You are currently on roster for schedule " + scheduleName,
|
|
99
|
+
onCallPolicyViewLink: (
|
|
100
|
+
await OnCallDutyPolicyService.getOnCallPolicyLinkInDashboard(
|
|
101
|
+
createdModel!.projectId!,
|
|
102
|
+
createdModel.onCallDutyPolicy!.id!,
|
|
103
|
+
)
|
|
104
|
+
).toString(),
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// Notify the current user about being added to the schedule.
|
|
108
|
+
const emailMessage: EmailEnvelope = {
|
|
109
|
+
templateType: EmailTemplateType.UserAddedToOnCallPolicy,
|
|
110
|
+
vars: vars,
|
|
111
|
+
subject: `You have been added to the on-call duty policy ${createdModel.onCallDutyPolicy?.name} for schedule ${scheduleName}`,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const sms: SMSMessage = {
|
|
115
|
+
message: `This is a message from OneUptime. You have been added to the on-call duty policy ${createdModel.onCallDutyPolicy?.name} for schedule ${scheduleName} and escalation rule ${createdModel.onCallDutyPolicyEscalationRule?.name} with order ${createdModel.onCallDutyPolicyEscalationRule?.order}. To unsubscribe from this notification, go to User Settings in the OneUptime Dashboard.`,
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const callMessage: CallRequestMessage = {
|
|
119
|
+
data: [
|
|
120
|
+
{
|
|
121
|
+
sayMessage: `This is a message from OneUptime. You have been added to the on-call duty policy ${createdModel.onCallDutyPolicy?.name} for schedule ${scheduleName} and escalation rule ${createdModel.onCallDutyPolicyEscalationRule?.name} with order ${createdModel.onCallDutyPolicyEscalationRule?.order}. To unsubscribe from this notification, go to User Settings in the OneUptime Dashboard. Goodbye.`,
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
await UserNotificationSettingService.sendUserNotification({
|
|
127
|
+
userId: sendEmailToUserId,
|
|
128
|
+
projectId: createdModel!.projectId!,
|
|
129
|
+
emailEnvelope: emailMessage,
|
|
130
|
+
smsMessage: sms,
|
|
131
|
+
callRequestMessage: callMessage,
|
|
132
|
+
eventType:
|
|
133
|
+
NotificationSettingEventType.SEND_WHEN_USER_IS_ADDED_TO_ON_CALL_POLICY,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
return createdItem;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
protected override async onBeforeDelete(
|
|
140
|
+
deleteBy: DeleteBy<Model>,
|
|
141
|
+
): Promise<OnDelete<Model>> {
|
|
142
|
+
const itemsToFetchBeforeDelete: Array<Model> = await this.findBy({
|
|
143
|
+
query: deleteBy.query,
|
|
144
|
+
props: {
|
|
145
|
+
isRoot: true,
|
|
146
|
+
},
|
|
147
|
+
select: {
|
|
148
|
+
projectId: true,
|
|
149
|
+
onCallDutyPolicyScheduleId: true,
|
|
150
|
+
onCallDutyPolicySchedule: {
|
|
151
|
+
name: true,
|
|
152
|
+
_id: true,
|
|
153
|
+
},
|
|
154
|
+
onCallDutyPolicyEscalationRule: {
|
|
155
|
+
name: true,
|
|
156
|
+
_id: true,
|
|
157
|
+
order: true,
|
|
158
|
+
},
|
|
159
|
+
onCallDutyPolicy: {
|
|
160
|
+
name: true,
|
|
161
|
+
_id: true,
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
limit: LIMIT_PER_PROJECT,
|
|
165
|
+
skip: 0,
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
return {
|
|
169
|
+
deleteBy,
|
|
170
|
+
carryForward: {
|
|
171
|
+
deletedItems: itemsToFetchBeforeDelete,
|
|
172
|
+
},
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
protected override async onDeleteSuccess(
|
|
177
|
+
onDelete: OnDelete<Model>,
|
|
178
|
+
_itemIdsBeforeDelete: Array<ObjectID>,
|
|
179
|
+
): Promise<OnDelete<Model>> {
|
|
180
|
+
const deletedItems: Array<Model> = onDelete.carryForward.deletedItems;
|
|
181
|
+
|
|
182
|
+
for (const deletedItem of deletedItems) {
|
|
183
|
+
const userOnSchedule: ObjectID | null =
|
|
184
|
+
await OnCallDutyPolicyScheduleService.getCurrentUserIdInSchedule(
|
|
185
|
+
deletedItem.onCallDutyPolicyScheduleId!,
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
if (!userOnSchedule) {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const sendEmailToUserId: ObjectID | undefined | null = userOnSchedule;
|
|
193
|
+
|
|
194
|
+
if (!sendEmailToUserId) {
|
|
195
|
+
return onDelete;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const scheduleName: string =
|
|
199
|
+
deletedItem.onCallDutyPolicySchedule?.name || "No name provided";
|
|
200
|
+
|
|
201
|
+
const vars: Dictionary<string> = {
|
|
202
|
+
onCallPolicyName:
|
|
203
|
+
deletedItem.onCallDutyPolicy?.name || "No name provided",
|
|
204
|
+
escalationRuleName:
|
|
205
|
+
deletedItem.onCallDutyPolicyEscalationRule?.name ||
|
|
206
|
+
"No name provided",
|
|
207
|
+
escalationRuleOrder:
|
|
208
|
+
deletedItem.onCallDutyPolicyEscalationRule?.order?.toString() ||
|
|
209
|
+
"No order provided",
|
|
210
|
+
reason: `You have been removed from the on-call duty policy escalation rule for schedule ${scheduleName}.`,
|
|
211
|
+
onCallPolicyViewLink: (
|
|
212
|
+
await OnCallDutyPolicyService.getOnCallPolicyLinkInDashboard(
|
|
213
|
+
deletedItem!.projectId!,
|
|
214
|
+
deletedItem.onCallDutyPolicy!.id!,
|
|
215
|
+
)
|
|
216
|
+
).toString(),
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
// Notify the current user about being removed from the schedule.
|
|
220
|
+
const emailMessage: EmailEnvelope = {
|
|
221
|
+
templateType: EmailTemplateType.UserRemovedFromOnCallPolicy,
|
|
222
|
+
vars: vars,
|
|
223
|
+
subject: `You have been removed from the on-call duty policy ${deletedItem.onCallDutyPolicy?.name} for schedule ${scheduleName}`,
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
const sms: SMSMessage = {
|
|
227
|
+
message: `This is a message from OneUptime. You have been removed from the on-call duty policy ${deletedItem.onCallDutyPolicy?.name} for schedule ${scheduleName} and escalation rule ${deletedItem.onCallDutyPolicyEscalationRule?.name} with order ${deletedItem.onCallDutyPolicyEscalationRule?.order}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard.`,
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const callMessage: CallRequestMessage = {
|
|
231
|
+
data: [
|
|
232
|
+
{
|
|
233
|
+
sayMessage: `This is a message from OneUptime. You have been removed from the on-call duty policy ${deletedItem.onCallDutyPolicy?.name} for schedule ${scheduleName} and escalation rule ${deletedItem.onCallDutyPolicyEscalationRule?.name} with order ${deletedItem.onCallDutyPolicyEscalationRule?.order}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard. Good Bye`,
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
await UserNotificationSettingService.sendUserNotification({
|
|
239
|
+
userId: sendEmailToUserId,
|
|
240
|
+
projectId: deletedItem!.projectId!,
|
|
241
|
+
emailEnvelope: emailMessage,
|
|
242
|
+
smsMessage: sms,
|
|
243
|
+
callRequestMessage: callMessage,
|
|
244
|
+
eventType:
|
|
245
|
+
NotificationSettingEventType.SEND_WHEN_USER_IS_REMOVED_FROM_ON_CALL_POLICY,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
return onDelete;
|
|
250
|
+
}
|
|
8
251
|
}
|
|
9
252
|
|
|
10
253
|
export default new Service();
|
|
@@ -671,6 +671,52 @@ export class Service extends DatabaseService<Model> {
|
|
|
671
671
|
select: {
|
|
672
672
|
order: true,
|
|
673
673
|
onCallDutyPolicyId: true,
|
|
674
|
+
projectId: true,
|
|
675
|
+
},
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
if (!resource) {
|
|
679
|
+
throw new BadDataException(
|
|
680
|
+
"OnCallDutyPolicyEscalationRule with this id not found",
|
|
681
|
+
);
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
// delete users in escalation rule, teams in escalation rule and schedules in escalation rule.
|
|
685
|
+
await OnCallDutyPolicyEscalationRuleScheduleService.deleteBy({
|
|
686
|
+
query: {
|
|
687
|
+
onCallDutyPolicyEscalationRuleId: resource.id!,
|
|
688
|
+
projectId: resource.projectId!,
|
|
689
|
+
},
|
|
690
|
+
limit: LIMIT_PER_PROJECT,
|
|
691
|
+
skip: 0,
|
|
692
|
+
props: {
|
|
693
|
+
isRoot: true,
|
|
694
|
+
},
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
// delete users in escalation rule.
|
|
698
|
+
await OnCallDutyPolicyEscalationRuleUserService.deleteBy({
|
|
699
|
+
query: {
|
|
700
|
+
onCallDutyPolicyEscalationRuleId: resource.id!,
|
|
701
|
+
projectId: resource.projectId!,
|
|
702
|
+
},
|
|
703
|
+
limit: LIMIT_PER_PROJECT,
|
|
704
|
+
skip: 0,
|
|
705
|
+
props: {
|
|
706
|
+
isRoot: true,
|
|
707
|
+
},
|
|
708
|
+
});
|
|
709
|
+
|
|
710
|
+
// delete teams in escalation rule.
|
|
711
|
+
await OnCallDutyPolicyEscalationRuleTeamService.deleteBy({
|
|
712
|
+
query: {
|
|
713
|
+
onCallDutyPolicyEscalationRuleId: resource.id!,
|
|
714
|
+
projectId: resource.projectId!,
|
|
715
|
+
},
|
|
716
|
+
limit: LIMIT_PER_PROJECT,
|
|
717
|
+
skip: 0,
|
|
718
|
+
props: {
|
|
719
|
+
isRoot: true,
|
|
674
720
|
},
|
|
675
721
|
});
|
|
676
722
|
}
|
|
@@ -1,9 +1,246 @@
|
|
|
1
|
+
import BadDataException from "../../Types/Exception/BadDataException";
|
|
2
|
+
import ObjectID from "../../Types/ObjectID";
|
|
3
|
+
import { OnCreate, OnDelete } from "../Types/Database/Hooks";
|
|
1
4
|
import DatabaseService from "./DatabaseService";
|
|
2
5
|
import Model from "Common/Models/DatabaseModels/OnCallDutyPolicyEscalationRuleTeam";
|
|
6
|
+
import Dictionary from "../../Types/Dictionary";
|
|
7
|
+
import OnCallDutyPolicyService from "./OnCallDutyPolicyService";
|
|
8
|
+
import EmailTemplateType from "../../Types/Email/EmailTemplateType";
|
|
9
|
+
import { EmailEnvelope } from "../../Types/Email/EmailMessage";
|
|
10
|
+
import { SMSMessage } from "../../Types/SMS/SMS";
|
|
11
|
+
import UserNotificationSettingService from "./UserNotificationSettingService";
|
|
12
|
+
import NotificationSettingEventType from "../../Types/NotificationSetting/NotificationSettingEventType";
|
|
13
|
+
import { CallRequestMessage } from "../../Types/Call/CallRequest";
|
|
14
|
+
import DeleteBy from "../Types/Database/DeleteBy";
|
|
15
|
+
import { LIMIT_PER_PROJECT } from "../../Types/Database/LimitMax";
|
|
16
|
+
import TeamMemberService from "./TeamMemberService";
|
|
17
|
+
import User from "../../Models/DatabaseModels/User";
|
|
3
18
|
|
|
4
19
|
export class Service extends DatabaseService<Model> {
|
|
5
20
|
public constructor() {
|
|
6
21
|
super(Model);
|
|
7
22
|
}
|
|
23
|
+
|
|
24
|
+
protected override async onCreateSuccess(
|
|
25
|
+
_onCreate: OnCreate<Model>,
|
|
26
|
+
createdItem: Model,
|
|
27
|
+
): Promise<Model> {
|
|
28
|
+
const createdItemId: ObjectID = createdItem.id!;
|
|
29
|
+
|
|
30
|
+
if (!createdItemId) {
|
|
31
|
+
throw new BadDataException("Created item does not have an ID");
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const createdModel: Model | null = await this.findOneById({
|
|
35
|
+
id: createdItemId,
|
|
36
|
+
select: {
|
|
37
|
+
projectId: true,
|
|
38
|
+
teamId: true,
|
|
39
|
+
team: {
|
|
40
|
+
name: true,
|
|
41
|
+
},
|
|
42
|
+
onCallDutyPolicyEscalationRule: {
|
|
43
|
+
name: true,
|
|
44
|
+
_id: true,
|
|
45
|
+
order: true,
|
|
46
|
+
},
|
|
47
|
+
onCallDutyPolicy: {
|
|
48
|
+
name: true,
|
|
49
|
+
_id: true,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
props: {
|
|
53
|
+
isRoot: true,
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
if (!createdModel) {
|
|
58
|
+
throw new BadDataException("Created item does not have an ID");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!createdModel.teamId) {
|
|
62
|
+
throw new BadDataException("Created item does not have a teamId");
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// send notification to the new current user.
|
|
66
|
+
|
|
67
|
+
const usersInTeam: Array<User> = await TeamMemberService.getUsersInTeam(
|
|
68
|
+
createdModel.teamId!,
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
for (const user of usersInTeam) {
|
|
72
|
+
const temaName: string = createdModel.team?.name || "No name provided";
|
|
73
|
+
|
|
74
|
+
const sendEmailToUserId: ObjectID | undefined | null = user?.id;
|
|
75
|
+
|
|
76
|
+
if (!sendEmailToUserId) {
|
|
77
|
+
return createdItem;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (!createdModel) {
|
|
81
|
+
return createdItem;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const vars: Dictionary<string> = {
|
|
85
|
+
onCallPolicyName:
|
|
86
|
+
createdModel.onCallDutyPolicy?.name || "No name provided",
|
|
87
|
+
escalationRuleName:
|
|
88
|
+
createdModel.onCallDutyPolicyEscalationRule?.name ||
|
|
89
|
+
"No name provided",
|
|
90
|
+
escalationRuleOrder:
|
|
91
|
+
createdModel.onCallDutyPolicyEscalationRule?.order?.toString() ||
|
|
92
|
+
"No order provided",
|
|
93
|
+
reason:
|
|
94
|
+
"You have been added to the on-call duty policy escalation rule because you are a member of the team " +
|
|
95
|
+
temaName,
|
|
96
|
+
onCallPolicyViewLink: (
|
|
97
|
+
await OnCallDutyPolicyService.getOnCallPolicyLinkInDashboard(
|
|
98
|
+
createdModel!.projectId!,
|
|
99
|
+
createdModel.onCallDutyPolicy!.id!,
|
|
100
|
+
)
|
|
101
|
+
).toString(),
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// current user changed, send alert the new current user.
|
|
105
|
+
const emailMessage: EmailEnvelope = {
|
|
106
|
+
templateType: EmailTemplateType.UserAddedToOnCallPolicy,
|
|
107
|
+
vars: vars,
|
|
108
|
+
subject: `You have been added to the on-call duty policy ${createdModel.onCallDutyPolicy?.name} for team ${temaName}`,
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const sms: SMSMessage = {
|
|
112
|
+
message: `This is a message from OneUptime. You have been added to the on-call duty policy ${createdModel.onCallDutyPolicy?.name} for team ${temaName} and escalation rule ${createdModel.onCallDutyPolicyEscalationRule?.name} with order ${createdModel.onCallDutyPolicyEscalationRule?.order}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard.`,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const callMessage: CallRequestMessage = {
|
|
116
|
+
data: [
|
|
117
|
+
{
|
|
118
|
+
sayMessage: `This is a message from OneUptime. You have been added to the on-call duty policy ${createdModel.onCallDutyPolicy?.name} for team ${temaName} and escalation rule ${createdModel.onCallDutyPolicyEscalationRule?.name} with order ${createdModel.onCallDutyPolicyEscalationRule?.order}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard. Good Bye`,
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
await UserNotificationSettingService.sendUserNotification({
|
|
124
|
+
userId: sendEmailToUserId,
|
|
125
|
+
projectId: createdModel!.projectId!,
|
|
126
|
+
emailEnvelope: emailMessage,
|
|
127
|
+
smsMessage: sms,
|
|
128
|
+
callRequestMessage: callMessage,
|
|
129
|
+
eventType:
|
|
130
|
+
NotificationSettingEventType.SEND_WHEN_USER_IS_ADDED_TO_ON_CALL_POLICY,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return createdItem;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
protected override async onBeforeDelete(
|
|
138
|
+
deleteBy: DeleteBy<Model>,
|
|
139
|
+
): Promise<OnDelete<Model>> {
|
|
140
|
+
const itemsToFetchBeforeDelete: Array<Model> = await this.findBy({
|
|
141
|
+
query: deleteBy.query,
|
|
142
|
+
props: {
|
|
143
|
+
isRoot: true,
|
|
144
|
+
},
|
|
145
|
+
select: {
|
|
146
|
+
projectId: true,
|
|
147
|
+
teamId: true,
|
|
148
|
+
team: {
|
|
149
|
+
name: true,
|
|
150
|
+
_id: true,
|
|
151
|
+
},
|
|
152
|
+
onCallDutyPolicyEscalationRule: {
|
|
153
|
+
name: true,
|
|
154
|
+
_id: true,
|
|
155
|
+
order: true,
|
|
156
|
+
},
|
|
157
|
+
onCallDutyPolicy: {
|
|
158
|
+
name: true,
|
|
159
|
+
_id: true,
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
limit: LIMIT_PER_PROJECT,
|
|
163
|
+
skip: 0,
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
return {
|
|
167
|
+
deleteBy,
|
|
168
|
+
carryForward: {
|
|
169
|
+
deletedItems: itemsToFetchBeforeDelete,
|
|
170
|
+
},
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
protected override async onDeleteSuccess(
|
|
175
|
+
onDelete: OnDelete<Model>,
|
|
176
|
+
_itemIdsBeforeDelete: Array<ObjectID>,
|
|
177
|
+
): Promise<OnDelete<Model>> {
|
|
178
|
+
const deletedItems: Array<Model> = onDelete.carryForward.deletedItems;
|
|
179
|
+
|
|
180
|
+
for (const deletedItem of deletedItems) {
|
|
181
|
+
const usersInTeam: Array<User> = await TeamMemberService.getUsersInTeam(
|
|
182
|
+
deletedItem.teamId!,
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
for (const user of usersInTeam) {
|
|
186
|
+
const sendEmailToUserId: ObjectID | undefined | null = user?.id;
|
|
187
|
+
|
|
188
|
+
if (!sendEmailToUserId) {
|
|
189
|
+
return onDelete;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const teamName: string = deletedItem.team?.name || "No name provided";
|
|
193
|
+
|
|
194
|
+
const vars: Dictionary<string> = {
|
|
195
|
+
onCallPolicyName:
|
|
196
|
+
deletedItem.onCallDutyPolicy?.name || "No name provided",
|
|
197
|
+
escalationRuleName:
|
|
198
|
+
deletedItem.onCallDutyPolicyEscalationRule?.name ||
|
|
199
|
+
"No name provided",
|
|
200
|
+
escalationRuleOrder:
|
|
201
|
+
deletedItem.onCallDutyPolicyEscalationRule?.order?.toString() ||
|
|
202
|
+
"No order provided",
|
|
203
|
+
reason: `You have been removed from the on-call duty policy escalation rule for team ${teamName}.`,
|
|
204
|
+
onCallPolicyViewLink: (
|
|
205
|
+
await OnCallDutyPolicyService.getOnCallPolicyLinkInDashboard(
|
|
206
|
+
deletedItem!.projectId!,
|
|
207
|
+
deletedItem.onCallDutyPolicy!.id!,
|
|
208
|
+
)
|
|
209
|
+
).toString(),
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
// current user changed, send alert the new current user.
|
|
213
|
+
const emailMessage: EmailEnvelope = {
|
|
214
|
+
templateType: EmailTemplateType.UserRemovedFromOnCallPolicy,
|
|
215
|
+
vars: vars,
|
|
216
|
+
subject: `You have been removed from the on-call duty policy ${deletedItem.onCallDutyPolicy?.name} for team ${teamName}`,
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const sms: SMSMessage = {
|
|
220
|
+
message: `This is a message from OneUptime. You have been removed from the on-call duty policy ${deletedItem.onCallDutyPolicy?.name} for team ${teamName} and escalation rule ${deletedItem.onCallDutyPolicyEscalationRule?.name} with order ${deletedItem.onCallDutyPolicyEscalationRule?.order}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard.`,
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const callMessage: CallRequestMessage = {
|
|
224
|
+
data: [
|
|
225
|
+
{
|
|
226
|
+
sayMessage: `This is a message from OneUptime. You have been removed from the on-call duty policy ${deletedItem.onCallDutyPolicy?.name} for team ${teamName} and escalation rule ${deletedItem.onCallDutyPolicyEscalationRule?.name} with order ${deletedItem.onCallDutyPolicyEscalationRule?.order}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard. Good Bye`,
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
UserNotificationSettingService.sendUserNotification({
|
|
232
|
+
userId: sendEmailToUserId,
|
|
233
|
+
projectId: deletedItem!.projectId!,
|
|
234
|
+
emailEnvelope: emailMessage,
|
|
235
|
+
smsMessage: sms,
|
|
236
|
+
callRequestMessage: callMessage,
|
|
237
|
+
eventType:
|
|
238
|
+
NotificationSettingEventType.SEND_WHEN_USER_IS_REMOVED_FROM_ON_CALL_POLICY,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
return onDelete;
|
|
244
|
+
}
|
|
8
245
|
}
|
|
9
246
|
export default new Service();
|