fix: Unable to edit employee information

This commit is contained in:
Net 2024-09-26 14:03:49 +07:00
parent 828eab36f2
commit d77bd3250b
3 changed files with 90 additions and 36 deletions

View file

@ -663,19 +663,6 @@ export const useEmployeeForm = defineStore('form-employee', () => {
districtId: '',
provinceId: '',
employeeWork: [
{
workEndDate: null,
workPermitExpireDate: null,
workPermitIssuDate: null,
workPermitNo: '',
workplace: '',
jobType: '',
positionName: '',
ownerName: '',
remark: '',
},
],
employeeCheckup: [
{
coverageExpireDate: null,
@ -689,6 +676,59 @@ export const useEmployeeForm = defineStore('form-employee', () => {
checkupType: '',
},
],
employeeWork: [
{
workEndDate: null,
workPermitExpireDate: null,
workPermitIssuDate: null,
workPermitNo: '',
workplace: '',
jobType: '',
positionName: '',
ownerName: '',
remark: '',
},
],
employeeInCountryNotice: [
{
noticeNumber: '',
noticeDate: '',
nextNoticeDate: new Date(),
tmNumber: '',
entryDate: new Date(),
travelBy: '',
travelFrom: '',
},
],
employeeVisa: [
{
number: '',
type: '',
entryCount: 0,
issueCountry: '',
issuePlace: '',
issueDate: new Date(),
expireDate: new Date(),
mrz: '',
remark: '',
},
],
employeePassport: [
{
number: '',
type: '',
issueDate: new Date(),
expireDate: new Date(),
issueCountry: '',
issuePlace: '',
previousPassportRef: '',
},
],
employeeOtherInfo: {
citizenId: '',
fatherFirstName: '',
@ -703,7 +743,6 @@ export const useEmployeeForm = defineStore('form-employee', () => {
motherLastNameEN: '',
motherBirthPlace: '',
},
image: null,
};
let resetEmployeeData = structuredClone(defaultFormData);
@ -944,7 +983,7 @@ export const useEmployeeForm = defineStore('form-employee', () => {
updatedByUserId,
createdBy,
updatedBy,
profileImageUrl,
...payload
} = _data;
@ -1001,10 +1040,6 @@ export const useEmployeeForm = defineStore('form-employee', () => {
state.value.profileUrl =
`${baseUrl}/employee/${id}/image/${_data.selectedImage}` || '';
profileImageUrl
? (state.value.profileSubmit = true)
: (state.value.profileSubmit = false);
state.value.formDataEmployeeOwner = { ...foundBranch };
if (
@ -1019,11 +1054,9 @@ export const useEmployeeForm = defineStore('form-employee', () => {
if (
state.value.infoEmployeePersonCard &&
Array.isArray(state.value.infoEmployeePersonCard) &&
state.value.infoEmployeePersonCard.length > 0 &&
profileImageUrl !== null
state.value.infoEmployeePersonCard.length > 0
) {
if (typeof state.value.infoEmployeePersonCard[0] === 'object') {
state.value.infoEmployeePersonCard[0].img = profileImageUrl;
}
}
flowStore.rotate();

View file

@ -132,11 +132,9 @@ const useEmployeeStore = defineStore('api-employee', () => {
list: { url: string; imgFile: File | null; name: string }[];
},
) {
console.log(data);
const {
id,
code,
image,
file,
zipCode,
employeeWork,
@ -303,6 +301,7 @@ const useEmployeeStore = defineStore('api-employee', () => {
createdByUserId,
createdAt,
employeeId,
...payload
} = data;
const res = await api.put<EmployeeOtherCreate>(
@ -317,7 +316,18 @@ const useEmployeeStore = defineStore('api-employee', () => {
}
async function editById(employeeId: string, data: Partial<EmployeeCreate>) {
const { id, code, image, file, ...payload } = data;
const {
id,
code,
file,
employeeCheckup,
employeeWork,
employeeInCountryNotice,
employeeVisa,
employeePassport,
...payload
} = data;
const res = await api.put<
Employee & { imageUrl: string; profileImageUploadUrl: string }
>(`/employee/${employeeId}`, payload, {
@ -326,14 +336,6 @@ const useEmployeeStore = defineStore('api-employee', () => {
if (!res) return false;
if (image) {
await api
.put(`/employee/${employeeId}/image`, image, {
headers: { 'Content-Type': image?.type },
onUploadProgress: (e) => console.log(e),
})
.catch((e) => console.error(e));
}
if (file) {
const attachmentUpload = file.map(async ({ group, file }) => {
if (file) {

View file

@ -55,13 +55,30 @@ export type Employee = {
employeeWork?: EmployeeWorkCreate[];
employeeCheckup?: EmployeeCheckupCreate[];
employeeOtherInfo?: EmployeeOtherCreate;
employeeInCountryNotice?: (EmployeeInCountryNoticePayload & {
id: string;
updatedAt: Date;
createdAt: Date;
employeeId: string;
})[];
employeeVisa?: (EmployeeVisaPayload & {
id: string;
updatedAt: Date;
createdAt: Date;
employeeId: string;
})[];
employeePassport?: EmployeePassportPayload & {
id: string;
updatedAt: Date;
createdAt: Date;
employeeId: string;
};
};
export type EmployeeCreate = {
selectedImage?: string;
id?: string;
code: string;
image: File | null;
customerBranchId: string;
status?: Status;
nrcNo: string;
@ -86,9 +103,11 @@ export type EmployeeCreate = {
districtId?: string | null;
provinceId?: string | null;
employeeWork?: EmployeeWorkCreate[];
employeeCheckup?: EmployeeCheckupCreate[];
employeeWork?: EmployeeWorkCreate[];
employeeInCountryNotice?: EmployeeInCountryNoticePayload[];
employeeVisa?: EmployeeVisaPayload[];
employeePassport?: EmployeePassportPayload[];
employeeOtherInfo?: EmployeeOtherCreate;