refactor(plugin-workflow): change to (#3871)
This commit is contained in:
		
							parent
							
								
									4adc116386
								
							
						
					
					
						commit
						6d0d21ede2
					
				| @ -11,7 +11,7 @@ export class CreateInstruction extends Instruction { | ||||
|     const { collection, params: { appends = [], ...params } = {} } = node.config; | ||||
|     const [dataSourceName, collectionName] = parseCollectionName(collection); | ||||
| 
 | ||||
|     const { repository, model } = this.workflow.app.dataSourceManager.dataSources | ||||
|     const { repository, filterTargetKey } = this.workflow.app.dataSourceManager.dataSources | ||||
|       .get(dataSourceName) | ||||
|       .collectionManager.getCollection(collectionName); | ||||
|     const options = processor.getParsedValue(params, node.id); | ||||
| @ -33,7 +33,7 @@ export class CreateInstruction extends Instruction { | ||||
|         return set; | ||||
|       }, new Set()); | ||||
|       result = await repository.findOne({ | ||||
|         filterByTk: created[model.primaryKeyAttribute], | ||||
|         filterByTk: created[filterTargetKey], | ||||
|         appends: Array.from(includeFields), | ||||
|         transaction, | ||||
|       }); | ||||
|  | ||||
| @ -42,7 +42,7 @@ async function handler(this: CollectionTrigger, workflow: WorkflowModel, data: M | ||||
|     .get(dataSourceName) | ||||
|     .collectionManager.getCollection(collectionName); | ||||
|   const { transaction, context } = options; | ||||
|   const { repository, model } = collection; | ||||
|   const { repository, filterTargetKey } = collection; | ||||
| 
 | ||||
|   // NOTE: if no configured fields changed, do not trigger
 | ||||
|   if ( | ||||
| @ -62,7 +62,7 @@ async function handler(this: CollectionTrigger, workflow: WorkflowModel, data: M | ||||
|     // const calculation = toCalculation(condition);
 | ||||
|     const count = await repository.count({ | ||||
|       filter: { | ||||
|         $and: [condition, { [model.primaryKeyAttribute]: data[model.primaryKeyAttribute] }], | ||||
|         $and: [condition, { [filterTargetKey]: data[filterTargetKey] }], | ||||
|       }, | ||||
|       context, | ||||
|       transaction, | ||||
| @ -82,7 +82,7 @@ async function handler(this: CollectionTrigger, workflow: WorkflowModel, data: M | ||||
|       return set; | ||||
|     }, new Set()); | ||||
|     result = await repository.findOne({ | ||||
|       filterByTk: data[model.primaryKeyAttribute], | ||||
|       filterByTk: data[filterTargetKey], | ||||
|       appends: Array.from(includeFields), | ||||
|       transaction, | ||||
|     }); | ||||
|  | ||||
| @ -283,8 +283,11 @@ export default class ScheduleTrigger { | ||||
|   } | ||||
| 
 | ||||
|   schedule(workflow: WorkflowModel, record, nextTime, toggle = true, options = {}) { | ||||
|     const { model } = this.workflow.app.db.getCollection(workflow.config.collection); | ||||
|     const recordPk = record.get(model.primaryKeyAttribute); | ||||
|     const [dataSourceName, collectionName] = parseCollectionName(workflow.config.collection); | ||||
|     const { filterTargetKey } = this.workflow.app.dataSourceManager.dataSources | ||||
|       .get(dataSourceName) | ||||
|       .collectionManager.getCollection(collectionName); | ||||
|     const recordPk = record.get(filterTargetKey); | ||||
|     if (toggle) { | ||||
|       const nextInterval = Math.max(0, nextTime - Date.now()); | ||||
|       const key = `${workflow.id}:${recordPk}@${nextTime}`; | ||||
| @ -307,8 +310,11 @@ export default class ScheduleTrigger { | ||||
|   } | ||||
| 
 | ||||
|   async trigger(workflow: WorkflowModel, record, nextTime, { transaction }: Transactionable = {}) { | ||||
|     const { repository, model } = this.workflow.app.db.getCollection(workflow.config.collection); | ||||
|     const recordPk = record.get(model.primaryKeyAttribute); | ||||
|     const [dataSourceName, collectionName] = parseCollectionName(workflow.config.collection); | ||||
|     const { repository, filterTargetKey } = this.workflow.app.dataSourceManager.dataSources | ||||
|       .get(dataSourceName) | ||||
|       .collectionManager.getCollection(collectionName); | ||||
|     const recordPk = record.get(filterTargetKey); | ||||
|     const data = await repository.findOne({ | ||||
|       filterByTk: recordPk, | ||||
|       appends: workflow.config.appends, | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user