@oneuptime/common 7.0.3035 → 7.0.3038
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/IncidentNoteTemplate.ts +8 -0
- package/Models/DatabaseModels/IncidentTemplate.ts +8 -0
- package/Models/DatabaseModels/Index.ts +6 -0
- package/Models/DatabaseModels/ScheduledMaintenanceTemplate.ts +953 -0
- package/Models/DatabaseModels/ScheduledMaintenanceTemplateOwnerTeam.ts +390 -0
- package/Models/DatabaseModels/ScheduledMaintenanceTemplateOwnerUser.ts +389 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1725880508430-MigrationName.ts +269 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1725881099935-MigrationName.ts +17 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1725881475134-MigrationName.ts +35 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1725884177663-MigrationName.ts +29 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1725898621366-MigrationName.ts +29 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1725900315712-MigrationName.ts +59 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/1725901024444-MigrationName.ts +23 -0
- package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +14 -0
- package/Server/Services/Index.ts +8 -0
- package/Server/Services/ScheduledMaintenanceService.ts +1 -1
- package/Server/Services/ScheduledMaintenanceTemplateOwnerTeamService.ts +10 -0
- package/Server/Services/ScheduledMaintenanceTemplateOwnerUserService.ts +10 -0
- package/Server/Services/ScheduledMaintenanceTemplateService.ts +318 -0
- package/Types/Permission.ts +115 -1
- package/UI/Components/Detail/Detail.tsx +12 -3
- package/UI/Components/Detail/Field.ts +1 -1
- package/build/dist/Models/DatabaseModels/IncidentNoteTemplate.js +8 -0
- package/build/dist/Models/DatabaseModels/IncidentNoteTemplate.js.map +1 -1
- package/build/dist/Models/DatabaseModels/IncidentTemplate.js +8 -0
- package/build/dist/Models/DatabaseModels/IncidentTemplate.js.map +1 -1
- package/build/dist/Models/DatabaseModels/Index.js +6 -0
- package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
- package/build/dist/Models/DatabaseModels/ScheduledMaintenanceTemplate.js +976 -0
- package/build/dist/Models/DatabaseModels/ScheduledMaintenanceTemplate.js.map +1 -0
- package/build/dist/Models/DatabaseModels/ScheduledMaintenanceTemplateOwnerTeam.js +402 -0
- package/build/dist/Models/DatabaseModels/ScheduledMaintenanceTemplateOwnerTeam.js.map +1 -0
- package/build/dist/Models/DatabaseModels/ScheduledMaintenanceTemplateOwnerUser.js +401 -0
- package/build/dist/Models/DatabaseModels/ScheduledMaintenanceTemplateOwnerUser.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1725880508430-MigrationName.js +98 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1725880508430-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1725881099935-MigrationName.js +12 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1725881099935-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1725881475134-MigrationName.js +18 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1725881475134-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1725884177663-MigrationName.js +16 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1725884177663-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1725898621366-MigrationName.js +16 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1725898621366-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1725900315712-MigrationName.js +26 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1725900315712-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1725901024444-MigrationName.js +14 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1725901024444-MigrationName.js.map +1 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +14 -0
- package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
- package/build/dist/Server/Services/Index.js +7 -0
- package/build/dist/Server/Services/Index.js.map +1 -1
- package/build/dist/Server/Services/ScheduledMaintenanceService.js +1 -1
- package/build/dist/Server/Services/ScheduledMaintenanceService.js.map +1 -1
- package/build/dist/Server/Services/ScheduledMaintenanceTemplateOwnerTeamService.js +9 -0
- package/build/dist/Server/Services/ScheduledMaintenanceTemplateOwnerTeamService.js.map +1 -0
- package/build/dist/Server/Services/ScheduledMaintenanceTemplateOwnerUserService.js +9 -0
- package/build/dist/Server/Services/ScheduledMaintenanceTemplateOwnerUserService.js.map +1 -0
- package/build/dist/Server/Services/ScheduledMaintenanceTemplateService.js +203 -0
- package/build/dist/Server/Services/ScheduledMaintenanceTemplateService.js.map +1 -0
- package/build/dist/Types/Permission.js +97 -1
- package/build/dist/Types/Permission.js.map +1 -1
- package/build/dist/UI/Components/Detail/Detail.js +9 -1
- package/build/dist/UI/Components/Detail/Detail.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from "typeorm";
|
|
2
|
+
|
|
3
|
+
export class MigrationName1725881475134 implements MigrationInterface {
|
|
4
|
+
public name = "MigrationName1725881475134";
|
|
5
|
+
|
|
6
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
+
await queryRunner.query(
|
|
8
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" ADD "templateName" character varying(100) NOT NULL`,
|
|
9
|
+
);
|
|
10
|
+
await queryRunner.query(
|
|
11
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" ADD "templateDescription" character varying(500) NOT NULL`,
|
|
12
|
+
);
|
|
13
|
+
await queryRunner.query(
|
|
14
|
+
`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "rotation" SET DEFAULT '{"_type":"Recurring","value":{"intervalType":"Day","intervalCount":{"_type":"PositiveNumber","value":1}}}'`,
|
|
15
|
+
);
|
|
16
|
+
await queryRunner.query(
|
|
17
|
+
`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "restrictionTimes" SET DEFAULT '{"_type":"RestrictionTimes","value":{"restictionType":"None","dayRestrictionTimes":null,"weeklyRestrictionTimes":[]}}'`,
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
22
|
+
await queryRunner.query(
|
|
23
|
+
`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "restrictionTimes" SET DEFAULT '{"_type": "RestrictionTimes", "value": {"restictionType": "None", "dayRestrictionTimes": null, "weeklyRestrictionTimes": []}}'`,
|
|
24
|
+
);
|
|
25
|
+
await queryRunner.query(
|
|
26
|
+
`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "rotation" SET DEFAULT '{"_type": "Recurring", "value": {"intervalType": "Day", "intervalCount": {"_type": "PositiveNumber", "value": 1}}}'`,
|
|
27
|
+
);
|
|
28
|
+
await queryRunner.query(
|
|
29
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" DROP COLUMN "templateDescription"`,
|
|
30
|
+
);
|
|
31
|
+
await queryRunner.query(
|
|
32
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" DROP COLUMN "templateName"`,
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from "typeorm";
|
|
2
|
+
|
|
3
|
+
export class MigrationName1725884177663 implements MigrationInterface {
|
|
4
|
+
public name = "MigrationName1725884177663";
|
|
5
|
+
|
|
6
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
+
await queryRunner.query(
|
|
8
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" DROP CONSTRAINT "FK_aea47be8b8af9673e9639e7dae3"`,
|
|
9
|
+
);
|
|
10
|
+
await queryRunner.query(
|
|
11
|
+
`DROP INDEX "public"."IDX_aea47be8b8af9673e9639e7dae"`,
|
|
12
|
+
);
|
|
13
|
+
await queryRunner.query(
|
|
14
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" DROP COLUMN "currentScheduledMaintenanceStateId"`,
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
19
|
+
await queryRunner.query(
|
|
20
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" ADD "currentScheduledMaintenanceStateId" uuid NOT NULL`,
|
|
21
|
+
);
|
|
22
|
+
await queryRunner.query(
|
|
23
|
+
`CREATE INDEX "IDX_aea47be8b8af9673e9639e7dae" ON "ScheduledMaintenanceTemplate" ("currentScheduledMaintenanceStateId") `,
|
|
24
|
+
);
|
|
25
|
+
await queryRunner.query(
|
|
26
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" ADD CONSTRAINT "FK_aea47be8b8af9673e9639e7dae3" FOREIGN KEY ("currentScheduledMaintenanceStateId") REFERENCES "ScheduledMaintenanceState"("_id") ON DELETE NO ACTION ON UPDATE NO ACTION`,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from "typeorm";
|
|
2
|
+
|
|
3
|
+
export class MigrationName1725898621366 implements MigrationInterface {
|
|
4
|
+
public name = "MigrationName1725898621366";
|
|
5
|
+
|
|
6
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
+
await queryRunner.query(
|
|
8
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" ADD "isRecurringEvent" boolean NOT NULL DEFAULT false`,
|
|
9
|
+
);
|
|
10
|
+
await queryRunner.query(
|
|
11
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" ALTER COLUMN "startsAt" DROP NOT NULL`,
|
|
12
|
+
);
|
|
13
|
+
await queryRunner.query(
|
|
14
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" ALTER COLUMN "endsAt" DROP NOT NULL`,
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
19
|
+
await queryRunner.query(
|
|
20
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" ALTER COLUMN "endsAt" SET NOT NULL`,
|
|
21
|
+
);
|
|
22
|
+
await queryRunner.query(
|
|
23
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" ALTER COLUMN "startsAt" SET NOT NULL`,
|
|
24
|
+
);
|
|
25
|
+
await queryRunner.query(
|
|
26
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" DROP COLUMN "isRecurringEvent"`,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from "typeorm";
|
|
2
|
+
|
|
3
|
+
export class MigrationName1725900315712 implements MigrationInterface {
|
|
4
|
+
public name = "MigrationName1725900315712";
|
|
5
|
+
|
|
6
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
+
await queryRunner.query(
|
|
8
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" DROP COLUMN "startsAt"`,
|
|
9
|
+
);
|
|
10
|
+
await queryRunner.query(
|
|
11
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" DROP COLUMN "endsAt"`,
|
|
12
|
+
);
|
|
13
|
+
await queryRunner.query(
|
|
14
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" ADD "firstEventScheduledAt" TIMESTAMP WITH TIME ZONE`,
|
|
15
|
+
);
|
|
16
|
+
await queryRunner.query(
|
|
17
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" ADD "firstEventStartsAt" TIMESTAMP WITH TIME ZONE`,
|
|
18
|
+
);
|
|
19
|
+
await queryRunner.query(
|
|
20
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" ADD "firstEventEndsAt" TIMESTAMP WITH TIME ZONE`,
|
|
21
|
+
);
|
|
22
|
+
await queryRunner.query(
|
|
23
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" ADD "scheduleNextEventAt" boolean NOT NULL DEFAULT false`,
|
|
24
|
+
);
|
|
25
|
+
await queryRunner.query(
|
|
26
|
+
`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "rotation" SET DEFAULT '{"_type":"Recurring","value":{"intervalType":"Day","intervalCount":{"_type":"PositiveNumber","value":1}}}'`,
|
|
27
|
+
);
|
|
28
|
+
await queryRunner.query(
|
|
29
|
+
`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "restrictionTimes" SET DEFAULT '{"_type":"RestrictionTimes","value":{"restictionType":"None","dayRestrictionTimes":null,"weeklyRestrictionTimes":[]}}'`,
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
34
|
+
await queryRunner.query(
|
|
35
|
+
`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "restrictionTimes" SET DEFAULT '{"_type": "RestrictionTimes", "value": {"restictionType": "None", "dayRestrictionTimes": null, "weeklyRestrictionTimes": []}}'`,
|
|
36
|
+
);
|
|
37
|
+
await queryRunner.query(
|
|
38
|
+
`ALTER TABLE "OnCallDutyPolicyScheduleLayer" ALTER COLUMN "rotation" SET DEFAULT '{"_type": "Recurring", "value": {"intervalType": "Day", "intervalCount": {"_type": "PositiveNumber", "value": 1}}}'`,
|
|
39
|
+
);
|
|
40
|
+
await queryRunner.query(
|
|
41
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" DROP COLUMN "scheduleNextEventAt"`,
|
|
42
|
+
);
|
|
43
|
+
await queryRunner.query(
|
|
44
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" DROP COLUMN "firstEventEndsAt"`,
|
|
45
|
+
);
|
|
46
|
+
await queryRunner.query(
|
|
47
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" DROP COLUMN "firstEventStartsAt"`,
|
|
48
|
+
);
|
|
49
|
+
await queryRunner.query(
|
|
50
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" DROP COLUMN "firstEventScheduledAt"`,
|
|
51
|
+
);
|
|
52
|
+
await queryRunner.query(
|
|
53
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" ADD "endsAt" TIMESTAMP WITH TIME ZONE`,
|
|
54
|
+
);
|
|
55
|
+
await queryRunner.query(
|
|
56
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" ADD "startsAt" TIMESTAMP WITH TIME ZONE`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { MigrationInterface, QueryRunner } from "typeorm";
|
|
2
|
+
|
|
3
|
+
export class MigrationName1725901024444 implements MigrationInterface {
|
|
4
|
+
public name = "MigrationName1725901024444";
|
|
5
|
+
|
|
6
|
+
public async up(queryRunner: QueryRunner): Promise<void> {
|
|
7
|
+
await queryRunner.query(
|
|
8
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" DROP COLUMN "scheduleNextEventAt"`,
|
|
9
|
+
);
|
|
10
|
+
await queryRunner.query(
|
|
11
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" ADD "scheduleNextEventAt" TIMESTAMP WITH TIME ZONE`,
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
public async down(queryRunner: QueryRunner): Promise<void> {
|
|
16
|
+
await queryRunner.query(
|
|
17
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" DROP COLUMN "scheduleNextEventAt"`,
|
|
18
|
+
);
|
|
19
|
+
await queryRunner.query(
|
|
20
|
+
`ALTER TABLE "ScheduledMaintenanceTemplate" ADD "scheduleNextEventAt" boolean NOT NULL`,
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -51,6 +51,13 @@ import { MigrationName1725379949648 } from "./1725379949648-MigrationName";
|
|
|
51
51
|
import { MigrationName1725551629492 } from "./1725551629492-MigrationName";
|
|
52
52
|
import { MigrationName1725556630384 } from "./1725556630384-MigrationName";
|
|
53
53
|
import { MigrationName1725618842598 } from "./1725618842598-MigrationName";
|
|
54
|
+
import { MigrationName1725880508430 } from "./1725880508430-MigrationName";
|
|
55
|
+
import { MigrationName1725881099935 } from "./1725881099935-MigrationName";
|
|
56
|
+
import { MigrationName1725881475134 } from "./1725881475134-MigrationName";
|
|
57
|
+
import { MigrationName1725884177663 } from "./1725884177663-MigrationName";
|
|
58
|
+
import { MigrationName1725898621366 } from "./1725898621366-MigrationName";
|
|
59
|
+
import { MigrationName1725900315712 } from "./1725900315712-MigrationName";
|
|
60
|
+
import { MigrationName1725901024444 } from "./1725901024444-MigrationName";
|
|
54
61
|
|
|
55
62
|
export default [
|
|
56
63
|
InitialMigration,
|
|
@@ -106,4 +113,11 @@ export default [
|
|
|
106
113
|
MigrationName1725551629492,
|
|
107
114
|
MigrationName1725556630384,
|
|
108
115
|
MigrationName1725618842598,
|
|
116
|
+
MigrationName1725880508430,
|
|
117
|
+
MigrationName1725881099935,
|
|
118
|
+
MigrationName1725881475134,
|
|
119
|
+
MigrationName1725884177663,
|
|
120
|
+
MigrationName1725898621366,
|
|
121
|
+
MigrationName1725900315712,
|
|
122
|
+
MigrationName1725901024444,
|
|
109
123
|
];
|
package/Server/Services/Index.ts
CHANGED
|
@@ -133,6 +133,9 @@ import TelemetryAttributeService from "./TelemetryAttributeService";
|
|
|
133
133
|
import TelemetryExceptionService from "./TelemetryExceptionService";
|
|
134
134
|
import ExceptionInstanceService from "./ExceptionInstanceService";
|
|
135
135
|
import CopilotActionTypePriorityService from "./CopilotActionTypePriorityService";
|
|
136
|
+
import ScheduledMaintenanceTemplateService from "./ScheduledMaintenanceTemplateService";
|
|
137
|
+
import ScheduledMaintenanceTemplateOwnerTeamService from "./ScheduledMaintenanceTemplateOwnerTeamService";
|
|
138
|
+
import ScheduledMaintenanceTemplateOwnerUserService from "./ScheduledMaintenanceTemplateOwnerUserService";
|
|
136
139
|
|
|
137
140
|
const services: Array<BaseService> = [
|
|
138
141
|
AcmeCertificateService,
|
|
@@ -277,6 +280,11 @@ const services: Array<BaseService> = [
|
|
|
277
280
|
CopilotActionTypePriorityService,
|
|
278
281
|
|
|
279
282
|
TelemetryExceptionService,
|
|
283
|
+
|
|
284
|
+
// scheduled maintenance templates
|
|
285
|
+
ScheduledMaintenanceTemplateService,
|
|
286
|
+
ScheduledMaintenanceTemplateOwnerTeamService,
|
|
287
|
+
ScheduledMaintenanceTemplateOwnerUserService,
|
|
280
288
|
];
|
|
281
289
|
|
|
282
290
|
export const AnalyticsServices: Array<
|
|
@@ -76,7 +76,7 @@ export class Service extends DatabaseService<Model> {
|
|
|
76
76
|
protected override async onBeforeCreate(
|
|
77
77
|
createBy: CreateBy<Model>,
|
|
78
78
|
): Promise<OnCreate<Model>> {
|
|
79
|
-
if (!createBy.props.tenantId) {
|
|
79
|
+
if (!createBy.props.tenantId && !createBy.data.projectId) {
|
|
80
80
|
throw new BadDataException(
|
|
81
81
|
"ProjectId required to create scheduled maintenane.",
|
|
82
82
|
);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import DatabaseService from "./DatabaseService";
|
|
2
|
+
import Model from "Common/Models/DatabaseModels/ScheduledMaintenanceTemplateOwnerTeam";
|
|
3
|
+
|
|
4
|
+
export class Service extends DatabaseService<Model> {
|
|
5
|
+
public constructor() {
|
|
6
|
+
super(Model);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default new Service();
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import DatabaseService from "./DatabaseService";
|
|
2
|
+
import Model from "Common/Models/DatabaseModels/ScheduledMaintenanceTemplateOwnerUser";
|
|
3
|
+
|
|
4
|
+
export class Service extends DatabaseService<Model> {
|
|
5
|
+
public constructor() {
|
|
6
|
+
super(Model);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default new Service();
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { OnCreate, OnUpdate } from "../Types/Database/Hooks";
|
|
2
|
+
import DatabaseService from "./DatabaseService";
|
|
3
|
+
import ScheduledMaintenanceTemplateOwnerTeamService from "./ScheduledMaintenanceTemplateOwnerTeamService";
|
|
4
|
+
import ScheduledMaintenanceTemplateOwnerUserService from "./ScheduledMaintenanceTemplateOwnerUserService";
|
|
5
|
+
import DatabaseCommonInteractionProps from "../../Types/BaseDatabase/DatabaseCommonInteractionProps";
|
|
6
|
+
import ObjectID from "../../Types/ObjectID";
|
|
7
|
+
import Typeof from "../../Types/Typeof";
|
|
8
|
+
import Model from "Common/Models/DatabaseModels/ScheduledMaintenanceTemplate";
|
|
9
|
+
import ScheduledMaintenanceTemplateOwnerTeam from "Common/Models/DatabaseModels/ScheduledMaintenanceTemplateOwnerTeam";
|
|
10
|
+
import ScheduledMaintenanceTemplateOwnerUser from "Common/Models/DatabaseModels/ScheduledMaintenanceTemplateOwnerUser";
|
|
11
|
+
import CreateBy from "../Types/Database/CreateBy";
|
|
12
|
+
import OneUptimeDate from "../../Types/Date";
|
|
13
|
+
import Recurring from "../../Types/Events/Recurring";
|
|
14
|
+
import UpdateBy from "../Types/Database/UpdateBy";
|
|
15
|
+
import QueryDeepPartialEntity from "../../Types/Database/PartialEntity";
|
|
16
|
+
import LIMIT_MAX from "../../Types/Database/LimitMax";
|
|
17
|
+
import BadDataException from "../../Types/Exception/BadDataException";
|
|
18
|
+
|
|
19
|
+
export class Service extends DatabaseService<Model> {
|
|
20
|
+
public constructor() {
|
|
21
|
+
super(Model);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public validateEventTemplate(template: Model): void {
|
|
25
|
+
// if recurring then start, end, scheduled time should not be null and all of them should be in the future.
|
|
26
|
+
if (template.isRecurringEvent) {
|
|
27
|
+
const startDate: Date | undefined = template.firstEventStartsAt;
|
|
28
|
+
const endDate: Date | undefined = template.firstEventEndsAt;
|
|
29
|
+
const scheduledTime: Date | undefined = template.firstEventScheduledAt;
|
|
30
|
+
|
|
31
|
+
if (!startDate) {
|
|
32
|
+
throw new BadDataException(
|
|
33
|
+
"Start date is required for recurring events.",
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (!endDate) {
|
|
38
|
+
throw new BadDataException(
|
|
39
|
+
"End date is required for recurring events.",
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!scheduledTime) {
|
|
44
|
+
throw new BadDataException(
|
|
45
|
+
"Scheduled time is required for recurring events.",
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// check if all dates are in the future.
|
|
50
|
+
|
|
51
|
+
if (OneUptimeDate.isInTheFuture(startDate) === false) {
|
|
52
|
+
throw new BadDataException("Start date should be in the future.");
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (OneUptimeDate.isInTheFuture(endDate) === false) {
|
|
56
|
+
throw new BadDataException("End date should be in the future.");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (OneUptimeDate.isInTheFuture(scheduledTime) === false) {
|
|
60
|
+
throw new BadDataException("Scheduled time should be in the future.");
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// make sure scheduedDate is < start date
|
|
64
|
+
if (!OneUptimeDate.isBefore(scheduledTime, startDate)) {
|
|
65
|
+
throw new BadDataException(
|
|
66
|
+
"Scheduled time should be less than start date.",
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// make sure scheduledDate is < end date
|
|
71
|
+
|
|
72
|
+
if (!OneUptimeDate.isBefore(scheduledTime, endDate)) {
|
|
73
|
+
throw new BadDataException(
|
|
74
|
+
"Scheduled time should be less than end date.",
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// make sure start date is < end date
|
|
79
|
+
|
|
80
|
+
if (!OneUptimeDate.isBefore(startDate, endDate)) {
|
|
81
|
+
throw new BadDataException("Start date should be less than end date.");
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// check recurring internval
|
|
85
|
+
|
|
86
|
+
if (template.recurringInterval === undefined) {
|
|
87
|
+
throw new BadDataException(
|
|
88
|
+
"Recurring interval is required for recurring events.",
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public getNextEventTime(data: {
|
|
95
|
+
dateAndTime: Date;
|
|
96
|
+
recurringInterval: Recurring;
|
|
97
|
+
}): Date {
|
|
98
|
+
// check if firstScheduledAt is in the future, and if yes return that.
|
|
99
|
+
|
|
100
|
+
if (OneUptimeDate.isInTheFuture(data.dateAndTime)) {
|
|
101
|
+
return data.dateAndTime;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// if not then calculate the next event time.
|
|
105
|
+
|
|
106
|
+
return Recurring.getNextDate(data.dateAndTime, data.recurringInterval);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
protected override async onBeforeCreate(
|
|
110
|
+
createBy: CreateBy<Model>,
|
|
111
|
+
): Promise<OnCreate<Model>> {
|
|
112
|
+
this.validateEventTemplate(createBy.data);
|
|
113
|
+
|
|
114
|
+
if (createBy.data.isRecurringEvent) {
|
|
115
|
+
// if all is good then the next scheduled at time should be set.
|
|
116
|
+
createBy.data.scheduleNextEventAt = this.getNextEventTime({
|
|
117
|
+
dateAndTime: createBy.data.firstEventScheduledAt!,
|
|
118
|
+
recurringInterval: createBy.data.recurringInterval!,
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
createBy: createBy,
|
|
124
|
+
carryForward: false,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
protected override async onBeforeUpdate(
|
|
129
|
+
updateBy: UpdateBy<Model>,
|
|
130
|
+
): Promise<OnUpdate<Model>> {
|
|
131
|
+
const newTemplate: QueryDeepPartialEntity<Model> = updateBy.data;
|
|
132
|
+
|
|
133
|
+
const existingTemplates: Array<Model> = await this.findBy({
|
|
134
|
+
query: updateBy.query,
|
|
135
|
+
select: {
|
|
136
|
+
_id: true,
|
|
137
|
+
isRecurringEvent: true,
|
|
138
|
+
firstEventScheduledAt: true,
|
|
139
|
+
recurringInterval: true,
|
|
140
|
+
firstEventEndsAt: true,
|
|
141
|
+
firstEventStartsAt: true,
|
|
142
|
+
},
|
|
143
|
+
limit: LIMIT_MAX,
|
|
144
|
+
skip: 0,
|
|
145
|
+
props: {
|
|
146
|
+
isRoot: true,
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
for (const template of existingTemplates) {
|
|
151
|
+
let isRecurring: boolean = Boolean(template.isRecurringEvent);
|
|
152
|
+
|
|
153
|
+
if (Object.keys(newTemplate).includes("isRecurringEvent")) {
|
|
154
|
+
isRecurring = newTemplate.isRecurringEvent as boolean;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
let firstEventScheduledAt: Date | undefined =
|
|
158
|
+
template.firstEventScheduledAt;
|
|
159
|
+
|
|
160
|
+
if (Object.keys(newTemplate).includes("firstEventScheduledAt")) {
|
|
161
|
+
firstEventScheduledAt = newTemplate.firstEventScheduledAt as Date;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
let recurringInterval: Recurring | undefined = template.recurringInterval;
|
|
165
|
+
|
|
166
|
+
if (Object.keys(newTemplate).includes("recurringInterval")) {
|
|
167
|
+
recurringInterval = newTemplate.recurringInterval as Recurring;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
let firstEventEndsAt: Date | undefined = template.firstEventEndsAt;
|
|
171
|
+
|
|
172
|
+
if (Object.keys(newTemplate).includes("firstEventEndsAt")) {
|
|
173
|
+
firstEventEndsAt = newTemplate.firstEventEndsAt as Date;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
let firstEventStartsAt: Date | undefined = template.firstEventStartsAt;
|
|
177
|
+
|
|
178
|
+
if (Object.keys(newTemplate).includes("firstEventStartsAt")) {
|
|
179
|
+
firstEventStartsAt = newTemplate.firstEventStartsAt as Date;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (isRecurring) {
|
|
183
|
+
// make sure all are not null.
|
|
184
|
+
|
|
185
|
+
if (!firstEventScheduledAt) {
|
|
186
|
+
throw new BadDataException(
|
|
187
|
+
"First event scheduled at is required for recurring events.",
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (!recurringInterval) {
|
|
192
|
+
throw new BadDataException(
|
|
193
|
+
"Recurring interval is required for recurring events.",
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (!firstEventEndsAt) {
|
|
198
|
+
throw new BadDataException(
|
|
199
|
+
"First event ends at is required for recurring events.",
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (!firstEventStartsAt) {
|
|
204
|
+
throw new BadDataException(
|
|
205
|
+
"First event starts at is required for recurring events.",
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// make sure scheduedDate is < start date
|
|
210
|
+
if (
|
|
211
|
+
!OneUptimeDate.isBefore(firstEventScheduledAt, firstEventStartsAt)
|
|
212
|
+
) {
|
|
213
|
+
throw new BadDataException(
|
|
214
|
+
"Scheduled time should be less than start date.",
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// make sure scheduledDate is < end date
|
|
219
|
+
|
|
220
|
+
if (!OneUptimeDate.isBefore(firstEventScheduledAt, firstEventEndsAt)) {
|
|
221
|
+
throw new BadDataException(
|
|
222
|
+
"Scheduled time should be less than end date.",
|
|
223
|
+
);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// make sure start date is < end date
|
|
227
|
+
|
|
228
|
+
if (!OneUptimeDate.isBefore(firstEventStartsAt, firstEventEndsAt)) {
|
|
229
|
+
throw new BadDataException(
|
|
230
|
+
"Start date should be less than end date.",
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// now get next interval time.
|
|
235
|
+
|
|
236
|
+
newTemplate.scheduleNextEventAt = this.getNextEventTime({
|
|
237
|
+
dateAndTime: firstEventScheduledAt,
|
|
238
|
+
recurringInterval: recurringInterval,
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
updateBy.data = newTemplate;
|
|
244
|
+
|
|
245
|
+
return {
|
|
246
|
+
updateBy: updateBy,
|
|
247
|
+
carryForward: false,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
protected override async onCreateSuccess(
|
|
252
|
+
onCreate: OnCreate<Model>,
|
|
253
|
+
createdItem: Model,
|
|
254
|
+
): Promise<Model> {
|
|
255
|
+
// add owners.
|
|
256
|
+
|
|
257
|
+
if (
|
|
258
|
+
createdItem.projectId &&
|
|
259
|
+
createdItem.id &&
|
|
260
|
+
onCreate.createBy.miscDataProps &&
|
|
261
|
+
(onCreate.createBy.miscDataProps["ownerTeams"] ||
|
|
262
|
+
onCreate.createBy.miscDataProps["ownerUsers"])
|
|
263
|
+
) {
|
|
264
|
+
await this.addOwners(
|
|
265
|
+
createdItem.projectId,
|
|
266
|
+
createdItem.id,
|
|
267
|
+
(onCreate.createBy.miscDataProps["ownerUsers"] as Array<ObjectID>) ||
|
|
268
|
+
[],
|
|
269
|
+
(onCreate.createBy.miscDataProps["ownerTeams"] as Array<ObjectID>) ||
|
|
270
|
+
[],
|
|
271
|
+
onCreate.createBy.props,
|
|
272
|
+
);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return createdItem;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
public async addOwners(
|
|
279
|
+
projectId: ObjectID,
|
|
280
|
+
scheduledMaintenanceTemplateId: ObjectID,
|
|
281
|
+
userIds: Array<ObjectID>,
|
|
282
|
+
teamIds: Array<ObjectID>,
|
|
283
|
+
props: DatabaseCommonInteractionProps,
|
|
284
|
+
): Promise<void> {
|
|
285
|
+
for (let teamId of teamIds) {
|
|
286
|
+
if (typeof teamId === Typeof.String) {
|
|
287
|
+
teamId = new ObjectID(teamId.toString());
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const teamOwner: ScheduledMaintenanceTemplateOwnerTeam =
|
|
291
|
+
new ScheduledMaintenanceTemplateOwnerTeam();
|
|
292
|
+
teamOwner.scheduledMaintenanceTemplateId = scheduledMaintenanceTemplateId;
|
|
293
|
+
teamOwner.projectId = projectId;
|
|
294
|
+
teamOwner.teamId = teamId;
|
|
295
|
+
|
|
296
|
+
await ScheduledMaintenanceTemplateOwnerTeamService.create({
|
|
297
|
+
data: teamOwner,
|
|
298
|
+
props: props,
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
for (let userId of userIds) {
|
|
303
|
+
if (typeof userId === Typeof.String) {
|
|
304
|
+
userId = new ObjectID(userId.toString());
|
|
305
|
+
}
|
|
306
|
+
const teamOwner: ScheduledMaintenanceTemplateOwnerUser =
|
|
307
|
+
new ScheduledMaintenanceTemplateOwnerUser();
|
|
308
|
+
teamOwner.scheduledMaintenanceTemplateId = scheduledMaintenanceTemplateId;
|
|
309
|
+
teamOwner.projectId = projectId;
|
|
310
|
+
teamOwner.userId = userId;
|
|
311
|
+
await ScheduledMaintenanceTemplateOwnerUserService.create({
|
|
312
|
+
data: teamOwner,
|
|
313
|
+
props: props,
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
export default new Service();
|