From c0b0417b6d7868c3cb421dbab8cd899034f53fe1 Mon Sep 17 00:00:00 2001 From: Josep Piguillem Date: Mon, 19 Oct 2026 19:53:56 +0200 Subject: [PATCH] fix(api): automations without conditions list and run again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Mongo leaves empty objects out, so a rule saved with no conditions came back without them: the automations list failed («Cannot return null for non-nullable field Automation.conditions») and the rules engine threw on it, so those rules never ran. The repository now gives them an empty object, as the views of «my work» already did. Co-Authored-By: Claude Opus 5.5 --- .../src/lib/mongo/automations.repository.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/libs/api/tracker/infrastructure/src/lib/mongo/automations.repository.ts b/libs/api/tracker/infrastructure/src/lib/mongo/automations.repository.ts index 56f1a9c..f97af80 100644 --- a/libs/api/tracker/infrastructure/src/lib/mongo/automations.repository.ts +++ b/libs/api/tracker/infrastructure/src/lib/mongo/automations.repository.ts @@ -30,21 +30,21 @@ export class MongoAutomationsRepository extends AutomationsRepository { .find({ projectId }) .sort({ createdAt: 1 }) .lean(); - return docs.map((doc) => fromDoc(doc) as Automation); + return docs.map(toAutomation); } async findActive(projectId: string): Promise { const docs = await this.automations .find({ projectId, active: true }) .lean(); - return docs.map((doc) => fromDoc(doc) as Automation); + return docs.map(toAutomation); } async findById(id: string): Promise { const doc = await this.automations .findOne({ id: id }) .lean(); - return doc ? (fromDoc(doc) as Automation) : null; + return doc ? toAutomation(doc) : null; } async insert({ id, ...rest }: Automation): Promise { @@ -83,3 +83,13 @@ export class MongoAutomationsRepository extends AutomationsRepository { ); } } + +/** + * Mongo leaves empty objects out (`minimize`): a rule saved with no + * conditions comes back without them, and both GraphQL and the rules + * engine need the object. + */ +function toAutomation(doc: AutomationDoc): Automation { + const automation = fromDoc(doc) as Automation; + return { ...automation, conditions: automation.conditions ?? {} }; +}