From 75246296aec7ec18ab9085e9860ff92cedd6ab28 Mon Sep 17 00:00:00 2001 From: oat_dev Date: Mon, 10 Jun 2024 14:10:34 +0700 Subject: [PATCH] feat: customer branch function + add --- src/pages/03_customer-management/MainPage.vue | 20 ++++- src/stores/customer/index.ts | 77 +++++++++++++++++++ 2 files changed, 95 insertions(+), 2 deletions(-) diff --git a/src/pages/03_customer-management/MainPage.vue b/src/pages/03_customer-management/MainPage.vue index e67e2a67..a0cdf1fa 100644 --- a/src/pages/03_customer-management/MainPage.vue +++ b/src/pages/03_customer-management/MainPage.vue @@ -30,6 +30,7 @@ import { Customer, CustomerUpdate, CustomerBranch, + CustomerBranchCreate, } from 'stores/customer/types'; import { onMounted } from 'vue'; import FormPerson from 'src/components/02_personnel-management/FormPerson.vue'; @@ -38,8 +39,15 @@ import FormEmployeeHealthCheck from 'src/components/03_customer-management/FormE import { dialog } from 'src/stores/utils'; const userCustomer = useCustomerStore(); -const { create, getStatsCustomer, fetchList, editById, fetchListById } = - userCustomer; +const { + create, + getStatsCustomer, + fetchList, + editById, + fetchListById, + createBranch, + deleteBranchById, +} = userCustomer; const formData = ref({ status: 'CREATED', customerType: 'CORP', @@ -302,6 +310,14 @@ async function onSubmit() { async function onSubmitCustomerBranch() { dialogInputCustomerBranchForm.value = false; + // await createBranch(); + + for (const item of formData.value.customerBranch || []) { + await createBranch({ + ...item, + customerId: currentCustomerId.value, + }); + } clearForm(); const result = await fetchListById(currentCustomerId.value); if (result) { diff --git a/src/stores/customer/index.ts b/src/stores/customer/index.ts index 755c3b0b..caca6871 100644 --- a/src/stores/customer/index.ts +++ b/src/stores/customer/index.ts @@ -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, + 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-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, }; });