diff --git a/src/stores/branch-contact/index.ts b/src/stores/branch-contact/index.ts index 9355442a..fa28e700 100644 --- a/src/stores/branch-contact/index.ts +++ b/src/stores/branch-contact/index.ts @@ -4,10 +4,12 @@ import { defineStore } from 'pinia'; import { BranchContact, BranchContactCreate } from './types'; import { Pagination } from '../types'; import { api } from 'src/boot/axios'; +import useFlowStore from '../flow'; type BranchContactId = string; const useBranchContactStore = defineStore('api-branch-contact', () => { + const flowStore = useFlowStore(); const data = ref>({ result: [], page: 0, @@ -48,7 +50,7 @@ const useBranchContactStore = defineStore('api-branch-contact', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -75,7 +77,7 @@ const useBranchContactStore = defineStore('api-branch-contact', () => { >(`/branch/${branchId}/contact`, data, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -104,7 +106,7 @@ const useBranchContactStore = defineStore('api-branch-contact', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -138,7 +140,7 @@ const useBranchContactStore = defineStore('api-branch-contact', () => { >(`/branch/${branchId}/contact/${contactId}`, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); diff --git a/src/stores/branch/index.ts b/src/stores/branch/index.ts index a449d182..8c9b03c2 100644 --- a/src/stores/branch/index.ts +++ b/src/stores/branch/index.ts @@ -5,10 +5,12 @@ import { api } from 'src/boot/axios'; import { Branch, BranchCreate } from './types'; import { BranchContact } from '../branch-contact/types'; import axios from 'axios'; +import useFlowStore from '../flow'; type BranchId = string; const useBranchStore = defineStore('api-branch', () => { + const flowStore = useFlowStore(); const data = ref>({ result: [], page: 0, @@ -60,7 +62,7 @@ const useBranchStore = defineStore('api-branch', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -104,7 +106,7 @@ const useBranchStore = defineStore('api-branch', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -135,7 +137,7 @@ const useBranchStore = defineStore('api-branch', () => { >('/branch', payload, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -179,7 +181,7 @@ const useBranchStore = defineStore('api-branch', () => { >(`/branch/${id}`, payload, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -218,7 +220,7 @@ const useBranchStore = defineStore('api-branch', () => { const res = await api.delete(`/branch/${id}`, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -240,7 +242,7 @@ const useBranchStore = defineStore('api-branch', () => { const res = await api.get(`/branch/${branchId}/user`, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -266,7 +268,7 @@ const useBranchStore = defineStore('api-branch', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -290,7 +292,7 @@ const useBranchStore = defineStore('api-branch', () => { const res = await api.delete(`/branch/${branchId}/user`, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, data: { user: ([] as string[]).concat(userId) }, @@ -313,7 +315,7 @@ const useBranchStore = defineStore('api-branch', () => { }>('/branch/stats', { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -337,7 +339,7 @@ const useBranchStore = defineStore('api-branch', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, diff --git a/src/stores/customer/index.ts b/src/stores/customer/index.ts index 47d0d0e7..353cfbeb 100644 --- a/src/stores/customer/index.ts +++ b/src/stores/customer/index.ts @@ -14,8 +14,10 @@ import { CustomerType, } from './types'; import axios from 'axios'; +import useFlowStore from '../flow'; const useCustomerStore = defineStore('api-customer', () => { + const flowStore = useFlowStore(); const data = ref>(); async function fetchListById( @@ -31,7 +33,7 @@ const useCustomerStore = defineStore('api-customer', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -81,7 +83,7 @@ const useCustomerStore = defineStore('api-customer', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -131,7 +133,7 @@ const useCustomerStore = defineStore('api-customer', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -153,7 +155,7 @@ const useCustomerStore = defineStore('api-customer', () => { const res = await api.get('/customer/type-stats', { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -188,7 +190,7 @@ const useCustomerStore = defineStore('api-customer', () => { >('/customer', payload, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -240,7 +242,7 @@ const useCustomerStore = defineStore('api-customer', () => { >(`/customer/${id}`, payload, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -276,7 +278,7 @@ const useCustomerStore = defineStore('api-customer', () => { const res = await api.delete(`/customer/${id}`, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -304,7 +306,7 @@ const useCustomerStore = defineStore('api-customer', () => { >('/customer-branch', data, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -329,7 +331,7 @@ const useCustomerStore = defineStore('api-customer', () => { >(`/customer-branch/${id}`, data, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -349,7 +351,7 @@ const useCustomerStore = defineStore('api-customer', () => { const res = await api.delete(`/customer-branch/${id}`, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -402,7 +404,7 @@ const useCustomerStore = defineStore('api-customer', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -433,7 +435,7 @@ const useCustomerStore = defineStore('api-customer', () => { const res = await api.get(`/customer-branch/${branchId}`, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); diff --git a/src/stores/employee/index.ts b/src/stores/employee/index.ts index 46001206..1ed0ca8f 100644 --- a/src/stores/employee/index.ts +++ b/src/stores/employee/index.ts @@ -11,8 +11,10 @@ import { } from './types'; import { CustomerBranch } from '../customer/types'; import axios from 'axios'; +import useFlowStore from '../flow'; const useEmployeeStore = defineStore('api-employee', () => { + const flowStore = useFlowStore(); const data = ref>(); const globalOption = ref(); const ownerOption = ref(); @@ -48,7 +50,7 @@ const useEmployeeStore = defineStore('api-employee', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -75,7 +77,7 @@ const useEmployeeStore = defineStore('api-employee', () => { >('/employee', payload, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -108,7 +110,7 @@ const useEmployeeStore = defineStore('api-employee', () => { >(`/employee/${id}`, payload, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -137,7 +139,7 @@ const useEmployeeStore = defineStore('api-employee', () => { const res = await api.delete(`/employee/${id}`, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -159,7 +161,7 @@ const useEmployeeStore = defineStore('api-employee', () => { const res = await api.get(`/employee/${id}/checkup`, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -179,7 +181,7 @@ const useEmployeeStore = defineStore('api-employee', () => { const res = await api.get(`/employee/${id}/work`, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -199,7 +201,7 @@ const useEmployeeStore = defineStore('api-employee', () => { const res = await api.get(`/employee/${id}/other-info`, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -221,7 +223,7 @@ const useEmployeeStore = defineStore('api-employee', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -244,7 +246,7 @@ const useEmployeeStore = defineStore('api-employee', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, diff --git a/src/stores/flow/index.ts b/src/stores/flow/index.ts new file mode 100644 index 00000000..030ff18a --- /dev/null +++ b/src/stores/flow/index.ts @@ -0,0 +1,16 @@ +import { ref } from 'vue'; +import { defineStore } from 'pinia'; + +const useFlowStore = defineStore('flow', () => { + const rtid = ref(crypto.randomUUID()); + + return { + rtid, + + rotate() { + rtid.value = crypto.randomUUID(); + }, + }; +}); + +export default useFlowStore; diff --git a/src/stores/product-service/index.ts b/src/stores/product-service/index.ts index 32651a4f..bcc571e4 100644 --- a/src/stores/product-service/index.ts +++ b/src/stores/product-service/index.ts @@ -21,9 +21,11 @@ import { ServiceAndProduct, } from './types'; import { ref } from 'vue'; +import useFlowStore from '../flow'; const useProductServiceStore = defineStore('api-product-service', () => { // Product Type + const flowStore = useFlowStore(); const workNameItems = ref<{ id: string; name: string; isEdit: boolean }[]>( [], @@ -76,7 +78,7 @@ const useProductServiceStore = defineStore('api-product-service', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -190,7 +192,7 @@ const useProductServiceStore = defineStore('api-product-service', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -300,7 +302,7 @@ const useProductServiceStore = defineStore('api-product-service', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -428,7 +430,7 @@ const useProductServiceStore = defineStore('api-product-service', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -491,7 +493,7 @@ const useProductServiceStore = defineStore('api-product-service', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -588,7 +590,7 @@ const useProductServiceStore = defineStore('api-product-service', () => { >(`/work${(params && '?'.concat(query)) || ''}`, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -681,7 +683,7 @@ const useProductServiceStore = defineStore('api-product-service', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -732,7 +734,7 @@ const useProductServiceStore = defineStore('api-product-service', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, diff --git a/src/stores/user/index.ts b/src/stores/user/index.ts index 524938cf..62d38d4d 100644 --- a/src/stores/user/index.ts +++ b/src/stores/user/index.ts @@ -15,10 +15,12 @@ import axios from 'axios'; import useBranchStore from '../branch'; import { Branch } from '../branch/types'; import { useI18n } from 'vue-i18n'; +import useFlowStore from '../flow'; const branchStore = useBranchStore(); const useUserStore = defineStore('api-user', () => { + const flowStore = useFlowStore(); const userOption = ref({ hqOpts: [], brOpts: [], @@ -145,7 +147,7 @@ const useUserStore = defineStore('api-user', () => { const res = await api.get(`/user/${userId}/attachment`, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -198,7 +200,7 @@ const useUserStore = defineStore('api-user', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -231,7 +233,7 @@ const useUserStore = defineStore('api-user', () => { data: payload, headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -270,7 +272,7 @@ const useUserStore = defineStore('api-user', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -294,7 +296,7 @@ const useUserStore = defineStore('api-user', () => { const res = await api.get(`/user/${id}`, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -321,7 +323,7 @@ const useUserStore = defineStore('api-user', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -356,7 +358,7 @@ const useUserStore = defineStore('api-user', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -386,7 +388,7 @@ const useUserStore = defineStore('api-user', () => { const res = await api.delete(`/user/${id}`, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -408,7 +410,7 @@ const useUserStore = defineStore('api-user', () => { const res = await api.get>(`/user/${userId}/branch`, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }); @@ -434,7 +436,7 @@ const useUserStore = defineStore('api-user', () => { { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, }, @@ -458,7 +460,7 @@ const useUserStore = defineStore('api-user', () => { const res = await api.delete(`/user/${userId}/branch`, { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, data: { branch: ([] as string[]).concat(branchId) }, @@ -478,7 +480,7 @@ const useUserStore = defineStore('api-user', () => { const res = await api.get('/user/type-stats', { headers: { 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId, + 'X-Rtid': flow?.refTransactionId || flowStore.rtid, 'X-Tid': flow?.transactionId, }, });