refactor: extract type
This commit is contained in:
parent
be2d232fab
commit
1b0cbc606c
2 changed files with 65 additions and 75 deletions
|
|
@ -1,41 +1,13 @@
|
|||
import { ref } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import { District, Province, SubDistrict } from '../address';
|
||||
import { Pagination, Status } from '../types';
|
||||
import { Pagination } from '../types';
|
||||
import { api } from 'src/boot/axios';
|
||||
|
||||
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;
|
||||
};
|
||||
import { Branch, BranchCreate } from './types';
|
||||
|
||||
const useBranchStore = defineStore('api-branch', () => {
|
||||
const data = ref<Pagination<Branch[]>>();
|
||||
|
||||
async function fetchBranch(
|
||||
async function fetchList(
|
||||
opts?: {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
|
|
@ -77,7 +49,7 @@ const useBranchStore = defineStore('api-branch', () => {
|
|||
return false;
|
||||
}
|
||||
|
||||
async function fetchBranchById(
|
||||
async function fetchById(
|
||||
id: string,
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
|
|
@ -100,31 +72,17 @@ const useBranchStore = defineStore('api-branch', () => {
|
|||
return false;
|
||||
}
|
||||
|
||||
async function createBranch(
|
||||
branch: {
|
||||
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;
|
||||
},
|
||||
async function create(
|
||||
branch: BranchCreate,
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const res = await api.post<Branch>('/branch', branch, {
|
||||
const res = await api.post<
|
||||
Branch & { qrCodeImageUrl: string; qrCodeImageUploadUrl: string }
|
||||
>('/branch', branch, {
|
||||
headers: {
|
||||
'X-Session-Id': flow?.sessionId,
|
||||
'X-Rtid': flow?.refTransactionId,
|
||||
|
|
@ -137,25 +95,9 @@ const useBranchStore = defineStore('api-branch', () => {
|
|||
return res.data;
|
||||
}
|
||||
|
||||
async function editBranchById(
|
||||
async function editById(
|
||||
id: string,
|
||||
branch: {
|
||||
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;
|
||||
},
|
||||
branch: Partial<BranchCreate>,
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
|
|
@ -175,7 +117,7 @@ const useBranchStore = defineStore('api-branch', () => {
|
|||
return res.data;
|
||||
}
|
||||
|
||||
async function deleteBranchById(
|
||||
async function deleteById(
|
||||
id: string,
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
|
|
@ -272,12 +214,12 @@ const useBranchStore = defineStore('api-branch', () => {
|
|||
|
||||
return {
|
||||
data,
|
||||
fetchBranch,
|
||||
fetchBranchById,
|
||||
fetchList,
|
||||
fetchById,
|
||||
|
||||
createBranch,
|
||||
editBranchById,
|
||||
deleteBranchById,
|
||||
create,
|
||||
editById,
|
||||
deleteById,
|
||||
|
||||
getUser,
|
||||
addUser,
|
||||
|
|
|
|||
48
src/stores/branch/types.ts
Normal file
48
src/stores/branch/types.ts
Normal 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;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue