fix mode profileSalaryTemp to profileSalary
All checks were successful
Build & Deploy on Dev / build (push) Successful in 53s

This commit is contained in:
Warunee Tamkoo 2026-02-05 16:46:32 +07:00
parent 631d634074
commit af466df0d0

View file

@ -1298,8 +1298,8 @@ export class ProfileSalaryTempController extends Controller {
const isOfficer = body.type.toUpperCase() === "OFFICER"; const isOfficer = body.type.toUpperCase() === "OFFICER";
/* ========================= /* =========================
* 1. Load Profile * 1. Load Profile
* ========================= */ * ========================= */
const profile = isOfficer const profile = isOfficer
? await queryRunner.manager.findOne(Profile, { where: { id: body.profileId } }) ? await queryRunner.manager.findOne(Profile, { where: { id: body.profileId } })
: await queryRunner.manager.findOne(ProfileEmployee, { where: { id: body.profileId } }); : await queryRunner.manager.findOne(ProfileEmployee, { where: { id: body.profileId } });
@ -1312,12 +1312,10 @@ export class ProfileSalaryTempController extends Controller {
await queryRunner.manager.save(profile); await queryRunner.manager.save(profile);
/* ========================= /* =========================
* 2. Load Salary Temp * 2. Load Salary Temp
* ========================= */ * ========================= */
const salaryTemps = await queryRunner.manager.find(ProfileSalaryTemp, { const salaryTemps = await queryRunner.manager.find(ProfileSalaryTemp, {
where: isOfficer where: isOfficer ? { profileId: body.profileId } : { profileEmployeeId: body.profileId },
? { profileId: body.profileId }
: { profileEmployeeId: body.profileId },
}); });
if (salaryTemps.length === 0) { if (salaryTemps.length === 0) {
@ -1325,10 +1323,10 @@ export class ProfileSalaryTempController extends Controller {
} }
/* ========================= /* =========================
* 3. Split Update / Insert * 3. Split Update / Insert
* ========================= */ * ========================= */
const toUpdate = salaryTemps.filter(t => t.salaryId); // const toUpdate = salaryTemps.filter((t) => t.salaryId && t.isEdit && !t.isDelete);
const toInsert = salaryTemps.filter(t => !t.salaryId); const toInsert = salaryTemps.filter((t) => !t.isDelete);
const dateNow = new Date(); const dateNow = new Date();
const metaUpdate = { const metaUpdate = {
lastUpdateUserId: req.user.sub, lastUpdateUserId: req.user.sub,
@ -1336,24 +1334,34 @@ export class ProfileSalaryTempController extends Controller {
lastUpdatedAt: dateNow, lastUpdatedAt: dateNow,
}; };
/* ========================= // delete profile salary temp
* 4. UPDATE await queryRunner.manager.delete(ProfileSalaryTemp, {
* ========================= */ ...(isOfficer ? { profileId: body.profileId } : { profileEmployeeId: body.profileId }),
for (const temp of toUpdate) { });
const { id, salaryId, isDelete, isEdit, ...data } = temp;
await queryRunner.manager.update( // delete profile salary
ProfileSalary, await queryRunner.manager.delete(ProfileSalary, {
{ id: salaryId }, ...(isOfficer ? { profileId: body.profileId } : { profileEmployeeId: body.profileId }),
{ });
...data,
...metaUpdate,
},
);
}
/* ========================= /* =========================
* 5. INSERT (bulk) * 4. UPDATE
* ========================= */ * ========================= */
// for (const temp of toUpdate) {
// const { id, salaryId, isDelete, isEdit, ...data } = temp;
// await queryRunner.manager.update(
// ProfileSalary,
// { id: salaryId },
// {
// ...data,
// ...metaUpdate,
// },
// );
// }
/* =========================
* 5. INSERT (bulk)
* ========================= */
if (toInsert.length > 0) { if (toInsert.length > 0) {
const metaCreate = { const metaCreate = {
createdUserId: req.user.sub, createdUserId: req.user.sub,
@ -1371,7 +1379,6 @@ export class ProfileSalaryTempController extends Controller {
await queryRunner.commitTransaction(); await queryRunner.commitTransaction();
return new HttpSuccess(); return new HttpSuccess();
} catch (error) { } catch (error) {
await queryRunner.rollbackTransaction(); await queryRunner.rollbackTransaction();
throw error; throw error;
@ -1380,7 +1387,6 @@ export class ProfileSalaryTempController extends Controller {
} }
} }
/** /**
* API * API
* *