no message

This commit is contained in:
Bright 2024-10-10 13:07:10 +07:00
parent e43c29dbc4
commit 8eb643c435

View file

@ -2039,13 +2039,13 @@ export class CommandController extends Controller {
body: { body: {
data: { data: {
bodyProfile: CreateProfileAllFields; bodyProfile: CreateProfileAllFields;
bodyEducations: CreateProfileEducation[]; bodyEducations?: CreateProfileEducation[];
bodyCertificates: CreateProfileCertificate[]; bodyCertificates?: CreateProfileCertificate[];
bodySalarys: CreateProfileSalary; bodySalarys?: CreateProfileSalary | null;
bodyPosition: { bodyPosition?: {
posmasterId: string; posmasterId: string;
positionId: string; positionId: string;
}; } | null;
}[]; }[];
}, },
) { ) {
@ -2101,109 +2101,119 @@ export class CommandController extends Controller {
await this.profileRepository.save(profile); await this.profileRepository.save(profile);
setLogDataDiff(req, { before, after: profile }); setLogDataDiff(req, { before, after: profile });
} }
if(profile && profile.id) { if(profile && profile.id) {
//Educations //Educations
await Promise.all( if(item.bodyEducations && item.bodyEducations.length > 0) {
item.bodyEducations.map(async (education) => { await Promise.all(
const profileEdu = new ProfileEducation(); item.bodyEducations.map(async (education) => {
Object.assign(profileEdu, { ...education, ...meta }); const profileEdu = new ProfileEducation();
const eduHistory = new ProfileEducationHistory(); Object.assign(profileEdu, { ...education, ...meta });
Object.assign(eduHistory, { ...profileEdu, id: undefined }); const eduHistory = new ProfileEducationHistory();
profileEdu.profileId = profile.id; Object.assign(eduHistory, { ...profileEdu, id: undefined });
await this.profileEducationRepo.save(profileEdu, { data: req }); profileEdu.profileId = profile.id;
setLogDataDiff(req, { before, after: profileEdu }); await this.profileEducationRepo.save(profileEdu, { data: req });
eduHistory.profileEducationId = profileEdu.id; setLogDataDiff(req, { before, after: profileEdu });
await this.profileEducationHistoryRepo.save(eduHistory, { data: req }); eduHistory.profileEducationId = profileEdu.id;
}), await this.profileEducationHistoryRepo.save(eduHistory, { data: req });
); }),
);
}
//Certificates //Certificates
await Promise.all( if(item.bodyCertificates && item.bodyCertificates.length > 0) {
item.bodyCertificates.map(async (cer) => { await Promise.all(
const profileCer = new ProfileCertificate(); item.bodyCertificates.map(async (cer) => {
Object.assign(profileCer, { ...cer, ...meta }); const profileCer = new ProfileCertificate();
const cerHistory = new ProfileCertificateHistory(); Object.assign(profileCer, { ...cer, ...meta });
Object.assign(cerHistory, { ...profileCer, id: undefined }); const cerHistory = new ProfileCertificateHistory();
profileCer.profileId = profile.id Object.assign(cerHistory, { ...profileCer, id: undefined });
await this.certificateRepo.save(profileCer, { data: req }); profileCer.profileId = profile.id
setLogDataDiff(req, { before, after: profileCer }); await this.certificateRepo.save(profileCer, { data: req });
cerHistory.profileCertificateId = profileCer.id; setLogDataDiff(req, { before, after: profileCer });
await this.certificateHistoryRepo.save(cerHistory, { data: req }); cerHistory.profileCertificateId = profileCer.id;
}), await this.certificateHistoryRepo.save(cerHistory, { data: req });
); }),
);
}
//Salary //Salary
const dest_item = await this.salaryRepo.findOne({ if(item.bodySalarys && item.bodySalarys != null) {
where: { profileId: profile.id }, const dest_item = await this.salaryRepo.findOne({
order: { order: "DESC" }, where: { profileId: profile.id },
}); order: { order: "DESC" },
const profileSal = new ProfileSalary(); });
Object.assign(profileSal, { ...item.bodySalarys, ...meta }); const profileSal = new ProfileSalary();
const salaryHistory = new ProfileSalaryHistory(); Object.assign(profileSal, { ...item.bodySalarys, ...meta });
Object.assign(salaryHistory, { ...profileSal, id: undefined }); const salaryHistory = new ProfileSalaryHistory();
profileSal.order = dest_item == null ? 1 : dest_item.order + 1, Object.assign(salaryHistory, { ...profileSal, id: undefined });
profileSal.profileId = profile.id profileSal.order = dest_item == null ? 1 : dest_item.order + 1,
await this.salaryRepo.save(profileSal, { data: req }); profileSal.profileId = profile.id
setLogDataDiff(req, { before, after: profileSal }); await this.salaryRepo.save(profileSal, { data: req });
salaryHistory.profileSalaryId = profileSal.id; setLogDataDiff(req, { before, after: profileSal });
await this.salaryHistoryRepo.save(salaryHistory, { data: req }); salaryHistory.profileSalaryId = profileSal.id;
await this.salaryHistoryRepo.save(salaryHistory, { data: req });
}
//Position //Position
const posMaster = await this.posMasterRepository.findOne({ if(item.bodyPosition && item.bodyPosition != null) {
where: { id: item.bodyPosition.posmasterId }, const posMaster = await this.posMasterRepository.findOne({
}); where: { id: item.bodyPosition.posmasterId },
if (posMaster == null) });
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); if (posMaster == null)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
const posMasterOld = await this.posMasterRepository.findOne({
where: { const posMasterOld = await this.posMasterRepository.findOne({
current_holderId: profile.id, where: {
orgRevisionId: posMaster.orgRevisionId, current_holderId: profile.id,
}, orgRevisionId: posMaster.orgRevisionId,
}); },
if (posMasterOld != null) posMasterOld.current_holderId = null; });
if (posMasterOld != null) posMasterOld.current_holderId = null;
const positionOld = await this.positionRepository.findOne({
where: { const positionOld = await this.positionRepository.findOne({
posMasterId: posMasterOld?.id, where: {
positionIsSelected: true, posMasterId: posMasterOld?.id,
}, positionIsSelected: true,
}); },
if (positionOld != null) { });
positionOld.positionIsSelected = false; if (positionOld != null) {
await this.positionRepository.save(positionOld); positionOld.positionIsSelected = false;
} await this.positionRepository.save(positionOld);
}
const checkPosition = await this.positionRepository.find({
where: { const checkPosition = await this.positionRepository.find({
posMasterId: item.bodyPosition.posmasterId, where: {
positionIsSelected: true, posMasterId: item.bodyPosition.posmasterId,
}, positionIsSelected: true,
}); },
if (checkPosition.length > 0) { });
const clearPosition = checkPosition.map((positions) => ({ if (checkPosition.length > 0) {
...positions, const clearPosition = checkPosition.map((positions) => ({
positionIsSelected: false, ...positions,
})); positionIsSelected: false,
await this.positionRepository.save(clearPosition); }));
} await this.positionRepository.save(clearPosition);
}
posMaster.current_holderId = profile.id;
if (posMasterOld != null) await this.posMasterRepository.save(posMasterOld); posMaster.current_holderId = profile.id;
await this.posMasterRepository.save(posMaster); if (posMasterOld != null) await this.posMasterRepository.save(posMasterOld);
await this.posMasterRepository.save(posMaster);
const positionNew = await this.positionRepository.findOne({
where: { const positionNew = await this.positionRepository.findOne({
id: item.bodyPosition.positionId, where: {
posMasterId: item.bodyPosition.posmasterId, id: item.bodyPosition.positionId,
}, posMasterId: item.bodyPosition.posmasterId,
}); },
if (positionNew != null) { });
positionNew.positionIsSelected = true; if (positionNew != null) {
profile.posLevelId = positionNew.posLevelId; positionNew.positionIsSelected = true;
profile.posTypeId = positionNew.posTypeId; profile.posLevelId = positionNew.posLevelId;
profile.position = positionNew.positionName; profile.posTypeId = positionNew.posTypeId;
await this.profileRepository.save(profile, { data: req }); profile.position = positionNew.positionName;
setLogDataDiff(req, { before, after: profile }); await this.profileRepository.save(profile, { data: req });
await this.positionRepository.save(positionNew, { data: req }); setLogDataDiff(req, { before, after: profile });
await this.positionRepository.save(positionNew, { data: req });
}
} }
} }
}), }),