From d3aa76b3f8a1eaa8a803c6290f6acc3a03610faa Mon Sep 17 00:00:00 2001 From: kittapath Date: Mon, 16 Sep 2024 15:15:59 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=99=E0=B8=9A=E0=B9=84=E0=B8=9F?= =?UTF-8?q?=E0=B8=A5=E0=B9=8C=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88?= =?UTF-8?q?=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/CommandSalaryController.ts | 4 +- src/controllers/CommandTypeController.ts | 62 ++++++++++++++++++- src/controllers/ImportDataController.ts | 6 +- src/entities/CommandType.ts | 16 +++++ src/entities/HR_POSITION_OFFICER.ts | 7 +++ .../1726474393379-add_CommandSalary.ts | 18 ++++++ 6 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 src/migration/1726474393379-add_CommandSalary.ts diff --git a/src/controllers/CommandSalaryController.ts b/src/controllers/CommandSalaryController.ts index 19bd8381..c5002f29 100644 --- a/src/controllers/CommandSalaryController.ts +++ b/src/controllers/CommandSalaryController.ts @@ -41,9 +41,9 @@ export class CommandSalaryController extends Controller { * */ @Get("list") - async Get() { + async Get(@Query() commandSysId: string) { const _commandSalary = await this.commandSalaryRepository.find({ - where: { isActive: true }, + where: { isActive: true, commandSysId: commandSysId }, select: [ "id", "name", diff --git a/src/controllers/CommandTypeController.ts b/src/controllers/CommandTypeController.ts index 8a39a9f7..5342c73a 100644 --- a/src/controllers/CommandTypeController.ts +++ b/src/controllers/CommandTypeController.ts @@ -49,6 +49,8 @@ export class CommandTypeController extends Controller { "name", "commandSysId", "code", + "fileCover", + "fileAttachment", "detailHeader", "detailBody", "detailFooter", @@ -57,7 +59,7 @@ export class CommandTypeController extends Controller { "createdFullName", "lastUpdateFullName", ], - order: { name: "ASC" }, + order: { createdAt: "ASC" }, }); return new HttpSuccess(_commandType); } @@ -83,7 +85,7 @@ export class CommandTypeController extends Controller { isActive == null || isActive == undefined ? null : `${isActive == true ? 1 : 0}`, }, ) - .orderBy("commandType.name", "ASC") + .orderBy("commandType.createdAt", "ASC") .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); @@ -106,6 +108,8 @@ export class CommandTypeController extends Controller { "name", "commandSysId", "code", + "fileCover", + "fileAttachment", "isActive", "detailHeader", "detailBody", @@ -229,6 +233,60 @@ export class CommandTypeController extends Controller { return new HttpSuccess(_commandType.id); } + /** + * API แก้ไขรายการ body ประเภทคำสั่ง + * + * @summary ORG_056 - CRUD ประเภทคำสั่ง (ADMIN) #61 + * + * @param {string} id Id ประเภทคำสั่ง + */ + @Put("cover/{id}") + async PutCover( + @Path() id: string, + @Body() + requestBody: { name: string }, + @Request() request: { user: Record }, + ) { + const _commandType = await this.commandTypeRepository.findOne({ where: { id: id } }); + if (!_commandType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทคำสั่งชื่อนี้"); + } + _commandType.fileCover = requestBody.name; + _commandType.lastUpdateUserId = request.user.sub; + _commandType.lastUpdateFullName = request.user.name; + _commandType.lastUpdatedAt = new Date(); + this.commandTypeRepository.merge(_commandType, requestBody); + await this.commandTypeRepository.save(_commandType); + return new HttpSuccess(_commandType.id); + } + + /** + * API แก้ไขรายการ body ประเภทคำสั่ง + * + * @summary ORG_056 - CRUD ประเภทคำสั่ง (ADMIN) #61 + * + * @param {string} id Id ประเภทคำสั่ง + */ + @Put("attachment/{id}") + async PutAttachment( + @Path() id: string, + @Body() + requestBody: { name: string }, + @Request() request: { user: Record }, + ) { + const _commandType = await this.commandTypeRepository.findOne({ where: { id: id } }); + if (!_commandType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทคำสั่งชื่อนี้"); + } + _commandType.fileAttachment = requestBody.name; + _commandType.lastUpdateUserId = request.user.sub; + _commandType.lastUpdateFullName = request.user.name; + _commandType.lastUpdatedAt = new Date(); + this.commandTypeRepository.merge(_commandType, requestBody); + await this.commandTypeRepository.save(_commandType); + return new HttpSuccess(_commandType.id); + } + /** * API ลบรายการประเภทคำสั่ง * diff --git a/src/controllers/ImportDataController.ts b/src/controllers/ImportDataController.ts index 15b406f6..e595cebd 100644 --- a/src/controllers/ImportDataController.ts +++ b/src/controllers/ImportDataController.ts @@ -296,7 +296,7 @@ export class ImportDataController extends Controller { await Promise.all( profiles.map(async (_item) => { const existingProfile = await this.HR_POSITION_OFFICERRepo.find({ - where: { CIT: _item.citizenId }, + where: { CIT: _item.citizenId, FLAG_PERSON_TYPE: "1" }, select: [ "CIT", "MP_POS_DATE", @@ -319,7 +319,9 @@ export class ImportDataController extends Controller { rowCount++; const profileSalary = new ProfileSalary(); profileSalary.date = - item.MP_POS_DATE == "" ? null_ : Extension.ConvertToDateTimeV2(item.MP_POS_DATE); + item.MP_POS_DATE == "" + ? null_ + : new Date(item.MP_POS_DATE.replace(" +0700 +07:00", "")); const SALARY: any = item.SALARY == null || item.SALARY == "" ? null_ : Number(item.SALARY); profileSalary.amount = SALARY; diff --git a/src/entities/CommandType.ts b/src/entities/CommandType.ts index d5d67529..8013d99d 100644 --- a/src/entities/CommandType.ts +++ b/src/entities/CommandType.ts @@ -21,6 +21,22 @@ export class CommandType extends EntityBase { }) code: string; + @Column({ + nullable: true, + comment: "คำสั่งเรื่อง", + length: 255, + default: null, + }) + fileCover: string; + + @Column({ + nullable: true, + comment: "คำสั่งเรื่อง", + length: 255, + default: null, + }) + fileAttachment: string; + @Column({ nullable: true, comment: "เนื้อหาคำสั่งส่วนต้น", diff --git a/src/entities/HR_POSITION_OFFICER.ts b/src/entities/HR_POSITION_OFFICER.ts index 622145a3..8e8ff97d 100644 --- a/src/entities/HR_POSITION_OFFICER.ts +++ b/src/entities/HR_POSITION_OFFICER.ts @@ -11,6 +11,13 @@ export class HR_POSITION_OFFICER { @PrimaryGeneratedColumn() id!: number; + @Column({ + nullable: true, + type: "text", + default: null, + }) + FLAG_PERSON_TYPE: string; + @Column({ nullable: true, type: "text", diff --git a/src/migration/1726474393379-add_CommandSalary.ts b/src/migration/1726474393379-add_CommandSalary.ts new file mode 100644 index 00000000..fd495e12 --- /dev/null +++ b/src/migration/1726474393379-add_CommandSalary.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddCommandSalary1726474393379 implements MigrationInterface { + name = 'AddCommandSalary1726474393379' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`commandType\` ADD \`fileCover\` varchar(255) NULL COMMENT 'คำสั่งเรื่อง'`); + await queryRunner.query(`ALTER TABLE \`commandType\` ADD \`fileAttachment\` varchar(255) NULL COMMENT 'คำสั่งเรื่อง'`); + // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` ADD \`FLAG_PERSON_TYPE\` text NULL`); + } + + public async down(queryRunner: QueryRunner): Promise { + // await queryRunner.query(`ALTER TABLE \`HR_POSITION_OFFICER\` DROP COLUMN \`FLAG_PERSON_TYPE\``); + await queryRunner.query(`ALTER TABLE \`commandType\` DROP COLUMN \`fileAttachment\``); + await queryRunner.query(`ALTER TABLE \`commandType\` DROP COLUMN \`fileCover\``); + } + +}