@oneuptime/common 7.0.4006 → 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/Models/DatabaseModels/OnCallDutyPolicySchedule.ts +68 -1
- package/Models/DatabaseModels/OnCallDutyPolicyScheduleLayer.ts +0 -79
- package/Server/API/OnCallDutyPolicyAPI.ts +87 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1743692467814-MigrationName.ts +35 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1743714801105-MigrationName.ts +23 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +4 -0
- 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/OnCallDutyPolicyScheduleLayerService.ts +61 -1
- package/Server/Services/OnCallDutyPolicyScheduleLayerUserService.ts +63 -0
- package/Server/Services/OnCallDutyPolicyScheduleService.ts +597 -18
- package/Server/Services/OnCallDutyPolicyService.ts +129 -0
- package/Server/Services/TeamService.ts +36 -0
- 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/Date.ts +23 -7
- package/Types/Email/EmailTemplateType.ts +6 -0
- package/Types/NotificationSetting/NotificationSettingEventType.ts +7 -0
- package/Types/OnCallDutyPolicy/Layer.ts +104 -20
- package/UI/Components/Alerts/Alert.tsx +6 -5
- package/UI/Components/HeaderAlert/HeaderAlert.tsx +2 -2
- package/build/dist/Models/DatabaseModels/OnCallDutyPolicySchedule.js +70 -1
- package/build/dist/Models/DatabaseModels/OnCallDutyPolicySchedule.js.map +1 -1
- package/build/dist/Models/DatabaseModels/OnCallDutyPolicyScheduleLayer.js +0 -82
- package/build/dist/Models/DatabaseModels/OnCallDutyPolicyScheduleLayer.js.map +1 -1
- package/build/dist/Server/API/OnCallDutyPolicyAPI.js +44 -0
- package/build/dist/Server/API/OnCallDutyPolicyAPI.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1743692467814-MigrationName.js +18 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1743692467814-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1743714801105-MigrationName.js +14 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1743714801105-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +4 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
- 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/OnCallDutyPolicyScheduleLayerService.js +39 -0
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleLayerService.js.map +1 -1
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleLayerUserService.js +42 -0
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleLayerUserService.js.map +1 -1
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleService.js +387 -8
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleService.js.map +1 -1
- package/build/dist/Server/Services/OnCallDutyPolicyService.js +101 -0
- package/build/dist/Server/Services/OnCallDutyPolicyService.js.map +1 -1
- package/build/dist/Server/Services/TeamService.js +27 -0
- package/build/dist/Server/Services/TeamService.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/Date.js +19 -7
- package/build/dist/Types/Date.js.map +1 -1
- 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/build/dist/Types/OnCallDutyPolicy/Layer.js +66 -11
- package/build/dist/Types/OnCallDutyPolicy/Layer.js.map +1 -1
- package/build/dist/UI/Components/Alerts/Alert.js +4 -4
- package/build/dist/UI/Components/Alerts/Alert.js.map +1 -1
- package/build/dist/UI/Components/HeaderAlert/HeaderAlert.js +2 -2
- package/build/dist/UI/Components/HeaderAlert/HeaderAlert.js.map +1 -1
- package/package.json +2 -2
|
@@ -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();
|
|
@@ -1,9 +1,219 @@
|
|
|
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/OnCallDutyPolicyEscalationRuleUser";
|
|
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";
|
|
3
16
|
|
|
4
17
|
export class Service extends DatabaseService<Model> {
|
|
5
18
|
public constructor() {
|
|
6
19
|
super(Model);
|
|
7
20
|
}
|
|
21
|
+
|
|
22
|
+
protected override async onCreateSuccess(
|
|
23
|
+
_onCreate: OnCreate<Model>,
|
|
24
|
+
createdItem: Model,
|
|
25
|
+
): Promise<Model> {
|
|
26
|
+
const createdItemId: ObjectID = createdItem.id!;
|
|
27
|
+
|
|
28
|
+
if (!createdItemId) {
|
|
29
|
+
throw new BadDataException("Created item does not have an ID");
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const createdModel: Model | null = await this.findOneById({
|
|
33
|
+
id: createdItemId,
|
|
34
|
+
select: {
|
|
35
|
+
projectId: true,
|
|
36
|
+
user: {
|
|
37
|
+
timezone: true,
|
|
38
|
+
_id: true,
|
|
39
|
+
},
|
|
40
|
+
onCallDutyPolicyEscalationRule: {
|
|
41
|
+
name: true,
|
|
42
|
+
_id: true,
|
|
43
|
+
order: true,
|
|
44
|
+
},
|
|
45
|
+
onCallDutyPolicy: {
|
|
46
|
+
name: true,
|
|
47
|
+
_id: true,
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
props: {
|
|
51
|
+
isRoot: true,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// send notification to the new current user.
|
|
56
|
+
|
|
57
|
+
const sendEmailToUserId: ObjectID | undefined | null =
|
|
58
|
+
createdModel?.user?.id;
|
|
59
|
+
|
|
60
|
+
if (!sendEmailToUserId) {
|
|
61
|
+
return createdItem;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!createdModel) {
|
|
65
|
+
return createdItem;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const vars: Dictionary<string> = {
|
|
69
|
+
onCallPolicyName:
|
|
70
|
+
createdModel.onCallDutyPolicy?.name || "No name provided",
|
|
71
|
+
escalationRuleName:
|
|
72
|
+
createdModel.onCallDutyPolicyEscalationRule?.name || "No name provided",
|
|
73
|
+
escalationRuleOrder:
|
|
74
|
+
createdModel.onCallDutyPolicyEscalationRule?.order?.toString() ||
|
|
75
|
+
"No order provided",
|
|
76
|
+
reason: "You have been added to the on-call duty policy escalation rule.",
|
|
77
|
+
onCallPolicyViewLink: (
|
|
78
|
+
await OnCallDutyPolicyService.getOnCallPolicyLinkInDashboard(
|
|
79
|
+
createdModel!.projectId!,
|
|
80
|
+
createdModel.onCallDutyPolicy!.id!,
|
|
81
|
+
)
|
|
82
|
+
).toString(),
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
// current user changed, send alert the new current user.
|
|
86
|
+
const emailMessage: EmailEnvelope = {
|
|
87
|
+
templateType: EmailTemplateType.UserAddedToOnCallPolicy,
|
|
88
|
+
vars: vars,
|
|
89
|
+
subject: `You have been added to the on-call duty policy ${createdModel.onCallDutyPolicy?.name}`,
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
const sms: SMSMessage = {
|
|
93
|
+
message: `This is a message from OneUptime. You have been added to the on-call duty policy ${createdModel.onCallDutyPolicy?.name} for escalation rule ${createdModel.onCallDutyPolicyEscalationRule?.name} with order ${createdModel.onCallDutyPolicyEscalationRule?.order}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard.`,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const callMessage: CallRequestMessage = {
|
|
97
|
+
data: [
|
|
98
|
+
{
|
|
99
|
+
sayMessage: `This is a message from OneUptime. You have been added to the on-call duty policy ${createdModel.onCallDutyPolicy?.name} for escalation rule ${createdModel.onCallDutyPolicyEscalationRule?.name} with order ${createdModel.onCallDutyPolicyEscalationRule?.order}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard. Good Bye`,
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
await UserNotificationSettingService.sendUserNotification({
|
|
105
|
+
userId: sendEmailToUserId,
|
|
106
|
+
projectId: createdModel!.projectId!,
|
|
107
|
+
emailEnvelope: emailMessage,
|
|
108
|
+
smsMessage: sms,
|
|
109
|
+
callRequestMessage: callMessage,
|
|
110
|
+
eventType:
|
|
111
|
+
NotificationSettingEventType.SEND_WHEN_USER_IS_ADDED_TO_ON_CALL_POLICY,
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return createdItem;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
protected override async onBeforeDelete(
|
|
118
|
+
deleteBy: DeleteBy<Model>,
|
|
119
|
+
): Promise<OnDelete<Model>> {
|
|
120
|
+
const itemsToFetchBeforeDelete: Array<Model> = await this.findBy({
|
|
121
|
+
query: deleteBy.query,
|
|
122
|
+
props: {
|
|
123
|
+
isRoot: true,
|
|
124
|
+
},
|
|
125
|
+
select: {
|
|
126
|
+
projectId: true,
|
|
127
|
+
user: {
|
|
128
|
+
timezone: true,
|
|
129
|
+
_id: true,
|
|
130
|
+
},
|
|
131
|
+
onCallDutyPolicyEscalationRule: {
|
|
132
|
+
name: true,
|
|
133
|
+
_id: true,
|
|
134
|
+
order: true,
|
|
135
|
+
},
|
|
136
|
+
onCallDutyPolicy: {
|
|
137
|
+
name: true,
|
|
138
|
+
_id: true,
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
limit: LIMIT_PER_PROJECT,
|
|
142
|
+
skip: 0,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
deleteBy,
|
|
147
|
+
carryForward: {
|
|
148
|
+
deletedItems: itemsToFetchBeforeDelete,
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
protected override async onDeleteSuccess(
|
|
154
|
+
onDelete: OnDelete<Model>,
|
|
155
|
+
_itemIdsBeforeDelete: Array<ObjectID>,
|
|
156
|
+
): Promise<OnDelete<Model>> {
|
|
157
|
+
const deletedItems: Array<Model> = onDelete.carryForward.deletedItems;
|
|
158
|
+
|
|
159
|
+
for (const deletedItem of deletedItems) {
|
|
160
|
+
const sendEmailToUserId: ObjectID | undefined | null =
|
|
161
|
+
deletedItem.user?.id;
|
|
162
|
+
|
|
163
|
+
if (!sendEmailToUserId) {
|
|
164
|
+
return onDelete;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const vars: Dictionary<string> = {
|
|
168
|
+
onCallPolicyName:
|
|
169
|
+
deletedItem.onCallDutyPolicy?.name || "No name provided",
|
|
170
|
+
escalationRuleName:
|
|
171
|
+
deletedItem.onCallDutyPolicyEscalationRule?.name ||
|
|
172
|
+
"No name provided",
|
|
173
|
+
escalationRuleOrder:
|
|
174
|
+
deletedItem.onCallDutyPolicyEscalationRule?.order?.toString() ||
|
|
175
|
+
"No order provided",
|
|
176
|
+
reason:
|
|
177
|
+
"You have been removed from the on-call duty policy escalation rule.",
|
|
178
|
+
onCallPolicyViewLink: (
|
|
179
|
+
await OnCallDutyPolicyService.getOnCallPolicyLinkInDashboard(
|
|
180
|
+
deletedItem!.projectId!,
|
|
181
|
+
deletedItem.onCallDutyPolicy!.id!,
|
|
182
|
+
)
|
|
183
|
+
).toString(),
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
// current user changed, send alert the new current user.
|
|
187
|
+
const emailMessage: EmailEnvelope = {
|
|
188
|
+
templateType: EmailTemplateType.UserRemovedFromOnCallPolicy,
|
|
189
|
+
vars: vars,
|
|
190
|
+
subject: `You have been removed from the on-call duty policy ${deletedItem.onCallDutyPolicy?.name}`,
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
const sms: SMSMessage = {
|
|
194
|
+
message: `This is a message from OneUptime. You have been removed from the on-call duty policy ${deletedItem.onCallDutyPolicy?.name} for escalation rule ${deletedItem.onCallDutyPolicyEscalationRule?.name} with order ${deletedItem.onCallDutyPolicyEscalationRule?.order}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard.`,
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const callMessage: CallRequestMessage = {
|
|
198
|
+
data: [
|
|
199
|
+
{
|
|
200
|
+
sayMessage: `This is a message from OneUptime. You have been removed from the on-call duty policy ${deletedItem.onCallDutyPolicy?.name} for escalation rule ${deletedItem.onCallDutyPolicyEscalationRule?.name} with order ${deletedItem.onCallDutyPolicyEscalationRule?.order}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard. Good Bye`,
|
|
201
|
+
},
|
|
202
|
+
],
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
UserNotificationSettingService.sendUserNotification({
|
|
206
|
+
userId: sendEmailToUserId,
|
|
207
|
+
projectId: deletedItem!.projectId!,
|
|
208
|
+
emailEnvelope: emailMessage,
|
|
209
|
+
smsMessage: sms,
|
|
210
|
+
callRequestMessage: callMessage,
|
|
211
|
+
eventType:
|
|
212
|
+
NotificationSettingEventType.SEND_WHEN_USER_IS_REMOVED_FROM_ON_CALL_POLICY,
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return onDelete;
|
|
217
|
+
}
|
|
8
218
|
}
|
|
9
219
|
export default new Service();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import CreateBy from "../Types/Database/CreateBy";
|
|
2
2
|
import DeleteBy from "../Types/Database/DeleteBy";
|
|
3
|
-
import { OnCreate, OnDelete } from "../Types/Database/Hooks";
|
|
3
|
+
import { OnCreate, OnDelete, OnUpdate } from "../Types/Database/Hooks";
|
|
4
4
|
import QueryHelper from "../Types/Database/QueryHelper";
|
|
5
5
|
import DatabaseService from "./DatabaseService";
|
|
6
6
|
import SortOrder from "../../Types/BaseDatabase/SortOrder";
|
|
@@ -10,6 +10,7 @@ import ObjectID from "../../Types/ObjectID";
|
|
|
10
10
|
import PositiveNumber from "../../Types/PositiveNumber";
|
|
11
11
|
import Model from "Common/Models/DatabaseModels/OnCallDutyPolicyScheduleLayer";
|
|
12
12
|
import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
|
|
13
|
+
import OnCallDutyPolicyScheduleService from "./OnCallDutyPolicyScheduleService";
|
|
13
14
|
|
|
14
15
|
export class Service extends DatabaseService<Model> {
|
|
15
16
|
public constructor() {
|
|
@@ -51,6 +52,61 @@ export class Service extends DatabaseService<Model> {
|
|
|
51
52
|
};
|
|
52
53
|
}
|
|
53
54
|
|
|
55
|
+
protected override async onCreateSuccess(
|
|
56
|
+
_onCreate: OnCreate<Model>,
|
|
57
|
+
createdItem: Model,
|
|
58
|
+
): Promise<Model> {
|
|
59
|
+
const resource: Model | null = await this.findOneById({
|
|
60
|
+
id: createdItem.id!,
|
|
61
|
+
select: {
|
|
62
|
+
onCallDutyPolicyScheduleId: true,
|
|
63
|
+
},
|
|
64
|
+
props: {
|
|
65
|
+
isRoot: true,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (!resource || !resource.onCallDutyPolicyScheduleId) {
|
|
70
|
+
return createdItem;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
await OnCallDutyPolicyScheduleService.refreshCurrentUserIdAndHandoffTimeInSchedule(
|
|
74
|
+
resource.onCallDutyPolicyScheduleId,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
return createdItem;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
protected override async onUpdateSuccess(
|
|
81
|
+
_onUpdate: OnUpdate<Model>,
|
|
82
|
+
updatedItemIds: Array<ObjectID>,
|
|
83
|
+
): Promise<OnUpdate<Model>> {
|
|
84
|
+
for (const item of updatedItemIds) {
|
|
85
|
+
const resource: Model | null = await this.findOneById({
|
|
86
|
+
id: item,
|
|
87
|
+
select: {
|
|
88
|
+
onCallDutyPolicyScheduleId: true,
|
|
89
|
+
},
|
|
90
|
+
props: {
|
|
91
|
+
isRoot: true,
|
|
92
|
+
},
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
if (!resource || !resource.onCallDutyPolicyScheduleId) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
await OnCallDutyPolicyScheduleService.refreshCurrentUserIdAndHandoffTimeInSchedule(
|
|
100
|
+
resource.onCallDutyPolicyScheduleId,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
updateBy: _onUpdate.updateBy,
|
|
106
|
+
carryForward: null,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
54
110
|
@CaptureSpan()
|
|
55
111
|
protected override async onDeleteSuccess(
|
|
56
112
|
onDelete: OnDelete<Model>,
|
|
@@ -66,6 +122,10 @@ export class Service extends DatabaseService<Model> {
|
|
|
66
122
|
resource.onCallDutyPolicyScheduleId,
|
|
67
123
|
false,
|
|
68
124
|
);
|
|
125
|
+
|
|
126
|
+
await OnCallDutyPolicyScheduleService.refreshCurrentUserIdAndHandoffTimeInSchedule(
|
|
127
|
+
resource.onCallDutyPolicyScheduleId,
|
|
128
|
+
);
|
|
69
129
|
}
|
|
70
130
|
}
|
|
71
131
|
|
|
@@ -11,6 +11,7 @@ import ObjectID from "../../Types/ObjectID";
|
|
|
11
11
|
import PositiveNumber from "../../Types/PositiveNumber";
|
|
12
12
|
import Model from "Common/Models/DatabaseModels/OnCallDutyPolicyScheduleLayerUser";
|
|
13
13
|
import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
|
|
14
|
+
import OnCallDutyPolicyScheduleService from "./OnCallDutyPolicyScheduleService";
|
|
14
15
|
|
|
15
16
|
export class Service extends DatabaseService<Model> {
|
|
16
17
|
public constructor() {
|
|
@@ -79,6 +80,12 @@ export class Service extends DatabaseService<Model> {
|
|
|
79
80
|
resource.onCallDutyPolicyScheduleLayerId,
|
|
80
81
|
false,
|
|
81
82
|
);
|
|
83
|
+
|
|
84
|
+
if (resource.onCallDutyPolicyScheduleId) {
|
|
85
|
+
await OnCallDutyPolicyScheduleService.refreshCurrentUserIdAndHandoffTimeInSchedule(
|
|
86
|
+
resource.onCallDutyPolicyScheduleId,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
82
89
|
}
|
|
83
90
|
}
|
|
84
91
|
|
|
@@ -109,6 +116,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
109
116
|
select: {
|
|
110
117
|
order: true,
|
|
111
118
|
onCallDutyPolicyScheduleLayerId: true,
|
|
119
|
+
onCallDutyPolicyScheduleId: true,
|
|
112
120
|
},
|
|
113
121
|
});
|
|
114
122
|
}
|
|
@@ -119,6 +127,61 @@ export class Service extends DatabaseService<Model> {
|
|
|
119
127
|
};
|
|
120
128
|
}
|
|
121
129
|
|
|
130
|
+
protected override async onCreateSuccess(
|
|
131
|
+
_onCreate: OnCreate<Model>,
|
|
132
|
+
createdItem: Model,
|
|
133
|
+
): Promise<Model> {
|
|
134
|
+
const resource: Model | null = await this.findOneById({
|
|
135
|
+
id: createdItem.id!,
|
|
136
|
+
select: {
|
|
137
|
+
onCallDutyPolicyScheduleId: true,
|
|
138
|
+
},
|
|
139
|
+
props: {
|
|
140
|
+
isRoot: true,
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
if (!resource || !resource.onCallDutyPolicyScheduleId) {
|
|
145
|
+
return createdItem;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
await OnCallDutyPolicyScheduleService.refreshCurrentUserIdAndHandoffTimeInSchedule(
|
|
149
|
+
resource.onCallDutyPolicyScheduleId,
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
return createdItem;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
protected override async onUpdateSuccess(
|
|
156
|
+
_onUpdate: OnUpdate<Model>,
|
|
157
|
+
updatedItemIds: Array<ObjectID>,
|
|
158
|
+
): Promise<OnUpdate<Model>> {
|
|
159
|
+
for (const item of updatedItemIds) {
|
|
160
|
+
const resource: Model | null = await this.findOneById({
|
|
161
|
+
id: item,
|
|
162
|
+
select: {
|
|
163
|
+
onCallDutyPolicyScheduleId: true,
|
|
164
|
+
},
|
|
165
|
+
props: {
|
|
166
|
+
isRoot: true,
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
if (!resource || !resource.onCallDutyPolicyScheduleId) {
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
await OnCallDutyPolicyScheduleService.refreshCurrentUserIdAndHandoffTimeInSchedule(
|
|
175
|
+
resource.onCallDutyPolicyScheduleId,
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
return {
|
|
180
|
+
updateBy: _onUpdate.updateBy,
|
|
181
|
+
carryForward: null,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
122
185
|
@CaptureSpan()
|
|
123
186
|
protected override async onBeforeUpdate(
|
|
124
187
|
updateBy: UpdateBy<Model>,
|