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,22 +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 ( ) ;
3637 localStorage . clear ( ) ;
3738 } ,
3839 loginStatus : async ( ) => {
39- const res = await instance . get ( '/auth/jwt/login-status' ) ;
40- 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
4142 } ,
4243 } ,
4344 acg : {
@@ -48,23 +49,23 @@ export const api = Object.freeze({
4849 } ,
4950 logout : async ( ) => {
5051 await instance . get ( '/auth/passport/logout' ) ;
52+ await persistor . purge ( ) ;
5153 localStorage . clear ( ) ;
5254 } ,
5355 callbackExecute : async code => {
54- const res = await instance . get ( `/auth/passport/callback?code=${ code } ` ) ;
55- return res ;
56+ const response = await instance . get ( `/auth/passport/callback?code=${ code } ` ) ;
57+ return response ;
5658 } ,
5759 loginStatus : async ( ) => {
58- const res = await instance . get ( '/auth/passport/login-status' ) ;
59- 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
6062 } ,
6163 } ,
6264 workflows : {
63- // YES
6465 createWorkflowDefinition : async templateType => {
6566 try {
66- const res = await instance . post ( '/workflows/create' , { templateType : templateType } ) ;
67- return res ;
67+ const response = await instance . post ( '/workflows/create' , { templateType : templateType } ) ;
68+ return response ;
6869 } catch ( error ) {
6970 if ( error . response && error . response . status === 400 ) {
7071 return error . response ;
@@ -74,22 +75,18 @@ export const api = Object.freeze({
7475 } ,
7576 cancelWorkflowInstance : async workflow => {
7677 try {
77- const res = await instance . put ( `/workflows/${ workflow . definitionId } /instances/${ workflow . dacId } /cancel` ) ;
78- return res ;
78+ const response = await instance . put ( `/workflows/${ workflow . id } /instances/${ workflow . instanceId } /cancel` ) ;
79+ return response ;
7980 } catch ( error ) {
80- if ( error . response && error . response . status === 400 ) {
81- return error . response ;
82- }
83- throw error ;
81+ console . log ( error ) ;
8482 }
8583 } ,
86- // YES
8784 publishWorkflow : async workflowId => {
88- const res = await instance . post ( '/workflows/publish' , { workflowId } ) ;
85+ const response = await instance . post ( '/workflows/publish' , { workflowId } ) ;
8986
90- if ( res . status === 210 ) {
87+ if ( response . status === 210 ) {
9188 try {
92- window . open ( res . data , 'newTab' , 'width=800,height=600' ) ;
89+ window . open ( response . data , 'newTab' , 'width=800,height=600' ) ;
9390 await new Promise ( r => setTimeout ( r , 3000 ) ) ;
9491
9592 const published = await instance . post ( '/workflows/publish' , { workflowId } ) ;
@@ -99,32 +96,28 @@ export const api = Object.freeze({
9996 }
10097 }
10198
102- return res ;
99+ return response ;
103100 } ,
104- // YES
105101 triggerWorkflow : async ( workflowId , body ) => {
106102 try {
107- const res = await instance . put ( `/workflows/${ workflowId } /trigger` , body ) ;
108- return res ;
103+ const response = await instance . put ( `/workflows/${ workflowId } /trigger` , body ) ;
104+ return response ;
109105 } catch ( error ) {
110106 console . log ( error ) ;
111107 }
112108 } ,
113- // YES
114109 getWorkflowDefinitions : async ( ) => {
115- const res = await instance . get ( `/workflows/definitions` ) ;
116- return res ;
110+ const response = await instance . get ( `/workflows/definitions` ) ;
111+ return response ;
117112 } ,
118113 getWorkflowInstance : async workflow => {
119- const res = await instance . get ( `/workflows/${ workflow . definitionId } /instances/${ workflow . dacId } ` ) ;
120- return res ;
114+ const response = await instance . get ( `/workflows/${ workflow . id } /instances/${ workflow . instanceId } ` ) ;
115+ return response ;
121116 } ,
122- // YES
123- getWorkflowInstances : async definitionId => {
124- const res = await instance . get ( `/workflows/${ definitionId } /instances` ) ;
125- return res ;
117+ getWorkflowInstances : async workflowId => {
118+ const response = await instance . get ( `/workflows/${ workflowId } /instances` ) ;
119+ return response ;
126120 } ,
127- // YES
128121 downloadWorkflowTemplate : async templateName => {
129122 try {
130123 const response = await fetch ( `/workflows/download/${ templateName } ` ) ;
0 commit comments