mirror of
https://github.com/OneUptime/oneuptime
synced 2024-11-21 22:59:07 +00:00
feat: Implement cascading delete for status page resources in MonitorGroupService and MonitorService
This commit is contained in:
parent
346891e85d
commit
32fa57c63b
@ -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,
|
||||
|
@ -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[],
|
||||
|
Loading…
Reference in New Issue
Block a user