feat: add flow store

This commit is contained in:
Methapon2001 2024-06-25 16:05:42 +07:00
parent 02c5aa2a1c
commit 44ae39907e
7 changed files with 83 additions and 55 deletions

View file

@ -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<Pagination<BranchContact[]>>({
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,
},
});

View file

@ -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<Pagination<Branch[]>>({
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>(`/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,
},
},

View file

@ -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<Pagination<Customer[]>>();
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<CustomerStats>('/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>(`/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>(`/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,
},
});

View file

@ -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<Pagination<Employee[]>>();
const globalOption = ref();
const ownerOption = ref<CustomerBranch[]>();
@ -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>(`/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<EmployeeCheckup[]>(`/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<EmployeeWork[]>(`/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<EmployeeOther>(`/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,
},
},

16
src/stores/flow/index.ts Normal file
View file

@ -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;

View file

@ -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,
},
},

View file

@ -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<UserOption>({
hqOpts: [],
brOpts: [],
@ -145,7 +147,7 @@ const useUserStore = defineStore('api-user', () => {
const res = await api.get<UserAttachment[]>(`/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>(`/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>(`/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<Pagination<Branch[]>>(`/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,
},
});