feat: branch user related endpoint
This commit is contained in:
parent
63457d93a1
commit
5ecfe80965
1 changed files with 170 additions and 29 deletions
|
|
@ -35,12 +35,19 @@ export type Branch = {
|
|||
const useBranchStore = defineStore('api-branch', () => {
|
||||
const data = ref<Pagination<Branch[]>>();
|
||||
|
||||
async function fetchBranch(opts?: {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
zipCode?: string;
|
||||
query?: string;
|
||||
}) {
|
||||
async function fetchBranch(
|
||||
opts?: {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
zipCode?: string;
|
||||
query?: string;
|
||||
},
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (opts?.pageSize && opts?.pageSize > 0) {
|
||||
|
|
@ -54,6 +61,13 @@ const useBranchStore = defineStore('api-branch', () => {
|
|||
|
||||
const res = await api.get<Pagination<Branch[]>>(
|
||||
`/branch${(params && '?'.concat(query)) || ''}`,
|
||||
{
|
||||
headers: {
|
||||
'X-Session-Id': flow?.sessionId,
|
||||
'X-Rtid': flow?.refTransactionId,
|
||||
'X-Tid': flow?.transactionId,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (res && res.status === 200) {
|
||||
|
|
@ -63,8 +77,21 @@ const useBranchStore = defineStore('api-branch', () => {
|
|||
return false;
|
||||
}
|
||||
|
||||
async function fetchBranchById(id: string) {
|
||||
const res = await api.get<Branch>(`/branch/${id}`);
|
||||
async function fetchBranchById(
|
||||
id: string,
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const res = await api.get<Branch>(`/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;
|
||||
|
|
@ -73,24 +100,37 @@ 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;
|
||||
}) {
|
||||
const res = await api.post<Branch>('/branch', branch);
|
||||
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;
|
||||
},
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const res = await api.post<Branch>('/branch', branch, {
|
||||
headers: {
|
||||
'X-Session-Id': flow?.sessionId,
|
||||
'X-Rtid': flow?.refTransactionId,
|
||||
'X-Tid': flow?.transactionId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!res) return false;
|
||||
|
||||
|
|
@ -116,16 +156,113 @@ const useBranchStore = defineStore('api-branch', () => {
|
|||
provinceId?: string | null;
|
||||
headOfficeId?: string | null;
|
||||
},
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const res = await api.patch<Branch>(`/branch/${id}`, branch);
|
||||
const res = await api.put<Branch>(`/branch/${id}`, branch, {
|
||||
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) {
|
||||
const res = await api.delete<Branch>(`/branch/${id}`);
|
||||
async function deleteBranchById(
|
||||
id: string,
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const res = await api.delete<Branch>(`/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 getUser(
|
||||
branchId: string,
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const res = await api.get(`/branch/${branchId}/user`, {
|
||||
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 addUser(
|
||||
branchId: string,
|
||||
userId: string | string[],
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const res = await api.post(
|
||||
`/branch/${branchId}/user`,
|
||||
{ user: ([] as string[]).concat(userId) },
|
||||
{
|
||||
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 removeUser(
|
||||
branchId: string,
|
||||
userId: string | string[],
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const res = await api.delete(`/branch/${branchId}/user`, {
|
||||
headers: {
|
||||
'X-Session-Id': flow?.sessionId,
|
||||
'X-Rtid': flow?.refTransactionId,
|
||||
'X-Tid': flow?.transactionId,
|
||||
},
|
||||
data: { user: ([] as string[]).concat(userId) },
|
||||
});
|
||||
|
||||
if (!res) return false;
|
||||
if (res.status === 200) return res.data;
|
||||
|
|
@ -141,6 +278,10 @@ const useBranchStore = defineStore('api-branch', () => {
|
|||
createBranch,
|
||||
editBranchById,
|
||||
deleteBranchById,
|
||||
|
||||
getUser,
|
||||
addUser,
|
||||
removeUser,
|
||||
};
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue