Skip to content

Commit

Permalink
feat: Implement cascading delete for status page resources in Monitor…
Browse files Browse the repository at this point in the history
…GroupService and MonitorService
  • Loading branch information
simlarsen committed Sep 30, 2024
1 parent 346891e commit 32fa57c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
24 changes: 24 additions & 0 deletions Common/Server/Services/MonitorGroupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 24 additions & 1 deletion Common/Server/Services/MonitorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down Expand Up @@ -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[],
Expand Down

0 comments on commit 32fa57c

Please sign in to comment.