From 9aa0a97a531babf191a7e7030cd4f23bfd33854f Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Fri, 6 Feb 2026 17:02:08 +0700 Subject: [PATCH] fix script --- .../ProfileSalaryTempController.ts | 37 ++++++++----------- src/entities/ProfileSalaryTemp.ts | 5 ++- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/controllers/ProfileSalaryTempController.ts b/src/controllers/ProfileSalaryTempController.ts index b85bc85b..40c0003c 100644 --- a/src/controllers/ProfileSalaryTempController.ts +++ b/src/controllers/ProfileSalaryTempController.ts @@ -1339,9 +1339,7 @@ export class ProfileSalaryTempController extends Controller { // add insert to profile salary backup const profileSalaryBeforeDelete = await queryRunner.manager.find(ProfileSalary, { where: { - ...(isOfficer - ? { profileId: body.profileId } - : { profileEmployeeId: body.profileId }), + ...(isOfficer ? { profileId: body.profileId } : { profileEmployeeId: body.profileId }), }, }); @@ -1350,7 +1348,7 @@ export class ProfileSalaryTempController extends Controller { queryRunner.manager.create(ProfileSalaryBackup, { ...salary, profileSalaryId: id, - }) + }), ); await queryRunner.manager.insert(ProfileSalaryBackup, backupRows); } @@ -1389,17 +1387,11 @@ export class ProfileSalaryTempController extends Controller { lastUpdatedAt: dateNow, }; - const salaryRows = toInsert.filter( - x => !["17", "18"].includes(x.commandCode) - ); - // ส่งไปรักษาการ - const actPositionRows = toInsert.filter( - x => x.commandCode === "17" - ); + const salaryRows = toInsert.filter((x) => !["17", "18"].includes(x.commandCode)); + // ส่งไปรักษาการ + const actPositionRows = toInsert.filter((x) => x.commandCode === "17"); // ส่งไปช่วยราชการ - const assistanceRows = toInsert.filter( - x => x.commandCode === "18" - ); + const assistanceRows = toInsert.filter((x) => x.commandCode === "18"); if (salaryRows.length) { await queryRunner.manager.insert( @@ -1407,14 +1399,14 @@ export class ProfileSalaryTempController extends Controller { salaryRows.map(({ id, ...data }) => ({ ...data, ...metaCreated, - })) + })), ); } - if (actPositionRows.length) { + if (actPositionRows.length > 0) { await queryRunner.manager.insert( ProfileActposition, - actPositionRows.map(x => ({ + actPositionRows.map((x) => ({ profileId: x.profileId, profileEmployeeId: x.profileEmployeeId, dateStart: x.commandDateAffect, @@ -1427,14 +1419,14 @@ export class ProfileSalaryTempController extends Controller { status: false, isDeleted: false, ...metaCreated, - })) + })), ); } - - if (assistanceRows.length) { + + if (assistanceRows.length > 0) { await queryRunner.manager.insert( ProfileAssistance, - assistanceRows.map(x => ({ + assistanceRows.map((x) => ({ profileId: x.profileId, profileEmployeeId: x.profileEmployeeId, agency: x.orgRoot, @@ -1448,7 +1440,7 @@ export class ProfileSalaryTempController extends Controller { status: "DONE", isUpload: false, ...metaCreated, - })) + })), ); } } @@ -1457,6 +1449,7 @@ export class ProfileSalaryTempController extends Controller { if (backupTemp.length > 0) { const insertBackupTemp = toInsert.map(({ id, ...data }) => ({ ...data, + salaryId: null, })); await queryRunner.manager.insert(ProfileSalaryTemp, insertBackupTemp); diff --git a/src/entities/ProfileSalaryTemp.ts b/src/entities/ProfileSalaryTemp.ts index 9b13d071..97e74ec7 100644 --- a/src/entities/ProfileSalaryTemp.ts +++ b/src/entities/ProfileSalaryTemp.ts @@ -273,8 +273,9 @@ export class ProfileSalaryTemp extends EntityBase { length: 40, comment: "คีย์นอก(FK)ของตาราง profileSalary", default: null, + type: "varchar", }) - salaryId: string; + salaryId: string | null; @Column({ nullable: true, @@ -292,7 +293,7 @@ export class ProfileSalaryTemp extends EntityBase { }) posNumCodeSitAbb: string; - @Column({ + @Column({ nullable: true, length: 255, comment: "ด้านทางการบริหาร",