fix(plugin-workflow): add req context to processor (#936)
This commit is contained in:
parent
26c428a15b
commit
cadaa8a2c2
@ -88,6 +88,7 @@ export type Values = any;
|
||||
|
||||
export interface CountOptions extends Omit<SequelizeCountOptions, 'distinct' | 'where' | 'include'>, Transactionable {
|
||||
filter?: Filter;
|
||||
context?: any;
|
||||
}
|
||||
|
||||
export interface FilterByTk {
|
||||
|
@ -128,7 +128,7 @@ export default class WorkflowPlugin extends Plugin {
|
||||
}
|
||||
}
|
||||
|
||||
async trigger(workflow: WorkflowModel, context: Object, options: Transactionable = {}): Promise<ExecutionModel | null> {
|
||||
async trigger(workflow: WorkflowModel, context: Object, options: Transactionable & { context?: any } = {}): Promise<ExecutionModel | null> {
|
||||
// `null` means not to trigger
|
||||
if (context === null) {
|
||||
return null;
|
||||
@ -186,7 +186,7 @@ export default class WorkflowPlugin extends Plugin {
|
||||
|
||||
execution.workflow = workflow;
|
||||
|
||||
const processor = this.createProcessor(execution, { transaction });
|
||||
const processor = this.createProcessor(execution, { transaction, _context: options.context });
|
||||
|
||||
await processor.start();
|
||||
|
||||
|
@ -13,6 +13,8 @@ import { EXECUTION_STATUS, JOB_STATUS } from './constants';
|
||||
|
||||
|
||||
export interface ProcessorOptions extends Transactionable {
|
||||
// TODO(temp): pass request context here for $isVar and other operators
|
||||
_context?: any;
|
||||
plugin: Plugin
|
||||
}
|
||||
|
||||
@ -33,7 +35,7 @@ export default class Processor {
|
||||
jobsMap = new Map<number, JobModel>();
|
||||
jobsMapByNodeId: { [key: number]: any } = {};
|
||||
|
||||
constructor(public execution: ExecutionModel, private options: ProcessorOptions) {
|
||||
constructor(public execution: ExecutionModel, public options: ProcessorOptions) {
|
||||
}
|
||||
|
||||
// make dual linked nodes list then cache
|
||||
|
@ -12,6 +12,7 @@ export default {
|
||||
const options = processor.getParsedValue(params);
|
||||
const result = await repo.create({
|
||||
...options,
|
||||
context: processor.options._context,
|
||||
transaction: processor.transaction
|
||||
});
|
||||
|
||||
|
@ -12,6 +12,7 @@ export default {
|
||||
const options = processor.getParsedValue(params);
|
||||
const result = await repo.destroy({
|
||||
...options,
|
||||
context: processor.options._context,
|
||||
transaction: processor.transaction
|
||||
});
|
||||
|
||||
|
@ -14,6 +14,7 @@ export default {
|
||||
const options = processor.getParsedValue(params);
|
||||
const result = await (multiple ? repo.find : repo.findOne).call(repo, {
|
||||
...options,
|
||||
context: processor.options._context,
|
||||
transaction: processor.transaction
|
||||
});
|
||||
|
||||
|
@ -14,6 +14,7 @@ export default {
|
||||
const options = processor.getParsedValue(params);
|
||||
const result = await repo.update({
|
||||
...options,
|
||||
context: processor.options._context,
|
||||
transaction: processor.transaction
|
||||
});
|
||||
|
||||
|
@ -39,7 +39,7 @@ async function handler(this: CollectionTrigger, workflow: WorkflowModel, data: M
|
||||
// TODO: change to map filter format to calculation format
|
||||
// const calculation = toCalculation(condition);
|
||||
const { repository, model } = (<typeof Model>data.constructor).database.getCollection(collection);
|
||||
const { transaction } = options;
|
||||
const { transaction, context } = options;
|
||||
const count = await repository.count({
|
||||
filter: {
|
||||
$and: [
|
||||
@ -47,6 +47,7 @@ async function handler(this: CollectionTrigger, workflow: WorkflowModel, data: M
|
||||
{ [model.primaryKeyAttribute]: data[model.primaryKeyAttribute] }
|
||||
]
|
||||
},
|
||||
context,
|
||||
transaction
|
||||
});
|
||||
|
||||
@ -56,6 +57,7 @@ async function handler(this: CollectionTrigger, workflow: WorkflowModel, data: M
|
||||
}
|
||||
|
||||
return this.plugin.trigger(workflow, { data: data.get() }, {
|
||||
context: options.context,
|
||||
transaction: options.transaction
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user