diff --git a/src/stores/branch/index.ts b/src/stores/branch/index.ts index 286564e3..d270d850 100644 --- a/src/stores/branch/index.ts +++ b/src/stores/branch/index.ts @@ -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>(); - 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, { + 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, 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, diff --git a/src/stores/branch/types.ts b/src/stores/branch/types.ts new file mode 100644 index 00000000..93359487 --- /dev/null +++ b/src/stores/branch/types.ts @@ -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; +};