deleteById

This commit is contained in:
Alex Holliday committed 2026-01-15 18:24:58 +00:00
1 parent 6b5fd8d17f
commit 75bcf9df58
3 files changed
+17 -6

No files matched your search

@@ -29,6 +29,7 @@ export interface IMonitorsRepository {
updateById(monitorId: string, updates: Partial<Monitor>): Promise<Monitor>;
togglePauseById(monitorId: string, teamId: string): Promise<Monitor>;
// delete
deleteById(monitorId: string, teamId: string): Promise<Monitor>;
deleteByTeamId(teamId: string): Promise<{ monitors: Monitor[]; deletedCount: number }>;
// counts
@@ -131,6 +131,16 @@ class MongoMonitorsRepository implements IMonitorsRepository {
return this.toEntity(monitor);
};
deleteById = async (monitorId: string, teamId: string) => {
const deletedMonitor = await MonitorModel.findOneAndDelete({ _id: monitorId, teamId });
if (!deletedMonitor) {
throw new AppError({ message: `Monitor with ID ${monitorId} not found for the given team.`, status: 404 });
}
return this.toEntity(deletedMonitor);
};
deleteByTeamId = async (teamId: string) => {
const monitors = await MonitorModel.find({ teamId });
const { deletedCount } = await MonitorModel.deleteMany({ teamId });