@@ -8,14 +8,15 @@ const path = require('path');
88const { formatString, API_TYPES } = require ( '../../utils.js' ) ;
99const { getExampleByNumber } = require ( '../../manifestService' ) ;
1010const dsConfig = require ( '../../../config/index.js' ) . config ;
11- const { cancelWorkflow } = require ( '../examples/cancelWorkflow' ) ;
11+ const { getWorkflowInstance , cancelWorkflow } = require ( '../examples/cancelWorkflow' ) ;
1212
1313const eg004CancelWorkflow = exports ;
1414const exampleNumber = 4 ;
1515const eg = `mae00${ exampleNumber } ` ; // This example reference.
1616const api = API_TYPES . MAESTRO ;
1717const mustAuthenticate = '/ds/mustAuthenticate' ;
1818const minimumBufferMin = 3 ;
19+ const inProgressWorkflowStatus = 'In Progress' ;
1920
2021/**
2122 * Trigger workflow
@@ -83,6 +84,23 @@ eg004CancelWorkflow.getController = async (req, res) => {
8384 return res . render ( 'pages/error' , { errorCode, errorMessage, errorInfo } ) ;
8485 }
8586
87+ const args = {
88+ workflowId : req . session . workflowId ,
89+ instanceId : req . session . instanceId ,
90+ accessToken : req . user . accessToken ,
91+ basePath : dsConfig . maestroApiUrl ,
92+ accountId : req . session . accountId ,
93+ } ;
94+
95+ const instance = await getWorkflowInstance ( args ) ;
96+
97+ if ( instance . workflowStatus . toLocaleLowerCase ( ) !== inProgressWorkflowStatus . toLocaleLowerCase ( ) ) {
98+ const errorCode = '400' ;
99+ const errorMessage = 'Invalid workflow status' ;
100+ const errorInfo = example . CustomErrorTexts [ 2 ] . ErrorMessage ;
101+ return res . render ( 'pages/error' , { errorCode, errorMessage, errorInfo } ) ;
102+ }
103+
86104 const sourceFile =
87105 path . basename ( __filename ) [ 5 ] . toLowerCase ( ) +
88106 path . basename ( __filename ) . substr ( 6 ) ;
0 commit comments