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

@ -1315,9 +1315,7 @@ export class ProfileSalaryTempController extends Controller {
* 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) {
@ -1327,8 +1325,8 @@ 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,20 +1334,30 @@ export class ProfileSalaryTempController extends Controller {
lastUpdatedAt: dateNow, lastUpdatedAt: dateNow,
}; };
// delete profile salary temp
await queryRunner.manager.delete(ProfileSalaryTemp, {
...(isOfficer ? { profileId: body.profileId } : { profileEmployeeId: body.profileId }),
});
// delete profile salary
await queryRunner.manager.delete(ProfileSalary, {
...(isOfficer ? { profileId: body.profileId } : { profileEmployeeId: body.profileId }),
});
/* ========================= /* =========================
* 4. UPDATE * 4. UPDATE
* ========================= */ * ========================= */
for (const temp of toUpdate) { // for (const temp of toUpdate) {
const { id, salaryId, isDelete, isEdit, ...data } = temp; // const { id, salaryId, isDelete, isEdit, ...data } = temp;
await queryRunner.manager.update( // await queryRunner.manager.update(
ProfileSalary, // ProfileSalary,
{ id: salaryId }, // { id: salaryId },
{ // {
...data, // ...data,
...metaUpdate, // ...metaUpdate,
}, // },
); // );
} // }
/* ========================= /* =========================
* 5. INSERT (bulk) * 5. INSERT (bulk)
@ -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
* *