@oneuptime/common 7.0.4003 → 7.0.4007
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/OnCallDutyPolicyScheduleLayerService.ts +61 -1
- package/Server/Services/OnCallDutyPolicyScheduleLayerUserService.ts +63 -0
- package/Server/Services/OnCallDutyPolicyScheduleService.ts +216 -15
- package/Server/Services/OnCallDutyPolicyService.ts +129 -0
- package/Server/Services/TeamService.ts +36 -0
- package/Types/Date.ts +23 -7
- 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/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 +129 -6
- 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/Types/Date.js +19 -7
- package/build/dist/Types/Date.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
|
@@ -18,12 +18,158 @@ export class Service extends DatabaseService<Model> {
|
|
|
18
18
|
super(Model);
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
public async getOnCallSchedulesWhereUserIsOnCallDuty(data: {
|
|
22
|
+
projectId: ObjectID;
|
|
23
|
+
userId: ObjectID;
|
|
24
|
+
}): Promise<Array<Model>> {
|
|
25
|
+
const schedules: Array<Model> = await this.findBy({
|
|
26
|
+
query: {
|
|
27
|
+
projectId: data.projectId,
|
|
28
|
+
currentUserIdOnRoster: data.userId,
|
|
29
|
+
},
|
|
30
|
+
select: {
|
|
31
|
+
_id: true,
|
|
32
|
+
name: true,
|
|
33
|
+
},
|
|
34
|
+
limit: LIMIT_PER_PROJECT,
|
|
35
|
+
skip: 0,
|
|
36
|
+
props: {
|
|
37
|
+
isRoot: true,
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return schedules;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public async refreshCurrentUserIdAndHandoffTimeInSchedule(
|
|
23
45
|
scheduleId: ObjectID,
|
|
24
|
-
): Promise<
|
|
46
|
+
): Promise<{
|
|
47
|
+
currentUserId: ObjectID | null;
|
|
48
|
+
handOffTimeAt: Date | null;
|
|
49
|
+
nextUserId: ObjectID | null;
|
|
50
|
+
nextHandOffTimeAt: Date | null;
|
|
51
|
+
}> {
|
|
52
|
+
const result: {
|
|
53
|
+
currentUserId: ObjectID | null;
|
|
54
|
+
handOffTimeAt: Date | null;
|
|
55
|
+
nextUserId: ObjectID | null;
|
|
56
|
+
nextHandOffTimeAt: Date | null;
|
|
57
|
+
rosterStartAt: Date | null;
|
|
58
|
+
nextRosterStartAt: Date | null;
|
|
59
|
+
} = await this.getCurrrentUserIdAndHandoffTimeInSchedule(scheduleId);
|
|
60
|
+
|
|
61
|
+
await this.updateOneById({
|
|
62
|
+
id: scheduleId!,
|
|
63
|
+
data: {
|
|
64
|
+
currentUserIdOnRoster: result.currentUserId,
|
|
65
|
+
rosterHandoffAt: result.handOffTimeAt,
|
|
66
|
+
nextUserIdOnRoster: result.nextUserId,
|
|
67
|
+
rosterNextHandoffAt: result.nextHandOffTimeAt,
|
|
68
|
+
rosterStartAt: result.rosterStartAt,
|
|
69
|
+
rosterNextStartAt: result.nextRosterStartAt,
|
|
70
|
+
},
|
|
71
|
+
props: {
|
|
72
|
+
isRoot: true,
|
|
73
|
+
ignoreHooks: true,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return result;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public async getCurrrentUserIdAndHandoffTimeInSchedule(
|
|
81
|
+
scheduleId: ObjectID,
|
|
82
|
+
): Promise<{
|
|
83
|
+
rosterStartAt: Date | null;
|
|
84
|
+
currentUserId: ObjectID | null;
|
|
85
|
+
handOffTimeAt: Date | null;
|
|
86
|
+
nextUserId: ObjectID | null;
|
|
87
|
+
nextHandOffTimeAt: Date | null;
|
|
88
|
+
nextRosterStartAt: Date | null;
|
|
89
|
+
}> {
|
|
90
|
+
const resultReturn: {
|
|
91
|
+
rosterStartAt: Date | null;
|
|
92
|
+
currentUserId: ObjectID | null;
|
|
93
|
+
handOffTimeAt: Date | null;
|
|
94
|
+
nextUserId: ObjectID | null;
|
|
95
|
+
nextHandOffTimeAt: Date | null;
|
|
96
|
+
nextRosterStartAt: Date | null;
|
|
97
|
+
} = {
|
|
98
|
+
currentUserId: null,
|
|
99
|
+
handOffTimeAt: null,
|
|
100
|
+
nextUserId: null,
|
|
101
|
+
nextHandOffTimeAt: null,
|
|
102
|
+
rosterStartAt: null,
|
|
103
|
+
nextRosterStartAt: null,
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
const events: Array<CalendarEvent> | null =
|
|
107
|
+
await this.getEventByIndexInSchedule({
|
|
108
|
+
scheduleId: scheduleId,
|
|
109
|
+
getNumberOfEvents: 2,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
let currentEvent: CalendarEvent | null = events[0] || null;
|
|
113
|
+
let nextEvent: CalendarEvent | null = events[1] || null;
|
|
114
|
+
|
|
115
|
+
// if the current event start time in the future then the current event is the next event.
|
|
116
|
+
if (currentEvent && OneUptimeDate.isInTheFuture(currentEvent.start)) {
|
|
117
|
+
nextEvent = currentEvent;
|
|
118
|
+
currentEvent = null;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (currentEvent) {
|
|
122
|
+
const userId: string | undefined = currentEvent?.title; // this is user id in string.
|
|
123
|
+
|
|
124
|
+
if (userId) {
|
|
125
|
+
resultReturn.currentUserId = new ObjectID(userId);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// get handOffTime
|
|
129
|
+
const handOffTime: Date | undefined = currentEvent?.end; // this is user id in string.
|
|
130
|
+
if (handOffTime) {
|
|
131
|
+
resultReturn.handOffTimeAt = handOffTime;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// get start time
|
|
135
|
+
const startTime: Date | undefined = currentEvent?.start; // this is user id in string.
|
|
136
|
+
if (startTime) {
|
|
137
|
+
resultReturn.rosterStartAt = startTime;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// do the same for next event.
|
|
142
|
+
|
|
143
|
+
if (nextEvent) {
|
|
144
|
+
const userId: string | undefined = nextEvent?.title; // this is user id in string.
|
|
145
|
+
|
|
146
|
+
if (userId) {
|
|
147
|
+
resultReturn.nextUserId = new ObjectID(userId);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// get handOffTime
|
|
151
|
+
const handOffTime: Date | undefined = nextEvent?.end; // this is user id in string.
|
|
152
|
+
if (handOffTime) {
|
|
153
|
+
resultReturn.nextHandOffTimeAt = handOffTime;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// get start time
|
|
157
|
+
const startTime: Date | undefined = nextEvent?.start; // this is user id in string.
|
|
158
|
+
if (startTime) {
|
|
159
|
+
resultReturn.nextRosterStartAt = startTime;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return resultReturn;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
private async getScheduleLayerProps(data: {
|
|
167
|
+
scheduleId: ObjectID;
|
|
168
|
+
}): Promise<Array<LayerProps>> {
|
|
25
169
|
// get schedule layers.
|
|
26
170
|
|
|
171
|
+
const scheduleId: ObjectID = data.scheduleId;
|
|
172
|
+
|
|
27
173
|
const layers: Array<OnCallDutyPolicyScheduleLayer> =
|
|
28
174
|
await OnCallDutyPolicyScheduleLayerService.findBy({
|
|
29
175
|
query: {
|
|
@@ -70,12 +216,6 @@ export class Service extends DatabaseService<Model> {
|
|
|
70
216
|
},
|
|
71
217
|
});
|
|
72
218
|
|
|
73
|
-
const currentStartTime: Date = OneUptimeDate.getCurrentDate();
|
|
74
|
-
const currentEndTime: Date = OneUptimeDate.addRemoveSeconds(
|
|
75
|
-
currentStartTime,
|
|
76
|
-
1,
|
|
77
|
-
);
|
|
78
|
-
|
|
79
219
|
const layerProps: Array<LayerProps> = [];
|
|
80
220
|
|
|
81
221
|
for (const layer of layers) {
|
|
@@ -101,17 +241,78 @@ export class Service extends DatabaseService<Model> {
|
|
|
101
241
|
});
|
|
102
242
|
}
|
|
103
243
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
244
|
+
return layerProps;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
public async getEventByIndexInSchedule(data: {
|
|
248
|
+
scheduleId: ObjectID;
|
|
249
|
+
getNumberOfEvents: number; // which event would you like to get. First event, second event, etc.
|
|
250
|
+
}): Promise<Array<CalendarEvent>> {
|
|
251
|
+
const layerProps: Array<LayerProps> = await this.getScheduleLayerProps({
|
|
252
|
+
scheduleId: data.scheduleId,
|
|
108
253
|
});
|
|
109
254
|
|
|
110
|
-
if (
|
|
255
|
+
if (layerProps.length === 0) {
|
|
256
|
+
return [];
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const currentStartTime: Date = OneUptimeDate.getCurrentDate();
|
|
260
|
+
const currentEndTime: Date = OneUptimeDate.addRemoveYears(
|
|
261
|
+
currentStartTime,
|
|
262
|
+
1,
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
const numberOfEventsToGet: number = data.getNumberOfEvents;
|
|
266
|
+
const events: Array<CalendarEvent> = LayerUtil.getMultiLayerEvents(
|
|
267
|
+
{
|
|
268
|
+
layers: layerProps,
|
|
269
|
+
calendarStartDate: currentStartTime,
|
|
270
|
+
calendarEndDate: currentEndTime,
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
getNumberOfEvents: numberOfEventsToGet,
|
|
274
|
+
},
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
return events;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
@CaptureSpan()
|
|
281
|
+
public async getCurrentUserIdInSchedule(
|
|
282
|
+
scheduleId: ObjectID,
|
|
283
|
+
): Promise<ObjectID | null> {
|
|
284
|
+
const layerProps: Array<LayerProps> = await this.getScheduleLayerProps({
|
|
285
|
+
scheduleId: scheduleId,
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
if (layerProps.length === 0) {
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const currentStartTime: Date = OneUptimeDate.getCurrentDate();
|
|
293
|
+
const currentEndTime: Date = OneUptimeDate.addRemoveSeconds(
|
|
294
|
+
currentStartTime,
|
|
295
|
+
1,
|
|
296
|
+
);
|
|
297
|
+
|
|
298
|
+
const events: Array<CalendarEvent> = LayerUtil.getMultiLayerEvents(
|
|
299
|
+
{
|
|
300
|
+
layers: layerProps,
|
|
301
|
+
calendarStartDate: currentStartTime,
|
|
302
|
+
calendarEndDate: currentEndTime,
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
getNumberOfEvents: 1,
|
|
306
|
+
},
|
|
307
|
+
);
|
|
308
|
+
|
|
309
|
+
const currentEvent: CalendarEvent | null = events[0] || null;
|
|
310
|
+
|
|
311
|
+
if (!currentEvent) {
|
|
111
312
|
return null;
|
|
112
313
|
}
|
|
113
314
|
|
|
114
|
-
const userId: string | undefined =
|
|
315
|
+
const userId: string | undefined = currentEvent?.title; // this is user id in string.
|
|
115
316
|
|
|
116
317
|
if (!userId) {
|
|
117
318
|
return null;
|
|
@@ -9,6 +9,18 @@ import OnCallDutyPolicyExecutionLog from "Common/Models/DatabaseModels/OnCallDut
|
|
|
9
9
|
import DatabaseConfig from "../DatabaseConfig";
|
|
10
10
|
import URL from "../../Types/API/URL";
|
|
11
11
|
import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
|
|
12
|
+
import OnCallDutyPolicySchedule from "../../Models/DatabaseModels/OnCallDutyPolicySchedule";
|
|
13
|
+
import OnCallDutyPolicyScheduleService from "./OnCallDutyPolicyScheduleService";
|
|
14
|
+
import TeamService from "./TeamService";
|
|
15
|
+
import Team from "../../Models/DatabaseModels/Team";
|
|
16
|
+
import OnCallDutyPolicyEscalationRuleUser from "../../Models/DatabaseModels/OnCallDutyPolicyEscalationRuleUser";
|
|
17
|
+
import OnCallDutyPolicyEscalationRuleUserService from "./OnCallDutyPolicyEscalationRuleUserService";
|
|
18
|
+
import { LIMIT_PER_PROJECT } from "../../Types/Database/LimitMax";
|
|
19
|
+
import OnCallDutyPolicyEscalationRuleTeam from "../../Models/DatabaseModels/OnCallDutyPolicyEscalationRuleTeam";
|
|
20
|
+
import OnCallDutyPolicyEscalationRuleTeamService from "./OnCallDutyPolicyEscalationRuleTeamService";
|
|
21
|
+
import QueryHelper from "../Types/Database/QueryHelper";
|
|
22
|
+
import OnCallDutyPolicyEscalationRuleSchedule from "../../Models/DatabaseModels/OnCallDutyPolicyEscalationRuleSchedule";
|
|
23
|
+
import OnCallDutyPolicyEscalationRuleScheduleService from "./OnCallDutyPolicyEscalationRuleScheduleService";
|
|
12
24
|
|
|
13
25
|
export class Service extends DatabaseService<OnCallDutyPolicy> {
|
|
14
26
|
public constructor() {
|
|
@@ -100,5 +112,122 @@ export class Service extends DatabaseService<OnCallDutyPolicy> {
|
|
|
100
112
|
},
|
|
101
113
|
});
|
|
102
114
|
}
|
|
115
|
+
|
|
116
|
+
public async getOnCallPoliciesWhereUserIsOnCallDuty(data: {
|
|
117
|
+
projectId: ObjectID;
|
|
118
|
+
userId: ObjectID;
|
|
119
|
+
}): Promise<{
|
|
120
|
+
escalationRulesByUser: Array<OnCallDutyPolicyEscalationRuleUser>;
|
|
121
|
+
escalationRulesByTeam: Array<OnCallDutyPolicyEscalationRuleTeam>;
|
|
122
|
+
escalationRulesBySchedule: Array<OnCallDutyPolicyEscalationRuleSchedule>;
|
|
123
|
+
}> {
|
|
124
|
+
// get all schedules where user is on call duty.
|
|
125
|
+
const onCallSchedules: Array<OnCallDutyPolicySchedule> =
|
|
126
|
+
await OnCallDutyPolicyScheduleService.getOnCallSchedulesWhereUserIsOnCallDuty(
|
|
127
|
+
data,
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const teams: Array<Team> = await TeamService.getTeamsUserIsAPartOf({
|
|
131
|
+
userId: data.userId,
|
|
132
|
+
projectId: data.projectId,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// get escalationPolicies by user, team and schedule.
|
|
136
|
+
const escalationRulesByUser: Array<OnCallDutyPolicyEscalationRuleUser> =
|
|
137
|
+
await OnCallDutyPolicyEscalationRuleUserService.findBy({
|
|
138
|
+
query: {
|
|
139
|
+
userId: data.userId!,
|
|
140
|
+
projectId: data.projectId!,
|
|
141
|
+
},
|
|
142
|
+
select: {
|
|
143
|
+
onCallDutyPolicyEscalationRule: {
|
|
144
|
+
name: true,
|
|
145
|
+
_id: true,
|
|
146
|
+
order: true,
|
|
147
|
+
},
|
|
148
|
+
onCallDutyPolicy: {
|
|
149
|
+
name: true,
|
|
150
|
+
_id: true,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
limit: LIMIT_PER_PROJECT,
|
|
154
|
+
skip: 0,
|
|
155
|
+
props: {
|
|
156
|
+
isRoot: true,
|
|
157
|
+
},
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
// do the same for teams.
|
|
161
|
+
const escalationRulesByTeam: Array<OnCallDutyPolicyEscalationRuleTeam> =
|
|
162
|
+
await OnCallDutyPolicyEscalationRuleTeamService.findBy({
|
|
163
|
+
query: {
|
|
164
|
+
teamId: QueryHelper.any(
|
|
165
|
+
teams.map((team: Team) => {
|
|
166
|
+
return team.id!;
|
|
167
|
+
}),
|
|
168
|
+
),
|
|
169
|
+
projectId: data.projectId!,
|
|
170
|
+
},
|
|
171
|
+
select: {
|
|
172
|
+
onCallDutyPolicy: {
|
|
173
|
+
name: true,
|
|
174
|
+
_id: true,
|
|
175
|
+
},
|
|
176
|
+
onCallDutyPolicyEscalationRule: {
|
|
177
|
+
name: true,
|
|
178
|
+
_id: true,
|
|
179
|
+
order: true,
|
|
180
|
+
},
|
|
181
|
+
team: {
|
|
182
|
+
name: true,
|
|
183
|
+
_id: true,
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
limit: LIMIT_PER_PROJECT,
|
|
187
|
+
skip: 0,
|
|
188
|
+
props: {
|
|
189
|
+
isRoot: true,
|
|
190
|
+
},
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
// do the same for schedules.
|
|
194
|
+
const escalationRulesBySchedule: Array<OnCallDutyPolicyEscalationRuleSchedule> =
|
|
195
|
+
await OnCallDutyPolicyEscalationRuleScheduleService.findBy({
|
|
196
|
+
query: {
|
|
197
|
+
onCallDutyPolicyScheduleId: QueryHelper.any(
|
|
198
|
+
onCallSchedules.map((schedule: OnCallDutyPolicySchedule) => {
|
|
199
|
+
return schedule.id!;
|
|
200
|
+
}),
|
|
201
|
+
),
|
|
202
|
+
projectId: data.projectId!,
|
|
203
|
+
},
|
|
204
|
+
select: {
|
|
205
|
+
onCallDutyPolicy: {
|
|
206
|
+
name: true,
|
|
207
|
+
_id: true,
|
|
208
|
+
},
|
|
209
|
+
onCallDutyPolicyEscalationRule: {
|
|
210
|
+
name: true,
|
|
211
|
+
_id: true,
|
|
212
|
+
order: true,
|
|
213
|
+
},
|
|
214
|
+
onCallDutyPolicySchedule: {
|
|
215
|
+
name: true,
|
|
216
|
+
_id: true,
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
limit: LIMIT_PER_PROJECT,
|
|
220
|
+
skip: 0,
|
|
221
|
+
props: {
|
|
222
|
+
isRoot: true,
|
|
223
|
+
},
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
return {
|
|
227
|
+
escalationRulesByUser: escalationRulesByUser,
|
|
228
|
+
escalationRulesByTeam: escalationRulesByTeam,
|
|
229
|
+
escalationRulesBySchedule: escalationRulesBySchedule,
|
|
230
|
+
};
|
|
231
|
+
}
|
|
103
232
|
}
|
|
104
233
|
export default new Service();
|
|
@@ -6,12 +6,48 @@ import LIMIT_MAX from "../../Types/Database/LimitMax";
|
|
|
6
6
|
import BadDataException from "../../Types/Exception/BadDataException";
|
|
7
7
|
import Model from "Common/Models/DatabaseModels/Team";
|
|
8
8
|
import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
|
|
9
|
+
import ObjectID from "../../Types/ObjectID";
|
|
10
|
+
import TeamMember from "../../Models/DatabaseModels/TeamMember";
|
|
11
|
+
import TeamMemberService from "./TeamMemberService";
|
|
9
12
|
|
|
10
13
|
export class Service extends DatabaseService<Model> {
|
|
11
14
|
public constructor() {
|
|
12
15
|
super(Model);
|
|
13
16
|
}
|
|
14
17
|
|
|
18
|
+
public async getTeamsUserIsAPartOf(data: {
|
|
19
|
+
userId: ObjectID;
|
|
20
|
+
projectId: ObjectID;
|
|
21
|
+
}): Promise<Array<Model>> {
|
|
22
|
+
const teamMembers: Array<TeamMember> = await TeamMemberService.findBy({
|
|
23
|
+
query: {
|
|
24
|
+
userId: data.userId,
|
|
25
|
+
projectId: data.projectId,
|
|
26
|
+
},
|
|
27
|
+
select: {
|
|
28
|
+
team: {
|
|
29
|
+
name: true,
|
|
30
|
+
_id: true,
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
limit: LIMIT_MAX,
|
|
34
|
+
skip: 0,
|
|
35
|
+
props: {
|
|
36
|
+
isRoot: true,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const teams: Array<Model> = [];
|
|
41
|
+
|
|
42
|
+
for (const teamMember of teamMembers) {
|
|
43
|
+
if (teamMember.team) {
|
|
44
|
+
teams.push(teamMember.team);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return teams;
|
|
49
|
+
}
|
|
50
|
+
|
|
15
51
|
@CaptureSpan()
|
|
16
52
|
protected override async onBeforeUpdate(
|
|
17
53
|
updateBy: UpdateBy<Model>,
|
package/Types/Date.ts
CHANGED
|
@@ -14,6 +14,16 @@ export default class OneUptimeDate {
|
|
|
14
14
|
return new Date(timestamp * 1000);
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
public static getStartOfTheWeek(date: Date): Date {
|
|
18
|
+
date = this.fromString(date);
|
|
19
|
+
return moment(date).startOf("week").toDate();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public static getEndOfTheWeek(date: Date): Date {
|
|
23
|
+
date = this.fromString(date);
|
|
24
|
+
return moment(date).endOf("week").toDate();
|
|
25
|
+
}
|
|
26
|
+
|
|
17
27
|
public static getInBetweenDatesAsFormattedString(
|
|
18
28
|
inBetween: InBetween<Date>,
|
|
19
29
|
): string {
|
|
@@ -104,6 +114,11 @@ export default class OneUptimeDate {
|
|
|
104
114
|
return this.addRemoveDays(date, difference);
|
|
105
115
|
}
|
|
106
116
|
|
|
117
|
+
public static getDayOfTheWeekIndex(date: Date): number {
|
|
118
|
+
date = this.fromString(date);
|
|
119
|
+
return moment(date).weekday();
|
|
120
|
+
}
|
|
121
|
+
|
|
107
122
|
public static isOverlapping(
|
|
108
123
|
start: Date,
|
|
109
124
|
end: Date,
|
|
@@ -765,13 +780,13 @@ export default class OneUptimeDate {
|
|
|
765
780
|
public static isAfter(date: Date, startDate: Date): boolean {
|
|
766
781
|
date = this.fromString(date);
|
|
767
782
|
startDate = this.fromString(startDate);
|
|
768
|
-
return moment(date).isAfter(startDate);
|
|
783
|
+
return moment(date).isAfter(startDate, "seconds");
|
|
769
784
|
}
|
|
770
785
|
|
|
771
786
|
public static isOnOrAfter(date: Date, startDate: Date): boolean {
|
|
772
787
|
date = this.fromString(date);
|
|
773
788
|
startDate = this.fromString(startDate);
|
|
774
|
-
return moment(date).isSameOrAfter(startDate);
|
|
789
|
+
return moment(date).isSameOrAfter(startDate, "seconds");
|
|
775
790
|
}
|
|
776
791
|
|
|
777
792
|
public static getDayOfWeek(date: Date): DayOfWeek {
|
|
@@ -804,7 +819,8 @@ export default class OneUptimeDate {
|
|
|
804
819
|
public static isOnOrBefore(date: Date, endDate: Date): boolean {
|
|
805
820
|
date = this.fromString(date);
|
|
806
821
|
endDate = this.fromString(endDate);
|
|
807
|
-
|
|
822
|
+
|
|
823
|
+
return moment(date).isSameOrBefore(endDate, "seconds");
|
|
808
824
|
}
|
|
809
825
|
|
|
810
826
|
public static isEqualBySeconds(date: Date, startDate: Date): boolean {
|
|
@@ -815,13 +831,13 @@ export default class OneUptimeDate {
|
|
|
815
831
|
|
|
816
832
|
public static hasExpired(expirationDate: Date): boolean {
|
|
817
833
|
expirationDate = this.fromString(expirationDate);
|
|
818
|
-
return !moment(this.getCurrentDate()).isBefore(expirationDate);
|
|
834
|
+
return !moment(this.getCurrentDate()).isBefore(expirationDate, "seconds");
|
|
819
835
|
}
|
|
820
836
|
|
|
821
837
|
public static isBefore(date: Date, endDate: Date): boolean {
|
|
822
838
|
date = this.fromString(date);
|
|
823
839
|
endDate = this.fromString(endDate);
|
|
824
|
-
return moment(date).isBefore(endDate);
|
|
840
|
+
return moment(date).isBefore(endDate, "seconds");
|
|
825
841
|
}
|
|
826
842
|
|
|
827
843
|
public static getCurrentDateAsFormattedString(options?: {
|
|
@@ -1135,12 +1151,12 @@ export default class OneUptimeDate {
|
|
|
1135
1151
|
|
|
1136
1152
|
public static isInThePast(date: string | Date): boolean {
|
|
1137
1153
|
date = this.fromString(date);
|
|
1138
|
-
return moment(date).isBefore(new Date());
|
|
1154
|
+
return moment(date).isBefore(new Date(), "seconds");
|
|
1139
1155
|
}
|
|
1140
1156
|
|
|
1141
1157
|
public static isInTheFuture(date: string | Date): boolean {
|
|
1142
1158
|
date = this.fromString(date);
|
|
1143
|
-
return moment(date).isAfter(new Date());
|
|
1159
|
+
return moment(date).isAfter(new Date(), "seconds");
|
|
1144
1160
|
}
|
|
1145
1161
|
|
|
1146
1162
|
public static fromString(date: string | JSONObject | Date): Date {
|