fix(plugin-workflow): fix appends null to collection trigger (#1661)

This commit is contained in:
Junyi 2023-04-07 15:04:40 +07:00 committed by GitHub
parent cefe678348
commit 3ec8b2d45f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 1 deletions

View File

@ -204,6 +204,35 @@ describe('workflow > triggers > collection', () => {
expect(job.result.data.category.title).toBe('c1');
});
it('appends belongsTo null', async () => {
const workflow = await WorkflowModel.create({
enabled: true,
type: 'collection',
config: {
mode: 1,
collection: 'posts',
appends: ['category']
}
});
await workflow.createNode({
type: 'echo'
});
const post = await PostRepo.create({
values: {
title: 't1',
}
});
await sleep(500);
const [execution] = await workflow.getExecutions();
expect(execution.status).toBe(EXECUTION_STATUS.RESOLVED);
const [job] = await execution.getJobs();
expect(job.result.data.category).toBeNull();
});
it('appends hasMany', async () => {
const workflow = await WorkflowModel.create({
enabled: true,

View File

@ -79,7 +79,7 @@ async function handler(this: CollectionTrigger, workflow: WorkflowModel, data: M
});
includeFields.forEach(field => {
const value = included!.get(field);
data.set(field, Array.isArray(value) ? value.map(item => item.toJSON()) : value.toJSON(), { raw: true });
data.set(field, Array.isArray(value) ? value.map(item => item.toJSON()) : (value ? value.toJSON() : null), { raw: true });
});
}