From 67806c94b15290d4add6922f65db6a80624b8bb9 Mon Sep 17 00:00:00 2001 From: egeoztass Date: Mon, 7 Sep 2026 12:31:07 +0200 Subject: [PATCH] fix: return the created monitor from createMonitor The controller writes the service's return value into the response, but createMonitor was typed Promise and returned nothing, so every successful POST /monitors answered data: null and callers had no way to read the new monitor's id. Fixes #3917 Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01D7eViZ2Np5ZpWUYNoRhmAt --- server/src/domain/monitors/monitor.service.ts | 5 +++-- server/test/unit/services/monitorService.test.ts | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/server/src/domain/monitors/monitor.service.ts b/server/src/domain/monitors/monitor.service.ts index 43cba16d8..9e4f7f6e5 100644 --- a/server/src/domain/monitors/monitor.service.ts +++ b/server/src/domain/monitors/monitor.service.ts @@ -60,7 +60,7 @@ const computeRestartsInRange = (aggregate: DockerContainerStatsBucket[]): number export interface IMonitorService { // create - createMonitor(teamId: string, userId: string, body: Partial): Promise; + createMonitor(teamId: string, userId: string, body: Partial): Promise; createMonitors(monitors: Array): Promise; addDemoMonitors(args: { userId: string; teamId: string }): Promise; @@ -180,7 +180,7 @@ export class MonitorService implements IMonitorService { this.incidentsRepository = incidentsRepository; } - createMonitor = async (teamId: string, userId: string, body: Monitor): Promise => { + createMonitor = async (teamId: string, userId: string, body: Monitor): Promise => { // proxyId is only needed in custom mode if (body.proxyMode !== "custom") { delete body.proxyId; @@ -191,6 +191,7 @@ export class MonitorService implements IMonitorService { } this.scheduler.addJob(monitor.id, monitor); + return monitor; }; createMonitors = async (monitors: Array): Promise => { diff --git a/server/test/unit/services/monitorService.test.ts b/server/test/unit/services/monitorService.test.ts index 1bb4b3423..d3f5dd1a7 100644 --- a/server/test/unit/services/monitorService.test.ts +++ b/server/test/unit/services/monitorService.test.ts @@ -122,16 +122,17 @@ const createService = ( describe("MonitorService", () => { describe("createMonitor", () => { - it("creates a monitor and adds a job", async () => { + it("creates a monitor, adds a job and returns the created document", async () => { const monitorsRepository = createMonitorsRepositoryMock(); const monitor = makeMonitor(); (monitorsRepository.create as jest.Mock).mockResolvedValue(monitor); const { service, jobQueue } = createService({ monitorsRepository }); - await service.createMonitor(TEAM_ID, USER_ID, monitor as any); + const result = await service.createMonitor(TEAM_ID, USER_ID, monitor as any); expect(monitorsRepository.create).toHaveBeenCalledWith(monitor, TEAM_ID, USER_ID); expect(jobQueue.addJob).toHaveBeenCalledWith(MONITOR_ID, monitor); + expect(result).toBe(monitor); }); it("strips a stray proxyId when proxyMode is not custom", async () => {