Explorar el Código

minor refactor

thomas hace 3 años
padre
commit
80df0093b5
Se han modificado 2 ficheros con 48 adiciones y 16 borrados
  1. 1 0
      src/components/AdminCommands.vue
  2. 47 16
      src/components/UIClient.vue

+ 1 - 0
src/components/AdminCommands.vue

@@ -32,6 +32,7 @@ export default class AdminCommands extends Vue {
   socket = null
   responses = []
   url = 'http://localhost:3011'
+  // url = 'http://swopt.com:3011'
   cnt = 0
 
   setResponse(data) {

+ 47 - 16
src/components/UIClient.vue

@@ -191,6 +191,7 @@ export default class UiClient extends Vue {
     cancelRequest: null,
   }
   url = 'http://localhost:3011';
+  // url = 'http://swopt.com:3011';
   messages: Message[] = [];
   loading: boolean = false
   modal: boolean = false
@@ -257,7 +258,7 @@ export default class UiClient extends Vue {
       const responseException = results.find( (r: any) => r?.header?.messageType == 'ResponseException' )
 
       if( responseException != null ){
-        throw Error(responseException?.data)
+        throw new Error(responseException?.data)
       }
       // look for response
       const response = results.find( (r: any) => {
@@ -265,7 +266,7 @@ export default class UiClient extends Vue {
         return ['FisResponse','Response'].indexOf(messageType) > -1
       })
       if(response == null){
-        throw Error('fail to get success response')
+        throw new Error('fail to get success response')
       }
 
       // try extract data
@@ -282,20 +283,25 @@ export default class UiClient extends Vue {
   })
 
   async startSession() {
-    this.session.ucpId = await this.getResponse( getLoginMessage(10000), 'signin', (response) => {
-      console.log('response2', response)
-      const ucpId = response?.data?.ucpId
-      if( ucpId == null) throw Error('missing ucpId')
-      console.log('ucpId', ucpId)
-      return ucpId
-    })
+    this.session.ucpId = await this.getResponse(
+      getLoginMessage(10000),
+      'signin',
+      (response) => {
+        const ucpId = response?.data?.ucpId
+        if( ucpId == null) throw new Error('missing ucpId')
+        return ucpId
+      }
+    )
   }
 
   async endSession() {
     this.session.ucpId = await this.getResponse(
       getLogoutMessage(this.session.ucpId),
       'signout',
-      _ => null
+      (data) => {
+        console.log('endSession',JSON.stringify(data?.data,null,3))
+        return null
+      },
     )
   }
 
@@ -303,7 +309,12 @@ export default class UiClient extends Vue {
     this.form.type = await this.getResponse(
       getNewPurchaseRequisition(this.session.ucpId),
       'new product requisition',
-      _ => 'productrequisition',
+      (data) => {
+        if( data?.data != 1 ) {
+          new Error('expected 1 but got ' + JSON.stringify(data?.data) )
+        }
+        return 'productrequisition'
+      },
     )
     this.form.docDt = "2021-01-10Z"
     this.form.cancelRequest = getCancelPurchaseRequisition(this.session.ucpId)
@@ -312,7 +323,12 @@ export default class UiClient extends Vue {
     this.form.type = await this.getResponse(
       getNewUserProfile(this.session.ucpId),
       'new user profile',
-      _ => 'userprofile',
+      (data) => {
+        if( data?.data != 1 ) {
+          throw new Error('expected 1 but got ' + JSON.stringify(data?.data) )
+        }
+        return 'userprofile'
+      },
     )
     this.form.userName = "abcxyz"
     this.form.cancelRequest = getCancelUserProfile(this.session.ucpId)
@@ -321,7 +337,10 @@ export default class UiClient extends Vue {
     this.form.type = await this.getResponse(
       this.form.cancelRequest,
       'cancel changes',
-      _ => null,
+      (data) => {
+        console.log('cancel changes',JSON.stringify(data?.data,null,3))
+        return null
+      },
     )
   }
 
@@ -383,7 +402,7 @@ export default class UiClient extends Vue {
       const results = await this.client.getAllResponsesFromRequest(getLogoutMessage(this.session.ucpId))
       const response = results.find( (r: any) => r?.header?.messageType == 'Response' )
       
-      if(response == null) throw Error('fail to get success response')
+      if(response == null) throw new Error('fail to get success response')
 
       console.log('response',response);
 
@@ -399,7 +418,13 @@ export default class UiClient extends Vue {
     await this.getResponse(
       getSetPurchaseRequisitionDocDt(this.session.ucpId, this.form.docDt),
       'setItem docDt',
-      _ => null,
+      (data) => {
+        if( data?.data?.Result != 1) {
+          throw new Error('expect data.Result = 1 but got ' + JSON.stringify(data?.data))
+        }
+        // console.log('setItemDocDt',JSON.stringify(data?.data,null,3))
+        return null
+      },
     )
   }
 
@@ -407,7 +432,13 @@ export default class UiClient extends Vue {
     await this.getResponse(
       getSetUserProfileUserName(this.session.ucpId, this.form.userName),
       'setItem userName',
-      _ => null,
+      (data) => {
+        if( data?.data?.Result != 1) {
+          throw new Error('expect data.Result = 1 but got ' + JSON.stringify(data?.data))
+        }
+        console.log('setItemUserName',JSON.stringify(data?.data,null,3))
+        return null
+      },
     )
   }