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: '', districtId: '',
provinceId: '', provinceId: '',
employeeWork: [
{
workEndDate: null,
workPermitExpireDate: null,
workPermitIssuDate: null,
workPermitNo: '',
workplace: '',
jobType: '',
positionName: '',
ownerName: '',
remark: '',
},
],
employeeCheckup: [ employeeCheckup: [
{ {
coverageExpireDate: null, coverageExpireDate: null,
@ -689,6 +676,59 @@ export const useEmployeeForm = defineStore('form-employee', () => {
checkupType: '', 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: { employeeOtherInfo: {
citizenId: '', citizenId: '',
fatherFirstName: '', fatherFirstName: '',
@ -703,7 +743,6 @@ export const useEmployeeForm = defineStore('form-employee', () => {
motherLastNameEN: '', motherLastNameEN: '',
motherBirthPlace: '', motherBirthPlace: '',
}, },
image: null,
}; };
let resetEmployeeData = structuredClone(defaultFormData); let resetEmployeeData = structuredClone(defaultFormData);
@ -944,7 +983,7 @@ export const useEmployeeForm = defineStore('form-employee', () => {
updatedByUserId, updatedByUserId,
createdBy, createdBy,
updatedBy, updatedBy,
profileImageUrl,
...payload ...payload
} = _data; } = _data;
@ -1001,10 +1040,6 @@ export const useEmployeeForm = defineStore('form-employee', () => {
state.value.profileUrl = state.value.profileUrl =
`${baseUrl}/employee/${id}/image/${_data.selectedImage}` || ''; `${baseUrl}/employee/${id}/image/${_data.selectedImage}` || '';
profileImageUrl
? (state.value.profileSubmit = true)
: (state.value.profileSubmit = false);
state.value.formDataEmployeeOwner = { ...foundBranch }; state.value.formDataEmployeeOwner = { ...foundBranch };
if ( if (
@ -1019,11 +1054,9 @@ export const useEmployeeForm = defineStore('form-employee', () => {
if ( if (
state.value.infoEmployeePersonCard && state.value.infoEmployeePersonCard &&
Array.isArray(state.value.infoEmployeePersonCard) && Array.isArray(state.value.infoEmployeePersonCard) &&
state.value.infoEmployeePersonCard.length > 0 && state.value.infoEmployeePersonCard.length > 0
profileImageUrl !== null
) { ) {
if (typeof state.value.infoEmployeePersonCard[0] === 'object') { if (typeof state.value.infoEmployeePersonCard[0] === 'object') {
state.value.infoEmployeePersonCard[0].img = profileImageUrl;
} }
} }
flowStore.rotate(); flowStore.rotate();

View file

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

View file

@ -55,13 +55,30 @@ export type Employee = {
employeeWork?: EmployeeWorkCreate[]; employeeWork?: EmployeeWorkCreate[];
employeeCheckup?: EmployeeCheckupCreate[]; employeeCheckup?: EmployeeCheckupCreate[];
employeeOtherInfo?: EmployeeOtherCreate; 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 = { export type EmployeeCreate = {
selectedImage?: string; selectedImage?: string;
id?: string; id?: string;
code: string; code: string;
image: File | null;
customerBranchId: string; customerBranchId: string;
status?: Status; status?: Status;
nrcNo: string; nrcNo: string;
@ -86,9 +103,11 @@ export type EmployeeCreate = {
districtId?: string | null; districtId?: string | null;
provinceId?: string | null; provinceId?: string | null;
employeeWork?: EmployeeWorkCreate[];
employeeCheckup?: EmployeeCheckupCreate[]; employeeCheckup?: EmployeeCheckupCreate[];
employeeWork?: EmployeeWorkCreate[];
employeeInCountryNotice?: EmployeeInCountryNoticePayload[];
employeeVisa?: EmployeeVisaPayload[];
employeePassport?: EmployeePassportPayload[];
employeeOtherInfo?: EmployeeOtherCreate; employeeOtherInfo?: EmployeeOtherCreate;