import PostgresDatabase from '../Infrastructure/PostgresDatabase'; import Model from 'Model/Models/Workflow'; import DatabaseService, { OnUpdate } from './DatabaseService'; import ObjectID from 'Common/Types/ObjectID'; import { JSONObject } from 'Common/Types/JSON'; import { ComponentType, NodeDataProp, NodeType, } from 'Common/Types/Workflow/Component'; import API from 'Common/Utils/API'; import EmptyResponseData from 'Common/Types/API/EmptyResponse'; import URL from 'Common/Types/API/URL'; import Protocol from 'Common/Types/API/Protocol'; import { WorkflowHostname } from '../EnvironmentConfig'; import Route from 'Common/Types/API/Route'; import ClusterKeyAuthorization from '../Middleware/ClusterKeyAuthorization'; export class Service extends DatabaseService { public constructor(postgresDatabase?: PostgresDatabase) { super(Model, postgresDatabase); } protected override async onUpdateSuccess( onUpdate: OnUpdate, _updatedItemIds: ObjectID[] ): Promise> { /// save trigger and trigger args. if ( onUpdate.updateBy.data && (onUpdate.updateBy.data as any).graph && (((onUpdate.updateBy.data as any).graph as any)[ 'nodes' ] as Array) ) { let trigger: NodeDataProp | null = null; // check if it has a trigger node. for (const node of ((onUpdate.updateBy.data as any).graph as any)[ 'nodes' ] as Array) { const nodeData: NodeDataProp = node['data'] as any; if ( nodeData.componentType === ComponentType.Trigger && nodeData.nodeType === NodeType.Node ) { // found the trigger; trigger = nodeData; } } await this.updateOneById({ id: new ObjectID(onUpdate.updateBy.query._id! as any), data: { triggerId: trigger?.metadataId! || null, triggerArguments: trigger?.arguments || {}, } as any, props: { isRoot: true, ignoreHooks: true, }, }); } await API.post( new URL( Protocol.HTTP, WorkflowHostname, new Route('/workflow/update/' + onUpdate.updateBy.query._id!) ), {}, { ...ClusterKeyAuthorization.getClusterKeyHeaders(), } ); return onUpdate; } } export default new Service();