11import axios from 'axios' ;
2- import { store } from '../store/store' ;
2+ import { persistor , store } from '../store/store' ;
33
44const apiUrl = process . env . BACKEND_API ;
55
@@ -22,21 +22,23 @@ export const api = Object.freeze({
2222 jwt : {
2323 // Login by JSON Web Token
2424 login : async ( ) => {
25- const res = await instance . get ( '/auth/jwt/login' ) ;
25+ const response = await instance . get ( '/auth/jwt/login' ) ;
2626 // If user has never logged in before, redirect to consent screen
27- if ( res . status === 210 ) {
28- window . location = res . data ;
27+ if ( response . status === 210 ) {
28+ window . location = response . data ;
2929 return ;
3030 }
3131
32- return res ;
32+ return response ;
3333 } ,
3434 logout : async ( ) => {
3535 await instance . get ( '/auth/jwt/logout' ) ;
36+ await persistor . purge ( ) ;
37+ localStorage . clear ( ) ;
3638 } ,
3739 loginStatus : async ( ) => {
38- const res = await instance . get ( '/auth/jwt/login-status' ) ;
39- return JSON . parse ( res . data ) ; // response boolean
40+ const response = await instance . get ( '/auth/jwt/login-status' ) ;
41+ return JSON . parse ( response . data ) ; // response boolean
4042 } ,
4143 } ,
4244 acg : {
@@ -47,21 +49,23 @@ export const api = Object.freeze({
4749 } ,
4850 logout : async ( ) => {
4951 await instance . get ( '/auth/passport/logout' ) ;
52+ await persistor . purge ( ) ;
53+ localStorage . clear ( ) ;
5054 } ,
5155 callbackExecute : async code => {
52- const res = await instance . get ( `/auth/passport/callback?code=${ code } ` ) ;
53- return res ;
56+ const response = await instance . get ( `/auth/passport/callback?code=${ code } ` ) ;
57+ return response ;
5458 } ,
5559 loginStatus : async ( ) => {
56- const res = await instance . get ( '/auth/passport/login-status' ) ;
57- return JSON . parse ( res . data ) ; // response boolean
60+ const response = await instance . get ( '/auth/passport/login-status' ) ;
61+ return JSON . parse ( response . data ) ; // response boolean
5862 } ,
5963 } ,
6064 workflows : {
6165 createWorkflowDefinition : async templateType => {
6266 try {
63- const res = await instance . post ( '/workflows/create' , { templateType : templateType } ) ;
64- return res ;
67+ const response = await instance . post ( '/workflows/create' , { templateType : templateType } ) ;
68+ return response ;
6569 } catch ( error ) {
6670 if ( error . response && error . response . status === 400 ) {
6771 return error . response ;
@@ -71,21 +75,18 @@ export const api = Object.freeze({
7175 } ,
7276 cancelWorkflowInstance : async workflow => {
7377 try {
74- const res = await instance . put ( `/workflows/${ workflow . definitionId } /instances/${ workflow . dacId } /cancel` ) ;
75- return res ;
78+ const response = await instance . put ( `/workflows/${ workflow . id } /instances/${ workflow . instanceId } /cancel` ) ;
79+ return response ;
7680 } catch ( error ) {
77- if ( error . response && error . response . status === 400 ) {
78- return error . response ;
79- }
80- throw error ;
81+ console . log ( error ) ;
8182 }
8283 } ,
8384 publishWorkflow : async workflowId => {
84- const res = await instance . post ( '/workflows/publish' , { workflowId } ) ;
85+ const response = await instance . post ( '/workflows/publish' , { workflowId } ) ;
8586
86- if ( res . status === 210 ) {
87+ if ( response . status === 210 ) {
8788 try {
88- window . open ( res . data , 'newTab' , 'width=800,height=600' ) ;
89+ window . open ( response . data , 'newTab' , 'width=800,height=600' ) ;
8990 await new Promise ( r => setTimeout ( r , 3000 ) ) ;
9091
9192 const published = await instance . post ( '/workflows/publish' , { workflowId } ) ;
@@ -95,19 +96,27 @@ export const api = Object.freeze({
9596 }
9697 }
9798
98- return res ;
99+ return response ;
100+ } ,
101+ triggerWorkflow : async ( workflowId , body ) => {
102+ try {
103+ const response = await instance . put ( `/workflows/${ workflowId } /trigger` , body ) ;
104+ return response ;
105+ } catch ( error ) {
106+ console . log ( error ) ;
107+ }
99108 } ,
100109 getWorkflowDefinitions : async ( ) => {
101- const res = await instance . get ( `/workflows/definitions` ) ;
102- return res ;
110+ const response = await instance . get ( `/workflows/definitions` ) ;
111+ return response ;
103112 } ,
104113 getWorkflowInstance : async workflow => {
105- const res = await instance . get ( `/workflows/${ workflow . definitionId } /instances/${ workflow . dacId } ` ) ;
106- return res ;
114+ const response = await instance . get ( `/workflows/${ workflow . id } /instances/${ workflow . instanceId } ` ) ;
115+ return response ;
107116 } ,
108- getWorkflowInstances : async definitionId => {
109- const res = await instance . get ( `/workflows/${ definitionId } /instances` ) ;
110- return res ;
117+ getWorkflowInstances : async workflowId => {
118+ const response = await instance . get ( `/workflows/${ workflowId } /instances` ) ;
119+ return response ;
111120 } ,
112121 downloadWorkflowTemplate : async templateName => {
113122 try {
0 commit comments