feat: Implement cascading delete for status page resources in MonitorGroupService and MonitorService

This commit is contained in:
Simon Larsen 2024-09-30 15:12:51 +01:00
parent 346891e85d
commit 32fa57c63b
No known key found for this signature in database
GPG Key ID: 96C5DCA24769DBCA
2 changed files with 48 additions and 1 deletions

View File

@ -12,12 +12,36 @@ import MonitorGroup from "Common/Models/DatabaseModels/MonitorGroup";
import MonitorGroupResource from "Common/Models/DatabaseModels/MonitorGroupResource";
import MonitorStatus from "Common/Models/DatabaseModels/MonitorStatus";
import MonitorStatusTimeline from "Common/Models/DatabaseModels/MonitorStatusTimeline";
import DeleteBy from "../Types/Database/DeleteBy";
import { OnDelete } from "../Types/Database/Hooks";
import StatusPageResourceService from "./StatusPageResourceService";
export class Service extends DatabaseService<MonitorGroup> {
public constructor() {
super(MonitorGroup);
}
protected override async onBeforeDelete(
deleteBy: DeleteBy<MonitorGroup>,
): Promise<OnDelete<MonitorGroup>> {
if (deleteBy.query._id) {
// delete all the status page resource for this monitor.
await StatusPageResourceService.deleteBy({
query: {
monitorGroupId: new ObjectID(deleteBy.query._id as string),
},
limit: LIMIT_MAX,
skip: 0,
props: {
isRoot: true,
},
});
}
return { deleteBy, carryForward: null };
}
public async getStatusTimeline(
monitorGroupId: ObjectID,
startDate: Date,

View File

@ -21,7 +21,7 @@ import URL from "../../Types/API/URL";
import DatabaseCommonInteractionProps from "../../Types/BaseDatabase/DatabaseCommonInteractionProps";
import SortOrder from "../../Types/BaseDatabase/SortOrder";
import { PlanType } from "../../Types/Billing/SubscriptionPlan";
import { LIMIT_PER_PROJECT } from "../../Types/Database/LimitMax";
import LIMIT_MAX, { LIMIT_PER_PROJECT } from "../../Types/Database/LimitMax";
import BadDataException from "../../Types/Exception/BadDataException";
import { JSONObject } from "../../Types/JSON";
import MonitorType, {
@ -50,12 +50,35 @@ import { CallRequestMessage } from "../../Types/Call/CallRequest";
import UserNotificationSettingService from "./UserNotificationSettingService";
import NotificationSettingEventType from "../../Types/NotificationSetting/NotificationSettingEventType";
import Query from "../Types/Database/Query";
import DeleteBy from "../Types/Database/DeleteBy";
import StatusPageResourceService from "./StatusPageResourceService";
export class Service extends DatabaseService<Model> {
public constructor() {
super(Model);
}
protected override async onBeforeDelete(
deleteBy: DeleteBy<Model>,
): Promise<OnDelete<Model>> {
if (deleteBy.query._id) {
// delete all the status page resource for this monitor.
await StatusPageResourceService.deleteBy({
query: {
monitorId: new ObjectID(deleteBy.query._id as string),
},
limit: LIMIT_MAX,
skip: 0,
props: {
isRoot: true,
},
});
}
return { deleteBy, carryForward: null };
}
protected override async onDeleteSuccess(
onDelete: OnDelete<Model>,
_itemIdsBeforeDelete: ObjectID[],