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 useBranchStore = defineStore('api-branch', () => {
|
||||||
const data = ref<Pagination<Branch[]>>();
|
const data = ref<Pagination<Branch[]>>();
|
||||||
|
|
||||||
async function fetchBranch(opts?: {
|
async function fetchBranch(
|
||||||
page?: number;
|
opts?: {
|
||||||
pageSize?: number;
|
page?: number;
|
||||||
zipCode?: string;
|
pageSize?: number;
|
||||||
query?: string;
|
zipCode?: string;
|
||||||
}) {
|
query?: string;
|
||||||
|
},
|
||||||
|
flow?: {
|
||||||
|
sessionId: string;
|
||||||
|
refTransactionId: string;
|
||||||
|
transactionId: string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
if (opts?.pageSize && opts?.pageSize > 0) {
|
if (opts?.pageSize && opts?.pageSize > 0) {
|
||||||
|
|
@ -54,6 +61,13 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
|
|
||||||
const res = await api.get<Pagination<Branch[]>>(
|
const res = await api.get<Pagination<Branch[]>>(
|
||||||
`/branch${(params && '?'.concat(query)) || ''}`,
|
`/branch${(params && '?'.concat(query)) || ''}`,
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
'X-Session-Id': flow?.sessionId,
|
||||||
|
'X-Rtid': flow?.refTransactionId,
|
||||||
|
'X-Tid': flow?.transactionId,
|
||||||
|
},
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (res && res.status === 200) {
|
if (res && res.status === 200) {
|
||||||
|
|
@ -63,8 +77,21 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchBranchById(id: string) {
|
async function fetchBranchById(
|
||||||
const res = await api.get<Branch>(`/branch/${id}`);
|
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) return false;
|
||||||
if (res.status === 200) return res.data;
|
if (res.status === 200) return res.data;
|
||||||
|
|
@ -73,24 +100,37 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createBranch(branch: {
|
async function createBranch(
|
||||||
code: string;
|
branch: {
|
||||||
taxNo: string;
|
code: string;
|
||||||
nameEN: string;
|
taxNo: string;
|
||||||
nameTH: string;
|
nameEN: string;
|
||||||
addressEN: string;
|
nameTH: string;
|
||||||
addressTH: string;
|
addressEN: string;
|
||||||
zipCode: string;
|
addressTH: string;
|
||||||
email: string;
|
zipCode: string;
|
||||||
telephoneNo: string;
|
email: string;
|
||||||
longitude: string;
|
telephoneNo: string;
|
||||||
latitude: string;
|
longitude: string;
|
||||||
subDistrictId?: string | null;
|
latitude: string;
|
||||||
districtId?: string | null;
|
subDistrictId?: string | null;
|
||||||
provinceId?: string | null;
|
districtId?: string | null;
|
||||||
headOfficeId?: string | null;
|
provinceId?: string | null;
|
||||||
}) {
|
headOfficeId?: string | null;
|
||||||
const res = await api.post<Branch>('/branch', branch);
|
},
|
||||||
|
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;
|
if (!res) return false;
|
||||||
|
|
||||||
|
|
@ -116,16 +156,113 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
provinceId?: string | null;
|
provinceId?: string | null;
|
||||||
headOfficeId?: 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;
|
if (!res) return false;
|
||||||
|
|
||||||
return res.data;
|
return res.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteBranchById(id: string) {
|
async function deleteBranchById(
|
||||||
const res = await api.delete<Branch>(`/branch/${id}`);
|
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) return false;
|
||||||
if (res.status === 200) return res.data;
|
if (res.status === 200) return res.data;
|
||||||
|
|
@ -141,6 +278,10 @@ const useBranchStore = defineStore('api-branch', () => {
|
||||||
createBranch,
|
createBranch,
|
||||||
editBranchById,
|
editBranchById,
|
||||||
deleteBranchById,
|
deleteBranchById,
|
||||||
|
|
||||||
|
getUser,
|
||||||
|
addUser,
|
||||||
|
removeUser,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue