feat: customer branch function + add

This commit is contained in:
oat_dev 2024-06-10 14:10:34 +07:00
parent aba1d61e01
commit 75246296ae
2 changed files with 95 additions and 2 deletions

View file

@ -10,6 +10,7 @@ import {
BranchAttachment,
CustomerStats,
CustomerBranch,
CustomerBranchCreate,
} from './types';
import axios from 'axios';
@ -231,6 +232,79 @@ const useCustomerStore = defineStore('api-customer', () => {
return false;
}
async function createBranch(
data: CustomerBranchCreate & { customerId: string },
flow?: {
sessionId: string;
refTransactionId: string;
transactionId: string;
},
) {
const res = await api.post<
Customer & {
branch: CustomerBranch[];
imageUrl: string;
imageUploadUrl: string;
}
>('/customer-branch', data, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId,
'X-Tid': flow?.transactionId,
},
});
if (!res) return false;
return res.data;
}
async function editBranchById(
id: string,
data: Partial<CustomerBranchCreate & { customerId: string }>,
flow?: {
sessionId: string;
refTransactionId: string;
transactionId: string;
},
) {
const res = await api.put<
Customer & {
branch: CustomerBranch[];
}
>(`'/customer-branch'/${id}`, data, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId,
'X-Tid': flow?.transactionId,
},
});
if (!res) return false;
return res.data;
}
async function deleteBranchById(
id: string,
flow?: {
sessionId: string;
refTransactionId: string;
transactionId: string;
},
) {
const res = await api.delete<Customer>(`/customer-branch/${id}`, {
headers: {
'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId,
'X-Tid': flow?.transactionId,
},
});
if (!res) return false;
if (res.status === 200) return res.data;
return false;
}
async function addBranchAttachment(
branchId: string,
payload: BranchAttachmentCreate,
@ -303,6 +377,9 @@ const useCustomerStore = defineStore('api-customer', () => {
create,
editById,
deleteById,
createBranch,
editBranchById,
deleteBranchById,
};
});