implement remaining methods
This commit is contained in:
1 parent
9962866ba5
commit
8bd608bee0
3 files changed
+39
-6
No files matched your search
@@ -4,11 +4,13 @@ export interface IMaintenanceWindowsRepository {
|
|||||||
create(data: Partial<MaintenanceWindow>): Promise<MaintenanceWindow>;
|
create(data: Partial<MaintenanceWindow>): Promise<MaintenanceWindow>;
|
||||||
// fetch
|
// fetch
|
||||||
findById(id: string, teamId: string): Promise<MaintenanceWindow>;
|
findById(id: string, teamId: string): Promise<MaintenanceWindow>;
|
||||||
|
findByMonitorId(monitorId: string, teamId: string): Promise<MaintenanceWindow[]>;
|
||||||
findByTeamId(teamId: string, active: boolean, page: number, rowsPerPage: number, field: string, order: string): Promise<MaintenanceWindow[]>;
|
findByTeamId(teamId: string, active: boolean, page: number, rowsPerPage: number, field: string, order: string): Promise<MaintenanceWindow[]>;
|
||||||
|
|
||||||
// update
|
// update
|
||||||
|
updateById(id: string, teamId: string, data: Partial<MaintenanceWindow>): Promise<MaintenanceWindow>;
|
||||||
// delete
|
// delete
|
||||||
|
deleteById(id: string, teamId: string): Promise<MaintenanceWindow>;
|
||||||
// other
|
// other
|
||||||
countByTeamId(teamId: string, active: boolean): Promise<number>;
|
countByTeamId(teamId: string, active: boolean): Promise<number>;
|
||||||
}
|
}
|
||||||
@@ -63,6 +63,14 @@ class MongoMaintenanceWindowsRepository implements IMaintenanceWindowsRepository
|
|||||||
return this.toEntity(maintenanceWindow);
|
return this.toEntity(maintenanceWindow);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
findByMonitorId = async (monitorId: string, teamId: string): Promise<MaintenanceWindow[]> => {
|
||||||
|
const maintenanceWindows = await MaintenanceWindowModel.find({
|
||||||
|
monitorId: monitorId,
|
||||||
|
teamId: teamId,
|
||||||
|
});
|
||||||
|
return this.mapDocuments(maintenanceWindows);
|
||||||
|
};
|
||||||
|
|
||||||
findByTeamId = async (
|
findByTeamId = async (
|
||||||
teamId: string,
|
teamId: string,
|
||||||
active: boolean,
|
active: boolean,
|
||||||
@@ -91,6 +99,31 @@ class MongoMaintenanceWindowsRepository implements IMaintenanceWindowsRepository
|
|||||||
return this.mapDocuments(maintenanceWindows);
|
return this.mapDocuments(maintenanceWindows);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
updateById = async (id: string, teamId: string, data: Partial<MaintenanceWindow>): Promise<MaintenanceWindow> => {
|
||||||
|
const updated = await MaintenanceWindowModel.findOneAndUpdate(
|
||||||
|
{
|
||||||
|
_id: new mongoose.Types.ObjectId(id),
|
||||||
|
teamId: new mongoose.Types.ObjectId(teamId),
|
||||||
|
},
|
||||||
|
{ $set: data },
|
||||||
|
{ new: true, runValidators: true }
|
||||||
|
);
|
||||||
|
if (!updated) {
|
||||||
|
throw new AppError({ message: "Maintenance window not found or could not be updated", status: 404 });
|
||||||
|
}
|
||||||
|
return this.toEntity(updated);
|
||||||
|
};
|
||||||
|
|
||||||
|
deleteById = async (id: string, teamId: string): Promise<MaintenanceWindow> => {
|
||||||
|
const deleted = await MaintenanceWindowModel.findOneAndDelete({
|
||||||
|
_id: new mongoose.Types.ObjectId(id),
|
||||||
|
teamId: new mongoose.Types.ObjectId(teamId),
|
||||||
|
});
|
||||||
|
if (!deleted) {
|
||||||
|
throw new AppError({ message: "Maintenance window not found or could not be deleted", status: 404 });
|
||||||
|
}
|
||||||
|
return this.toEntity(deleted);
|
||||||
|
};
|
||||||
countByTeamId = async (teamId: string, active: boolean) => {
|
countByTeamId = async (teamId: string, active: boolean) => {
|
||||||
const maintenanceQuery: Record<string, any> = { teamId };
|
const maintenanceQuery: Record<string, any> = { teamId };
|
||||||
|
|
||||||
|
|||||||
@@ -68,17 +68,15 @@ class MaintenanceWindowService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
getMaintenanceWindowsByMonitorId = async ({ monitorId, teamId }: { monitorId: string; teamId: string }) => {
|
getMaintenanceWindowsByMonitorId = async ({ monitorId, teamId }: { monitorId: string; teamId: string }) => {
|
||||||
const maintenanceWindows = await this.db.maintenanceWindowModule.getMaintenanceWindowsByMonitorId({ monitorId, teamId });
|
return await this.maintenanceWindowsRepository.findByMonitorId(monitorId, teamId);
|
||||||
return maintenanceWindows;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
deleteMaintenanceWindow = async ({ id, teamId }: { id: string; teamId: string }) => {
|
deleteMaintenanceWindow = async ({ id, teamId }: { id: string; teamId: string }) => {
|
||||||
await this.db.maintenanceWindowModule.deleteMaintenanceWindowById({ id, teamId });
|
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: any }) => {
|
||||||
const editedMaintenanceWindow = await this.db.maintenanceWindowModule.editMaintenanceWindowById({ id, body, teamId });
|
return await this.maintenanceWindowsRepository.updateById(id, teamId, body);
|
||||||
return editedMaintenanceWindow;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user