From e1f7e94e0da72a261ad568894e47d7108aae0f0c Mon Sep 17 00:00:00 2001 From: Junyi Date: Sat, 15 Mar 2025 22:27:31 +0800 Subject: [PATCH] fix(plugin-workflow-aggregate): fix round on null result (#6473) --- .../src/server/AggregateInstruction.ts | 2 +- .../src/server/__tests__/instruction.test.ts | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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',