From 233babd89b56e2a77e3d9f83024f77ce1178cb51 Mon Sep 17 00:00:00 2001 From: Methapon Metanipat Date: Wed, 4 Sep 2024 13:32:20 +0700 Subject: [PATCH] refactor: remove unused --- src/stores/branch-contact/index.ts | 162 ----------------------------- 1 file changed, 162 deletions(-) diff --git a/src/stores/branch-contact/index.ts b/src/stores/branch-contact/index.ts index fa28e700..8b137891 100644 --- a/src/stores/branch-contact/index.ts +++ b/src/stores/branch-contact/index.ts @@ -1,163 +1 @@ -import axios from 'axios'; -import { ref, watch } from 'vue'; -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, - pageSize: 0, - total: 0, - }); - const map = ref>({}); - - watch(data, () => { - data.value.result.forEach((v) => { - map.value[v.id] = v; - }); - }); - - async function fetchList( - branchId: string, - opts?: { - page?: number; - pageSize?: number; - }, - flow?: { - sessionId?: string; - refTransactionId?: string; - transactionId?: string; - }, - ) { - const params = new URLSearchParams(); - - if (opts?.pageSize && opts?.pageSize > 0) { - params.append('pageSize', `${opts.pageSize}`); - } - if (opts?.page && opts.page > 0) params.append('page', `${opts.page}`); - - const query = params.toString(); - - const res = await api.get>( - `/branch/${branchId}/contact${(params && '?'.concat(query)) || ''}`, - { - headers: { - 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId || flowStore.rtid, - 'X-Tid': flow?.transactionId, - }, - }, - ); - - if (res && res.status === 200) { - data.value = res.data; - return data.value; - } - return false; - } - - async function create( - branchId: string, - data: BranchContactCreate, - flow?: { - sessionId?: string; - refTransactionId?: string; - transactionId?: string; - }, - ) { - const res = await api.post< - BranchContact & { qrCodeImageUploadUrl: string } - >(`/branch/${branchId}/contact`, data, { - headers: { - 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId || flowStore.rtid, - 'X-Tid': flow?.transactionId, - }, - }); - - if (!res) return false; - - return res.data; - } - - async function editById( - branchId: string, - contactId: string, - data: Partial, - qrCodeImage?: File, - flow?: { - sessionId?: string; - refTransactionId?: string; - transactionId?: string; - }, - ) { - const { ...payload } = data; - - const res = await api.put( - `/branch/${branchId}/contact/${contactId}`, - payload, - { - headers: { - 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId || flowStore.rtid, - 'X-Tid': flow?.transactionId, - }, - }, - ); - - if (qrCodeImage) { - await axios - .put(res.data.qrCodeImageUploadUrl, qrCodeImage, { - headers: { 'Content-Type': qrCodeImage.type }, - onUploadProgress: (e) => console.log(e), - }) - .catch((e) => console.error(e)); - } - - if (!res) return false; - - return res.data; - } - - async function deleteById( - branchId: string, - contactId: string, - flow?: { - sessionId?: string; - refTransactionId?: string; - transactionId?: string; - }, - ) { - const res = await api.delete< - BranchContact & { qrCodeImageUploadUrl: string } - >(`/branch/${branchId}/contact/${contactId}`, { - headers: { - 'X-Session-Id': flow?.sessionId, - 'X-Rtid': flow?.refTransactionId || flowStore.rtid, - 'X-Tid': flow?.transactionId, - }, - }); - - if (!res) return false; - - return res.data; - } - - return { - data, - map, - fetchList, - create, - editById, - deleteById, - }; -}); - -export default useBranchContactStore;