tachybase_todo/packages/plugins/workflow/src/server/instructions/create.ts
Junyi 9f8460ca22
feat(plugin-workflow): change to unlimited depth preloading associations in workflow (#2142)
* refactor(plugin-snapshot): move AppendsTreeSelect component into client package

* refactor(plugin-workflow): change all appends fields select to AppendsTreeSelect

* refactor(plugin-workflow): change appends and toJSON logic on server side

* fix(plugin-workflow): fix toJSON logic and build error

* fix(plugin-workflow): fix missing component injection

* fix(plugin-workflow): fix cycle association in variables

* refactor(client): change AppendsTreeSelect to lazy load

* fix(client): fix lazy load in option
2023-07-17 20:36:17 -07:00

40 lines
1.2 KiB
TypeScript

import { JOB_STATUS } from '../constants';
import { toJSON } from '../utils';
import type { FlowNodeModel } from '../types';
export default {
async run(node: FlowNodeModel, input, processor) {
const { collection, params: { appends = [], ...params } = {} } = node.config;
const { repository, model } = (<typeof FlowNodeModel>node.constructor).database.getCollection(collection);
const options = processor.getParsedValue(params, node);
const created = await repository.create({
...options,
context: {
executionId: processor.execution.id,
},
transaction: processor.transaction,
});
let result = created;
if (created && appends.length) {
const includeFields = appends.reduce((set, field) => {
set.add(field.split('.')[0]);
set.add(field);
return set;
}, new Set());
result = await repository.findOne({
filterByTk: created[model.primaryKeyAttribute],
appends: Array.from(includeFields),
transaction: processor.transaction,
});
}
return {
// NOTE: get() for non-proxied instance (#380)
result: toJSON(result),
status: JOB_STATUS.RESOLVED,
};
},
};