fix(api): automations without conditions list and run again
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 <noreply@anthropic.com>
This commit is contained in:
@@ -30,21 +30,21 @@ export class MongoAutomationsRepository extends AutomationsRepository {
|
||||
.find({ projectId })
|
||||
.sort({ createdAt: 1 })
|
||||
.lean<AutomationDoc[]>();
|
||||
return docs.map((doc) => fromDoc(doc) as Automation);
|
||||
return docs.map(toAutomation);
|
||||
}
|
||||
|
||||
async findActive(projectId: string): Promise<Automation[]> {
|
||||
const docs = await this.automations
|
||||
.find({ projectId, active: true })
|
||||
.lean<AutomationDoc[]>();
|
||||
return docs.map((doc) => fromDoc(doc) as Automation);
|
||||
return docs.map(toAutomation);
|
||||
}
|
||||
|
||||
async findById(id: string): Promise<Automation | null> {
|
||||
const doc = await this.automations
|
||||
.findOne({ id: id })
|
||||
.lean<AutomationDoc>();
|
||||
return doc ? (fromDoc(doc) as Automation) : null;
|
||||
return doc ? toAutomation(doc) : null;
|
||||
}
|
||||
|
||||
async insert({ id, ...rest }: Automation): Promise<void> {
|
||||
@@ -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 ?? {} };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user