refactor: extract type

This commit is contained in:
Methapon2001 2024-04-04 11:46:25 +07:00
parent be2d232fab
commit 1b0cbc606c
2 changed files with 65 additions and 75 deletions

View file

@ -1,41 +1,13 @@
import { ref } from 'vue'; import { ref } from 'vue';
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { District, Province, SubDistrict } from '../address'; import { Pagination } from '../types';
import { Pagination, Status } from '../types';
import { api } from 'src/boot/axios'; import { api } from 'src/boot/axios';
import { Branch, BranchCreate } from './types';
export type Branch = {
subDistrict: SubDistrict | null;
district: District | null;
province: Province | null;
updatedAt: string;
updateBy: string;
createdAt: string;
createdBy: string;
status: Status;
headOfficeId: string | null;
isHeadOffice: boolean;
longitude: string;
latitude: string;
telephoneNo: string;
email: string;
zipCode: string;
subDistrictId: string;
districtId: string;
provinceId: string;
addressEN: string;
addressTH: string;
nameEN: string;
nameTH: string;
taxNo: string;
code: string;
id: string;
};
const useBranchStore = defineStore('api-branch', () => { const useBranchStore = defineStore('api-branch', () => {
const data = ref<Pagination<Branch[]>>(); const data = ref<Pagination<Branch[]>>();
async function fetchBranch( async function fetchList(
opts?: { opts?: {
page?: number; page?: number;
pageSize?: number; pageSize?: number;
@ -77,7 +49,7 @@ const useBranchStore = defineStore('api-branch', () => {
return false; return false;
} }
async function fetchBranchById( async function fetchById(
id: string, id: string,
flow?: { flow?: {
sessionId: string; sessionId: string;
@ -100,31 +72,17 @@ const useBranchStore = defineStore('api-branch', () => {
return false; return false;
} }
async function createBranch( async function create(
branch: { branch: BranchCreate,
code: string;
taxNo: string;
nameEN: string;
nameTH: string;
addressEN: string;
addressTH: string;
zipCode: string;
email: string;
telephoneNo: string;
longitude: string;
latitude: string;
subDistrictId?: string | null;
districtId?: string | null;
provinceId?: string | null;
headOfficeId?: string | null;
},
flow?: { flow?: {
sessionId: string; sessionId: string;
refTransactionId: string; refTransactionId: string;
transactionId: string; transactionId: string;
}, },
) { ) {
const res = await api.post<Branch>('/branch', branch, { const res = await api.post<
Branch & { qrCodeImageUrl: string; qrCodeImageUploadUrl: string }
>('/branch', branch, {
headers: { headers: {
'X-Session-Id': flow?.sessionId, 'X-Session-Id': flow?.sessionId,
'X-Rtid': flow?.refTransactionId, 'X-Rtid': flow?.refTransactionId,
@ -137,25 +95,9 @@ const useBranchStore = defineStore('api-branch', () => {
return res.data; return res.data;
} }
async function editBranchById( async function editById(
id: string, id: string,
branch: { branch: Partial<BranchCreate>,
code?: string;
taxNo?: string;
nameEN?: string;
nameTH?: string;
addressEN?: string;
addressTH?: string;
zipCode?: string;
email?: string;
telephoneNo?: string;
longitude?: string;
latitude?: string;
subDistrictId?: string | null;
districtId?: string | null;
provinceId?: string | null;
headOfficeId?: string | null;
},
flow?: { flow?: {
sessionId: string; sessionId: string;
refTransactionId: string; refTransactionId: string;
@ -175,7 +117,7 @@ const useBranchStore = defineStore('api-branch', () => {
return res.data; return res.data;
} }
async function deleteBranchById( async function deleteById(
id: string, id: string,
flow?: { flow?: {
sessionId: string; sessionId: string;
@ -272,12 +214,12 @@ const useBranchStore = defineStore('api-branch', () => {
return { return {
data, data,
fetchBranch, fetchList,
fetchBranchById, fetchById,
createBranch, create,
editBranchById, editById,
deleteBranchById, deleteById,
getUser, getUser,
addUser, addUser,

View file

@ -0,0 +1,48 @@
import { District, Province, SubDistrict } from '../address';
import { Status } from '../types';
export type Branch = {
subDistrict: SubDistrict | null;
district: District | null;
province: Province | null;
updatedAt: string;
updateBy: string;
createdAt: string;
createdBy: string;
status: Status;
headOfficeId: string | null;
isHeadOffice: boolean;
longitude: string;
latitude: string;
telephoneNo: string;
email: string;
zipCode: string;
subDistrictId: string | null;
districtId: string | null;
provinceId: string | null;
addressEN: string;
addressTH: string;
nameEN: string;
nameTH: string;
taxNo: string;
code: string;
id: string;
};
export type BranchCreate = {
code: string;
taxNo: string;
nameEN: string;
nameTH: string;
addressEN: string;
addressTH: string;
zipCode: string;
email: string;
telephoneNo: string;
longitude: string;
latitude: string;
subDistrictId?: string | null;
districtId?: string | null;
provinceId?: string | null;
headOfficeId?: string | null;
};