Add additional external hooks and provide additional data

This commit is contained in:
Jan Oberhauser
2020-05-05 01:23:54 +02:00
parent a380a9a394
commit 0387671cae
5 changed files with 79 additions and 37 deletions

View File

@@ -1,10 +1,46 @@
import {
IExternalHookFunctions,
IWorkflowBase,
} from '../';
// TODO: Move that to interfaces
interface IExternalHooks {
credentials?: {
create?: Array<{ (this: IExternalHookFunctions): Promise<void>; }>
delete?: Array<{ (this: IExternalHookFunctions, credentialId: string): Promise<void>; }>
update?: Array<{ (this: IExternalHookFunctions, credentialId: string): Promise<void>; }>
};
workflow?: {
create?: Array<{ (this: IExternalHookFunctions, workflowData: IWorkflowBase): Promise<void>; }>
delete?: Array<{ (this: IExternalHookFunctions, workflowId: string): Promise<void>; }>
update?: Array<{ (this: IExternalHookFunctions, workflowData: IWorkflowBase): Promise<void>; }>
};
}
export = {
credentials: {
new: [
() => {
create: [
async function (this: IExternalHookFunctions) {
// console.log(this.DbCollections.Workflow);
// Here any additional code can run or the creation blocked
throw new Error('No additional credentials can be created.');
},
],
},
};
workflow: {
update: [
async function (this: IExternalHookFunctions, workflowData: IWorkflowBase) {
console.log('update workflow hook');
// const responseData = await this.DbCollections.Workflow!.findOne(workflowData.id);
// console.log('workflowData');
// console.log(responseData);
// console.log(workflowData);
// Here any additional code can run or the creation blocked
throw new Error('Workflow can not be updated.');
},
],
},
} as IExternalHooks;