238af440e3
* feat(plugin-workflow): add loop instruction * fix(plugin-workflow): fix lint error * feat(plugin-workflow): add loop variable in client * feat(plugin-workflow): refactor and add job list to nodes in execution * feat(plugin-workflow): allow to query multiple records * fix(plugin-workflow): fix i18n * fix(plugin-workflow): fix undefined value in component * fix(plugin-workflow): fix parse context value with current node * fix(plugin-workflow): fix revision with scope variable * test(plugin-workflow): add failing case * fix(plugin-workflow): fix revision with scope variable * chore(plugin-workflow): fix lint errors * fix(plugin-workflow): fix workflow canvas page style * fix(plugin-workflow): revert abstracted node config drawer back to each node * fix(plugin-workflow): fix parallel extra call * fix(plugin-workflow): fix parallel branch end * fix(plugin-workflow): fix jobs variable in processor * fix(plugin-workflow): fix workflow canvas scroll style * fix(plugin-workflow): fix slowly opening job modal * fix(plugin-workflow): fix cycling reference
38 lines
1.3 KiB
TypeScript
38 lines
1.3 KiB
TypeScript
import { JOB_STATUS } from '../constants';
|
|
import FlowNodeModel from '../models/FlowNode';
|
|
|
|
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 result = await repository.create({
|
|
...options,
|
|
context: {
|
|
executionId: processor.execution.id,
|
|
},
|
|
transaction: processor.transaction,
|
|
});
|
|
|
|
if (result && appends.length) {
|
|
const includeFields = appends.filter((field) => !result.get(field) || !result[field]);
|
|
const included = await model.findByPk(result[model.primaryKeyAttribute], {
|
|
attributes: [model.primaryKeyAttribute],
|
|
include: includeFields,
|
|
transaction: processor.transaction,
|
|
});
|
|
includeFields.forEach((field) => {
|
|
const value = included!.get(field);
|
|
result.set(field, Array.isArray(value) ? value.map((item) => item.toJSON()) : value.toJSON(), { raw: true });
|
|
});
|
|
}
|
|
|
|
return {
|
|
// NOTE: get() for non-proxied instance (#380)
|
|
result: result?.toJSON(),
|
|
status: JOB_STATUS.RESOLVED,
|
|
};
|
|
},
|
|
};
|