Junyi ecf82208eb
refactor(plugin-workflow): abstract to classes (#515)
* refactor(plugin-workflow): abstract to classes

* fix(plugin-workflow): add indexes and fix cases

* test(plugin-workflow): skip schedule cases
2022-06-20 23:29:21 +08:00

29 lines
964 B
TypeScript

import FlowNodeModel from "../models/FlowNode";
import Processor from "../Processor";
import { JOB_STATUS } from "../constants";
export default {
async run(this: FlowNodeModel, input, processor: Processor) {
const {
collection,
multiple,
params = {}
} = this.config;
const repo = (<typeof FlowNodeModel>this.constructor).database.getRepository(collection);
const options = processor.getParsedValue(params);
const result = await (multiple ? repo.find : repo.findOne).call(repo, {
...options,
transaction: processor.transaction
});
// NOTE: `toJSON()` to avoid getting undefined value from Proxied model instance (#380)
// e.g. Object.prototype.hasOwnProperty.call(result, 'id') // false
// so the properties can not be get by json-templates(object-path)
return {
result: multiple ? result.map(item => item.toJSON()) : result?.toJSON(),
status: JOB_STATUS.RESOLVED
};
}
};