diff --git a/src/controllers/OrganizationDotnetController.ts b/src/controllers/OrganizationDotnetController.ts index 79cd5d93..638eb57e 100644 --- a/src/controllers/OrganizationDotnetController.ts +++ b/src/controllers/OrganizationDotnetController.ts @@ -26,6 +26,7 @@ import { Position } from "../entities/Position"; import { Insignia } from "../entities/Insignia"; import { CreateProfileInsignia, ProfileInsignia } from "../entities/ProfileInsignia"; import { PosMaster } from "../entities/PosMaster"; +import { EmployeePosDict } from "../entities/EmployeePosDict"; @Route("api/v1/org/dotnet") @Tags("Dotnet") @@ -43,6 +44,7 @@ export class OrganizationDotnetController extends Controller { private positionRepository = AppDataSource.getRepository(Position); private posMasterRepository = AppDataSource.getRepository(PosMaster); private insigniaRepo = AppDataSource.getRepository(ProfileInsignia); + private employeePosDictRepository = AppDataSource.getRepository(EmployeePosDict); /** * 1. API Search Profile @@ -2366,11 +2368,15 @@ export class OrganizationDotnetController extends Controller { @Body() body: { empPosId: string[]; + rootId: string; }, ) { const findRevision = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true }, }); + const employeePosDict = await this.employeePosDictRepository.find({ + where: { id: In(body.empPosId) }, + }); const profiles = await this.profileEmpRepo.find({ relations: [ @@ -2387,12 +2393,12 @@ export class OrganizationDotnetController extends Controller { "current_holders.orgChild3", "current_holders.orgChild4", ], - where: { - current_holders: { - positions: { id: In(body.empPosId), positionIsSelected: true }, - orgRevisionId: findRevision?.id, - }, - }, + where: employeePosDict.map((entry) => ({ + posLevelId: entry.posLevelId, + posTypeId: entry.posTypeId, + position: entry.posDictName, + current_holders: { orgRootId: body.rootId }, + })), order: { profileSalary: { date: "DESC", diff --git a/src/entities/ProfileActposition.ts b/src/entities/ProfileActposition.ts index 740c8b44..dd95a458 100644 --- a/src/entities/ProfileActposition.ts +++ b/src/entities/ProfileActposition.ts @@ -45,11 +45,10 @@ export class ProfileActposition extends EntityBase { position: string; @Column({ - nullable: true, comment: "สถานะ", - default: null, + default: false, }) - status: string; + status: boolean; @Column({ nullable: true, @@ -80,7 +79,7 @@ export class CreateProfileActposition { dateEnd: Date | null; posNo: string | null; position: string | null; - status: string | null; + status: boolean; } export class CreateProfileActpositionEmployee { @@ -89,7 +88,7 @@ export class CreateProfileActpositionEmployee { dateEnd: Date | null; posNo: string | null; position: string | null; - status: string | null; + status: boolean; } export type UpdateProfileActposition = { @@ -97,5 +96,5 @@ export type UpdateProfileActposition = { dateEnd?: Date | null; posNo?: string | null; position?: string | null; - status?: string | null; + status: boolean; }; diff --git a/src/entities/ProfileActpositionHistory.ts b/src/entities/ProfileActpositionHistory.ts index 64582dcb..bb2034e7 100644 --- a/src/entities/ProfileActpositionHistory.ts +++ b/src/entities/ProfileActpositionHistory.ts @@ -35,11 +35,10 @@ export class ProfileActpositionHistory extends EntityBase { position: string; @Column({ - nullable: true, comment: "สถานะ", - default: null, + default: false, }) - status: string; + status: boolean; @Column({ nullable: true, diff --git a/src/migration/1737948097408-UpdateprofileActpositionaddstatus.ts b/src/migration/1737948097408-UpdateprofileActpositionaddstatus.ts new file mode 100644 index 00000000..e559ce25 --- /dev/null +++ b/src/migration/1737948097408-UpdateprofileActpositionaddstatus.ts @@ -0,0 +1,20 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateprofileActpositionaddstatus1737948097408 implements MigrationInterface { + name = 'UpdateprofileActpositionaddstatus1737948097408' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileActpositionHistory\` DROP COLUMN \`status\``); + await queryRunner.query(`ALTER TABLE \`profileActpositionHistory\` ADD \`status\` tinyint NOT NULL COMMENT 'สถานะ' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`profileActposition\` DROP COLUMN \`status\``); + await queryRunner.query(`ALTER TABLE \`profileActposition\` ADD \`status\` tinyint NOT NULL COMMENT 'สถานะ' DEFAULT 0`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`profileActposition\` DROP COLUMN \`status\``); + await queryRunner.query(`ALTER TABLE \`profileActposition\` ADD \`status\` varchar(255) NULL COMMENT 'สถานะ'`); + await queryRunner.query(`ALTER TABLE \`profileActpositionHistory\` DROP COLUMN \`status\``); + await queryRunner.query(`ALTER TABLE \`profileActpositionHistory\` ADD \`status\` varchar(255) NULL COMMENT 'สถานะ'`); + } + +}