feat: api endpoints employee
This commit is contained in:
parent
ba3bbd0ea7
commit
4772a6c90b
2 changed files with 238 additions and 0 deletions
147
src/stores/employee/index.ts
Normal file
147
src/stores/employee/index.ts
Normal file
|
|
@ -0,0 +1,147 @@
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { defineStore } from 'pinia';
|
||||||
|
import { Pagination } from '../types';
|
||||||
|
import { api } from 'src/boot/axios';
|
||||||
|
import { Employee, EmployeeCreate, EmployeeUpdate } from './types';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
const useCustomerStore = defineStore('api-employee', () => {
|
||||||
|
const data = ref<Pagination<Employee[]>>();
|
||||||
|
async function fetchList(
|
||||||
|
opts?: {
|
||||||
|
page?: number;
|
||||||
|
pageSize?: number;
|
||||||
|
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?.query) params.append('query', opts.query);
|
||||||
|
|
||||||
|
const query = params.toString();
|
||||||
|
|
||||||
|
const res = await api.get<Pagination<Employee[]>>(
|
||||||
|
`/customer${(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(
|
||||||
|
data: EmployeeCreate,
|
||||||
|
flow?: {
|
||||||
|
sessionId: string;
|
||||||
|
refTransactionId: string;
|
||||||
|
transactionId: string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const { image, ...payload } = data;
|
||||||
|
|
||||||
|
const res = await api.post<
|
||||||
|
Employee & { imageUrl: string; imageUploadUrl: string }
|
||||||
|
>('/customer', payload, {
|
||||||
|
headers: {
|
||||||
|
'X-Session-Id': flow?.sessionId,
|
||||||
|
'X-Rtid': flow?.refTransactionId,
|
||||||
|
'X-Tid': flow?.transactionId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await axios
|
||||||
|
.put(res.data.imageUploadUrl, image, {
|
||||||
|
headers: { 'Content-Type': image.type },
|
||||||
|
onUploadProgress: (e) => console.log(e),
|
||||||
|
})
|
||||||
|
.catch((e) => console.error(e));
|
||||||
|
|
||||||
|
if (!res) return false;
|
||||||
|
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function editById(
|
||||||
|
id: string,
|
||||||
|
data: EmployeeUpdate,
|
||||||
|
flow?: {
|
||||||
|
sessionId: string;
|
||||||
|
refTransactionId: string;
|
||||||
|
transactionId: string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const { image, ...payload } = data;
|
||||||
|
const res = await api.put<
|
||||||
|
Employee & { imageUrl: string; imageUploadUrl: string }
|
||||||
|
>(`/customer/${id}`, payload, {
|
||||||
|
headers: {
|
||||||
|
'X-Session-Id': flow?.sessionId,
|
||||||
|
'X-Rtid': flow?.refTransactionId,
|
||||||
|
'X-Tid': flow?.transactionId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (image)
|
||||||
|
await axios
|
||||||
|
.put(res.data.imageUploadUrl, image, {
|
||||||
|
headers: { 'Content-Type': image.type },
|
||||||
|
onUploadProgress: (e) => console.log(e),
|
||||||
|
})
|
||||||
|
.catch((e) => console.error(e));
|
||||||
|
|
||||||
|
if (!res) return false;
|
||||||
|
|
||||||
|
return res.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteById(
|
||||||
|
id: string,
|
||||||
|
flow?: {
|
||||||
|
sessionId: string;
|
||||||
|
refTransactionId: string;
|
||||||
|
transactionId: string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const res = await api.delete<Employee>(`/customer/${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;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
data,
|
||||||
|
|
||||||
|
fetchList,
|
||||||
|
create,
|
||||||
|
editById,
|
||||||
|
deleteById,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
export default useCustomerStore;
|
||||||
91
src/stores/employee/types.ts
Normal file
91
src/stores/employee/types.ts
Normal file
|
|
@ -0,0 +1,91 @@
|
||||||
|
import { District, Province, SubDistrict } from '../address';
|
||||||
|
import { Status } from '../types';
|
||||||
|
|
||||||
|
export type Employee = {
|
||||||
|
provinceId: string | null;
|
||||||
|
districtId: string | null;
|
||||||
|
subDistrictId: string | null;
|
||||||
|
subDistrict: SubDistrict | null;
|
||||||
|
district: District | null;
|
||||||
|
province: Province | null;
|
||||||
|
arrivalCardNo: string;
|
||||||
|
arrivalBarricade: string;
|
||||||
|
telephoneNo: string;
|
||||||
|
email: string;
|
||||||
|
zipCode: string;
|
||||||
|
address: string;
|
||||||
|
addressEN: string;
|
||||||
|
lastNameEN: string;
|
||||||
|
lastName: string;
|
||||||
|
firstNameEN: string;
|
||||||
|
firstName: string;
|
||||||
|
nationality: string;
|
||||||
|
gender: string;
|
||||||
|
dateOfBirth: string;
|
||||||
|
nrcNo: string;
|
||||||
|
code: string;
|
||||||
|
status: Status;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type EmployeeCreate = {
|
||||||
|
customerBranchId: string;
|
||||||
|
|
||||||
|
status?: Status;
|
||||||
|
|
||||||
|
code: string;
|
||||||
|
nrcNo: string;
|
||||||
|
|
||||||
|
dateOfBirth: Date;
|
||||||
|
gender: string;
|
||||||
|
nationality: string;
|
||||||
|
|
||||||
|
firstName: string;
|
||||||
|
firstNameEN: string;
|
||||||
|
lastName: string;
|
||||||
|
lastNameEN: string;
|
||||||
|
|
||||||
|
addressEN: string;
|
||||||
|
address: string;
|
||||||
|
zipCode: string;
|
||||||
|
email: string;
|
||||||
|
telephoneNo: string;
|
||||||
|
|
||||||
|
arrivalBarricade: string;
|
||||||
|
arrivalCardNo: string;
|
||||||
|
|
||||||
|
subDistrictId?: string | null;
|
||||||
|
districtId?: string | null;
|
||||||
|
provinceId?: string | null;
|
||||||
|
image: File;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type EmployeeUpdate = {
|
||||||
|
customerBranchId?: string;
|
||||||
|
status?: 'ACTIVE' | 'INACTIVE';
|
||||||
|
|
||||||
|
code?: string;
|
||||||
|
nrcNo?: string;
|
||||||
|
|
||||||
|
dateOfBirth?: Date;
|
||||||
|
gender?: string;
|
||||||
|
nationality?: string;
|
||||||
|
|
||||||
|
firstName?: string;
|
||||||
|
firstNameEN?: string;
|
||||||
|
lastName?: string;
|
||||||
|
lastNameEN?: string;
|
||||||
|
|
||||||
|
addressEN?: string;
|
||||||
|
address?: string;
|
||||||
|
zipCode?: string;
|
||||||
|
email?: string;
|
||||||
|
telephoneNo?: string;
|
||||||
|
|
||||||
|
arrivalBarricade?: string;
|
||||||
|
arrivalCardNo?: string;
|
||||||
|
|
||||||
|
subDistrictId?: string | null;
|
||||||
|
districtId?: string | null;
|
||||||
|
provinceId?: string | null;
|
||||||
|
image?: File;
|
||||||
|
};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue