maintenacne window
This commit is contained in:
1 parent
533a8911cd
commit
a4a3249b5b
2 files changed
+54
-15
No files matched your search
@@ -21,7 +21,17 @@ class MaintenanceWindowController {
|
||||
try {
|
||||
const validatedBody = createMaintenanceWindowBodyValidation.parse(req.body);
|
||||
const teamId = requireTeamId(req?.user?.teamId);
|
||||
await this.maintenanceWindowService.createMaintenanceWindow({ teamId, body: validatedBody });
|
||||
|
||||
const monitorIDs = validatedBody.monitors;
|
||||
const name = validatedBody.name;
|
||||
const active = validatedBody.active ? validatedBody.active : true;
|
||||
const duration = validatedBody.duration;
|
||||
const durationUnit = validatedBody.durationUnit;
|
||||
const repeat = validatedBody.repeat;
|
||||
const start = validatedBody.start;
|
||||
const end = validatedBody.end;
|
||||
|
||||
await this.maintenanceWindowService.createMaintenanceWindow({ teamId, monitorIDs, name, active, duration, durationUnit, repeat, start, end });
|
||||
|
||||
return res.status(200).json({
|
||||
success: true,
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
import { IMaintenanceWindowsRepository, IMonitorsRepository } from "@/repositories/index.js";
|
||||
import type { MaintenanceWindow } from "@/types/index.js";
|
||||
import type { DurationUnit, MaintenanceWindow } from "@/types/index.js";
|
||||
import { AppError } from "@/utils/AppError.js";
|
||||
|
||||
const SERVICE_NAME = "maintenanceWindowService";
|
||||
|
||||
export interface IMaintenanceWindowService {
|
||||
createMaintenanceWindow(params: { teamId: string; body: Partial<MaintenanceWindow> & { monitors: string[] } }): Promise<void>;
|
||||
createMaintenanceWindow(params: {
|
||||
teamId: string;
|
||||
monitorIDs: string[];
|
||||
name: string;
|
||||
active: boolean;
|
||||
duration: number;
|
||||
durationUnit: DurationUnit;
|
||||
repeat: number;
|
||||
start: string;
|
||||
end: string;
|
||||
}): Promise<void>;
|
||||
getMaintenanceWindowById(params: { id: string; teamId: string }): Promise<MaintenanceWindow>;
|
||||
getMaintenanceWindowsByTeamId(params: {
|
||||
teamId: string;
|
||||
@@ -40,9 +50,28 @@ export class MaintenanceWindowService implements IMaintenanceWindowService {
|
||||
return MaintenanceWindowService.SERVICE_NAME;
|
||||
}
|
||||
|
||||
createMaintenanceWindow = async ({ teamId, body }: { teamId: string; body: any }) => {
|
||||
const monitorIds = body.monitors;
|
||||
const monitors = await this.monitorsRepository.findByIds(monitorIds);
|
||||
createMaintenanceWindow = async ({
|
||||
teamId,
|
||||
monitorIDs,
|
||||
name,
|
||||
active,
|
||||
duration,
|
||||
durationUnit,
|
||||
repeat,
|
||||
start,
|
||||
end,
|
||||
}: {
|
||||
teamId: string;
|
||||
monitorIDs: string[];
|
||||
name: string;
|
||||
active: boolean;
|
||||
duration: number;
|
||||
durationUnit: DurationUnit;
|
||||
repeat: number;
|
||||
start: string;
|
||||
end: string;
|
||||
}) => {
|
||||
const monitors = await this.monitorsRepository.findByIds(monitorIDs);
|
||||
|
||||
const unauthorizedMonitors = monitors.filter((monitor) => monitor.teamId !== teamId);
|
||||
|
||||
@@ -55,17 +84,17 @@ export class MaintenanceWindowService implements IMaintenanceWindowService {
|
||||
});
|
||||
}
|
||||
|
||||
const dbTransactions = monitorIds.map((monitorId: string) => {
|
||||
const dbTransactions = monitorIDs.map((monitorId: string) => {
|
||||
return this.maintenanceWindowsRepository.create({
|
||||
teamId,
|
||||
monitorId,
|
||||
name: body.name,
|
||||
active: body.active ? body.active : true,
|
||||
duration: body.duration,
|
||||
durationUnit: body.durationUnit,
|
||||
repeat: body.repeat,
|
||||
start: body.start,
|
||||
end: body.end,
|
||||
name: name,
|
||||
active: active,
|
||||
duration: duration,
|
||||
durationUnit: durationUnit,
|
||||
repeat: repeat,
|
||||
start: start,
|
||||
end: end,
|
||||
});
|
||||
});
|
||||
await Promise.all(dbTransactions);
|
||||
@@ -106,7 +135,7 @@ export class MaintenanceWindowService implements IMaintenanceWindowService {
|
||||
return await this.maintenanceWindowsRepository.deleteById(id, teamId);
|
||||
};
|
||||
|
||||
editMaintenanceWindow = async ({ id, teamId, body }: { id: string; teamId: string; body: any }) => {
|
||||
editMaintenanceWindow = async ({ id, teamId, body }: { id: string; teamId: string; body: Partial<MaintenanceWindow> }) => {
|
||||
return await this.maintenanceWindowsRepository.updateById(id, teamId, body);
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user