From 70e691fe5703eb9c2b268678139e002c52f64913 Mon Sep 17 00:00:00 2001 From: Math Paquette Date: Sat, 29 Apr 2023 06:33:44 -0400 Subject: [PATCH] fix(api): automatically complete run when no tasks closes #70 --- apps/api/src/runs/run.entity.ts | 4 ++++ apps/api/src/runs/runs.service.ts | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/api/src/runs/run.entity.ts b/apps/api/src/runs/run.entity.ts index 6e9e4ca..8904060 100644 --- a/apps/api/src/runs/run.entity.ts +++ b/apps/api/src/runs/run.entity.ts @@ -101,6 +101,10 @@ export class RunEntity implements Run { throw new Error(`Run has been already closed!`); } + if (this.tasks.length === 0) { + this.complete(); + } + this.closed = true; } } diff --git a/apps/api/src/runs/runs.service.ts b/apps/api/src/runs/runs.service.ts index 308a26a..847945e 100644 --- a/apps/api/src/runs/runs.service.ts +++ b/apps/api/src/runs/runs.service.ts @@ -54,7 +54,10 @@ export class RunsService { } async close(id: number): Promise { - const run = await this.runsRepository.findOneBy({ id: id }); + const run = await this.runsRepository.findOne({ + where: { id: id }, + relations: { tasks: true }, + }); run.close(); return this.runsRepository.save(run); }