diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/AggregateInstruction.ts b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/AggregateInstruction.ts index 66423ce090..7517611809 100644 --- a/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/AggregateInstruction.ts +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/AggregateInstruction.ts @@ -49,7 +49,7 @@ export default class extends Instruction { }); return { - result: round(options.dataType === DataTypes.DOUBLE ? Number(result) : result, 14), + result: round((options.dataType === DataTypes.DOUBLE ? Number(result) : result) || 0, 14), status: JOB_STATUS.RESOLVED, }; } diff --git a/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/__tests__/instruction.test.ts b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/__tests__/instruction.test.ts index b5cd69a8d6..4a3102cd1d 100644 --- a/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/__tests__/instruction.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow-aggregate/src/server/__tests__/instruction.test.ts @@ -180,6 +180,27 @@ describe('workflow > instructions > aggregate', () => { expect(j2.result).toBe(0.3); }); + it('sum null will be 0', async () => { + const n1 = await workflow.createNode({ + type: 'aggregate', + config: { + aggregator: 'sum', + collection: 'posts', + params: { + field: 'read', + }, + }, + }); + + const p2 = await PostRepo.create({ values: { title: 't2' } }); + + await sleep(500); + + const [e1] = await workflow.getExecutions(); + const [j1] = await e1.getJobs(); + expect(j1.result).toBe(0); + }); + it('avg', async () => { const n1 = await workflow.createNode({ type: 'aggregate',