fix mode profileSalaryTemp to profileSalary
All checks were successful
Build & Deploy on Dev / build (push) Successful in 53s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 53s
This commit is contained in:
parent
631d634074
commit
af466df0d0
1 changed files with 35 additions and 29 deletions
|
|
@ -1298,8 +1298,8 @@ export class ProfileSalaryTempController extends Controller {
|
|||
const isOfficer = body.type.toUpperCase() === "OFFICER";
|
||||
|
||||
/* =========================
|
||||
* 1. Load Profile
|
||||
* ========================= */
|
||||
* 1. Load Profile
|
||||
* ========================= */
|
||||
const profile = isOfficer
|
||||
? await queryRunner.manager.findOne(Profile, { 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);
|
||||
|
||||
/* =========================
|
||||
* 2. Load Salary Temp
|
||||
* ========================= */
|
||||
* 2. Load Salary Temp
|
||||
* ========================= */
|
||||
const salaryTemps = await queryRunner.manager.find(ProfileSalaryTemp, {
|
||||
where: isOfficer
|
||||
? { profileId: body.profileId }
|
||||
: { profileEmployeeId: body.profileId },
|
||||
where: isOfficer ? { profileId: body.profileId } : { profileEmployeeId: body.profileId },
|
||||
});
|
||||
|
||||
if (salaryTemps.length === 0) {
|
||||
|
|
@ -1325,10 +1323,10 @@ export class ProfileSalaryTempController extends Controller {
|
|||
}
|
||||
|
||||
/* =========================
|
||||
* 3. Split Update / Insert
|
||||
* ========================= */
|
||||
const toUpdate = salaryTemps.filter(t => t.salaryId);
|
||||
const toInsert = salaryTemps.filter(t => !t.salaryId);
|
||||
* 3. Split Update / Insert
|
||||
* ========================= */
|
||||
// const toUpdate = salaryTemps.filter((t) => t.salaryId && t.isEdit && !t.isDelete);
|
||||
const toInsert = salaryTemps.filter((t) => !t.isDelete);
|
||||
const dateNow = new Date();
|
||||
const metaUpdate = {
|
||||
lastUpdateUserId: req.user.sub,
|
||||
|
|
@ -1336,24 +1334,34 @@ export class ProfileSalaryTempController extends Controller {
|
|||
lastUpdatedAt: dateNow,
|
||||
};
|
||||
|
||||
/* =========================
|
||||
* 4. UPDATE
|
||||
* ========================= */
|
||||
for (const temp of toUpdate) {
|
||||
const { id, salaryId, isDelete, isEdit, ...data } = temp;
|
||||
await queryRunner.manager.update(
|
||||
ProfileSalary,
|
||||
{ id: salaryId },
|
||||
{
|
||||
...data,
|
||||
...metaUpdate,
|
||||
},
|
||||
);
|
||||
}
|
||||
// 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 }),
|
||||
});
|
||||
|
||||
/* =========================
|
||||
* 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) {
|
||||
const metaCreate = {
|
||||
createdUserId: req.user.sub,
|
||||
|
|
@ -1371,7 +1379,6 @@ export class ProfileSalaryTempController extends Controller {
|
|||
|
||||
await queryRunner.commitTransaction();
|
||||
return new HttpSuccess();
|
||||
|
||||
} catch (error) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
throw error;
|
||||
|
|
@ -1380,7 +1387,6 @@ export class ProfileSalaryTempController extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* API แก้ไขข้อมูล
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue