Merge branch 'feat/api-endpoints-fn' into develop
This commit is contained in:
commit
6e896a7a37
6 changed files with 546 additions and 75 deletions
153
src/stores/branch-contact/index.ts
Normal file
153
src/stores/branch-contact/index.ts
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
import axios from 'axios';
|
||||
import { ref } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import { BranchContact, BranchContactCreate } from './types';
|
||||
import { Pagination } from '../types';
|
||||
import { api } from 'src/boot/axios';
|
||||
|
||||
const useBranchContactStore = defineStore('api-branch-contact', () => {
|
||||
const data = ref<Pagination<BranchContact[]>>();
|
||||
|
||||
async function fetchList(
|
||||
branchId: string,
|
||||
opts?: {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
},
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const params = new URLSearchParams();
|
||||
|
||||
if (opts?.pageSize && opts?.pageSize > 0) {
|
||||
params.append('pageSize', `${opts.pageSize}`);
|
||||
}
|
||||
if (opts?.page && opts.page > 0) params.append('page', `${opts.page}`);
|
||||
|
||||
const query = params.toString();
|
||||
|
||||
const res = await api.get<Pagination<BranchContact[]>>(
|
||||
`/branch/${branchId}/contact${(params && '?'.concat(query)) || ''}`,
|
||||
{
|
||||
headers: {
|
||||
'X-Session-Id': flow?.sessionId,
|
||||
'X-Rtid': flow?.refTransactionId,
|
||||
'X-Tid': flow?.transactionId,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (res && res.status === 200) {
|
||||
data.value = res.data;
|
||||
return data.value;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async function create(
|
||||
branchId: string,
|
||||
data: BranchContactCreate,
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const { qrCodeImage, ...payload } = data;
|
||||
|
||||
const res = await api.post<
|
||||
BranchContact & { qrCodeImageUploadUrl: string }
|
||||
>(`/branch/${branchId}/contact`, payload, {
|
||||
headers: {
|
||||
'X-Session-Id': flow?.sessionId,
|
||||
'X-Rtid': flow?.refTransactionId,
|
||||
'X-Tid': flow?.transactionId,
|
||||
},
|
||||
});
|
||||
|
||||
await axios
|
||||
.put(res.data.qrCodeImageUploadUrl, qrCodeImage, {
|
||||
headers: { 'Content-Type': qrCodeImage.type },
|
||||
onUploadProgress: (e) => console.log(e),
|
||||
})
|
||||
.catch((e) => console.error(e));
|
||||
|
||||
if (!res) return false;
|
||||
|
||||
return res.data;
|
||||
}
|
||||
|
||||
async function editById(
|
||||
branchId: string,
|
||||
contactId: string,
|
||||
data: Partial<BranchContactCreate>,
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const { qrCodeImage, ...payload } = data;
|
||||
|
||||
const res = await api.put<BranchContact & { qrCodeImageUploadUrl: string }>(
|
||||
`/branch/${branchId}/contact/${contactId}`,
|
||||
payload,
|
||||
{
|
||||
headers: {
|
||||
'X-Session-Id': flow?.sessionId,
|
||||
'X-Rtid': flow?.refTransactionId,
|
||||
'X-Tid': flow?.transactionId,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (qrCodeImage) {
|
||||
await axios
|
||||
.put(res.data.qrCodeImageUploadUrl, qrCodeImage, {
|
||||
headers: { 'Content-Type': qrCodeImage.type },
|
||||
onUploadProgress: (e) => console.log(e),
|
||||
})
|
||||
.catch((e) => console.error(e));
|
||||
}
|
||||
|
||||
if (!res) return false;
|
||||
|
||||
return res.data;
|
||||
}
|
||||
|
||||
async function deleteById(
|
||||
branchId: string,
|
||||
contactId: string,
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const res = await api.delete<
|
||||
BranchContact & { qrCodeImageUploadUrl: string }
|
||||
>(`/branch/${branchId}/contact/${contactId}`, {
|
||||
headers: {
|
||||
'X-Session-Id': flow?.sessionId,
|
||||
'X-Rtid': flow?.refTransactionId,
|
||||
'X-Tid': flow?.transactionId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!res) return false;
|
||||
|
||||
return res.data;
|
||||
}
|
||||
|
||||
return {
|
||||
fetchList,
|
||||
create,
|
||||
editById,
|
||||
deleteById,
|
||||
};
|
||||
});
|
||||
|
||||
export default useBranchContactStore;
|
||||
16
src/stores/branch-contact/types.ts
Normal file
16
src/stores/branch-contact/types.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
export type BranchContact = {
|
||||
id: string;
|
||||
lineId: string;
|
||||
telephoneNo: string;
|
||||
qrCodeImageUrl: string;
|
||||
updatedAt: string;
|
||||
updateBy: string;
|
||||
createdAt: string;
|
||||
createdBy: string;
|
||||
};
|
||||
|
||||
export type BranchContactCreate = {
|
||||
lineId: string;
|
||||
telephoneNo: string;
|
||||
qrCodeImage: File;
|
||||
};
|
||||
|
|
@ -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;
|
||||
};
|
||||
241
src/stores/user/index.ts
Normal file
241
src/stores/user/index.ts
Normal file
|
|
@ -0,0 +1,241 @@
|
|||
import { ref } from 'vue';
|
||||
import { defineStore } from 'pinia';
|
||||
import { Pagination } from '../types';
|
||||
import { api } from 'src/boot/axios';
|
||||
import { User, UserCreate } from './types';
|
||||
import axios from 'axios';
|
||||
|
||||
const useUserStore = defineStore('api-user', () => {
|
||||
const data = ref<Pagination<User[]>>();
|
||||
|
||||
async function fetchList(
|
||||
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) {
|
||||
params.append('pageSize', `${opts.pageSize}`);
|
||||
}
|
||||
if (opts?.page && opts.page > 0) params.append('page', `${opts.page}`);
|
||||
if (opts?.zipCode) params.append('zipCode', opts.zipCode);
|
||||
if (opts?.query) params.append('query', opts.query);
|
||||
|
||||
const query = params.toString();
|
||||
|
||||
const res = await api.get<Pagination<User[]>>(
|
||||
`/user${(params && '?'.concat(query)) || ''}`,
|
||||
{
|
||||
headers: {
|
||||
'X-Session-Id': flow?.sessionId,
|
||||
'X-Rtid': flow?.refTransactionId,
|
||||
'X-Tid': flow?.transactionId,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (res && res.status === 200) {
|
||||
data.value = res.data;
|
||||
return data.value;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
async function fetchById(
|
||||
id: string,
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const res = await api.get<User>(`/user/${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;
|
||||
if (res.status === 204) return null;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
async function create(
|
||||
data: UserCreate,
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const { profileImage, ...payload } = data;
|
||||
const res = await api.post<User & { profileImageUploadUrl: string }>(
|
||||
'/user',
|
||||
payload,
|
||||
{
|
||||
headers: {
|
||||
'X-Session-Id': flow?.sessionId,
|
||||
'X-Rtid': flow?.refTransactionId,
|
||||
'X-Tid': flow?.transactionId,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
await axios
|
||||
.put(res.data.profileImageUploadUrl, profileImage, {
|
||||
headers: { 'Content-Type': profileImage.type },
|
||||
onUploadProgress: (e) => console.log(e),
|
||||
})
|
||||
.catch((e) => console.error(e));
|
||||
|
||||
if (!res) return false;
|
||||
|
||||
return res.data;
|
||||
}
|
||||
|
||||
async function editById(
|
||||
id: string,
|
||||
data: Partial<Omit<UserCreate, 'keycloakId'>>,
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const res = await api.put<User>(`/user/${id}`, data, {
|
||||
headers: {
|
||||
'X-Session-Id': flow?.sessionId,
|
||||
'X-Rtid': flow?.refTransactionId,
|
||||
'X-Tid': flow?.transactionId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!res) return false;
|
||||
|
||||
return res.data;
|
||||
}
|
||||
|
||||
async function deleteById(
|
||||
id: string,
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const res = await api.delete<User>(`/user/${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 getBranch(
|
||||
userId: string,
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const res = await api.get(`/user/${userId}/branch`, {
|
||||
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 addBranch(
|
||||
userId: string,
|
||||
branchId: string | string[],
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const res = await api.post(
|
||||
`/user/${userId}/branch`,
|
||||
{ user: ([] as string[]).concat(branchId) },
|
||||
{
|
||||
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 removeBranch(
|
||||
userId: string,
|
||||
branchId: string | string[],
|
||||
flow?: {
|
||||
sessionId: string;
|
||||
refTransactionId: string;
|
||||
transactionId: string;
|
||||
},
|
||||
) {
|
||||
const res = await api.delete(`/user/${userId}/branch`, {
|
||||
headers: {
|
||||
'X-Session-Id': flow?.sessionId,
|
||||
'X-Rtid': flow?.refTransactionId,
|
||||
'X-Tid': flow?.transactionId,
|
||||
},
|
||||
data: { user: ([] as string[]).concat(branchId) },
|
||||
});
|
||||
|
||||
if (!res) return false;
|
||||
if (res.status === 200) return res.data;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return {
|
||||
data,
|
||||
fetchList,
|
||||
fetchById,
|
||||
|
||||
create,
|
||||
editById,
|
||||
deleteById,
|
||||
|
||||
getBranch,
|
||||
addBranch,
|
||||
removeBranch,
|
||||
};
|
||||
});
|
||||
|
||||
export default useUserStore;
|
||||
71
src/stores/user/types.ts
Normal file
71
src/stores/user/types.ts
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import { District, Province, SubDistrict } from '../address';
|
||||
import { Status } from '../types';
|
||||
|
||||
export type User = {
|
||||
subDistrict: SubDistrict | null;
|
||||
district: District | null;
|
||||
province: Province | null;
|
||||
updatedAt: string;
|
||||
updateBy: string;
|
||||
createdAt: string;
|
||||
createdBy: string;
|
||||
status: Status;
|
||||
trainingPlace: string;
|
||||
importNationality: string;
|
||||
sourceNationality: string;
|
||||
licenseExpireDate: string;
|
||||
licenseIssueDate: string;
|
||||
licenseNo: string;
|
||||
discountCondition: string;
|
||||
userRole: string;
|
||||
userType: string;
|
||||
retireDate: string;
|
||||
startDate: string;
|
||||
registrationNo: string;
|
||||
telephoneNo: string;
|
||||
email: string;
|
||||
zipCode: string;
|
||||
subDistrictId: string | null;
|
||||
districtId: string | null;
|
||||
provinceId: string | null;
|
||||
addressEN: string;
|
||||
addressTH: string;
|
||||
lastNameEN: string;
|
||||
lastNameTH: string;
|
||||
firstNameEN: string;
|
||||
firstNameTH: string;
|
||||
code: string;
|
||||
keycloakId: string;
|
||||
id: string;
|
||||
profileImageUrl: string;
|
||||
};
|
||||
|
||||
export type UserCreate = {
|
||||
provinceId?: string | null;
|
||||
districtId?: string | null;
|
||||
subDistrictId?: string | null;
|
||||
telephoneNo: string;
|
||||
email: string;
|
||||
zipCode: string;
|
||||
addressEN: string;
|
||||
addressTH: string;
|
||||
trainingPlace: string;
|
||||
importNationality: string;
|
||||
sourceNationality: string;
|
||||
licenseExpireDate: Date;
|
||||
licenseIssueDate: Date;
|
||||
licenseNo: string;
|
||||
discountCondition: string;
|
||||
retireDate: Date;
|
||||
startDate: Date;
|
||||
registrationNo: string;
|
||||
code: string;
|
||||
lastNameEN: string;
|
||||
lastNameTH: string;
|
||||
firstNameEN: string;
|
||||
firstNameTH: string;
|
||||
userRole: string;
|
||||
userType: string;
|
||||
keycloakId: string;
|
||||
profileImage: File;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue