diff --git a/src/controllers/OrganizationController.ts b/src/controllers/OrganizationController.ts index 5eeffbd7..7e26110b 100644 --- a/src/controllers/OrganizationController.ts +++ b/src/controllers/OrganizationController.ts @@ -688,12 +688,18 @@ export class OrganizationController extends Controller { * @summary ORG_039 - ประวัติหน่วยงาน (ADMIN) #42 * */ - @Get("/history/publish") - async GetHistoryPublish(@Query("id") id: string, @Query("type") type: number = 1) { - const _data = new Array(); - if (type == 1) { + @Post("/history/publish") + async GetHistoryPublish( + @Body() + requestBody: { + id: string; + type: number; + }, + @Request() request: { user: Record }, + ) { + if (requestBody.type == 1) { const orgChild1 = await this.child1Repository.findOne({ - where: { id: id }, + where: { id: requestBody.id }, }); if (!orgChild1) { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child1"); @@ -710,9 +716,9 @@ export class OrganizationController extends Controller { lastUpdatedAt: item.lastUpdatedAt, })); return new HttpSuccess(_data); - } else if (type == 2) { + } else if (requestBody.type == 2) { const orgChild2 = await this.child2Repository.findOne({ - where: { id: id }, + where: { id: requestBody.id }, }); if (!orgChild2) { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child2"); @@ -729,9 +735,9 @@ export class OrganizationController extends Controller { lastUpdatedAt: item.lastUpdatedAt, })); return new HttpSuccess(_data); - } else if (type == 3) { + } else if (requestBody.type == 3) { const orgChild3 = await this.child3Repository.findOne({ - where: { id: id }, + where: { id: requestBody.id }, }); if (!orgChild3) { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child3"); @@ -748,9 +754,9 @@ export class OrganizationController extends Controller { lastUpdatedAt: item.lastUpdatedAt, })); return new HttpSuccess(_data); - } else if (type == 4) { + } else if (requestBody.type == 4) { const orgChild4 = await this.child4Repository.findOne({ - where: { id: id }, + where: { id: requestBody.id }, }); if (!orgChild4) { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child4"); @@ -769,7 +775,7 @@ export class OrganizationController extends Controller { return new HttpSuccess(_data); } else { const orgRoot = await this.orgRootRepository.findOne({ - where: { id: id }, + where: { id: requestBody.id }, }); if (!orgRoot) { throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Root"); diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 3be43dca..2b9e7dc5 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -505,7 +505,7 @@ export class PositionController extends Controller { @Put("master/{id}") @Example({ posMasterNoPrefix: "กบ.", - posMasterNo: 1, + posMasterNo: "1", posMasterNoSuffix: "ช", posId: ["08db9e81-fc46-4e95-8b33-be4ca0016abf", "08db9e81-fc46-4e95-8b33-be4ca0016abf"], orgRootId: "08db9e81-fc46-4e95-8b33-be4ca0016abf", diff --git a/src/entities/PosMaster.ts b/src/entities/PosMaster.ts index 674860c1..26ab4376 100644 --- a/src/entities/PosMaster.ts +++ b/src/entities/PosMaster.ts @@ -79,37 +79,37 @@ export class PosMaster extends EntityBase { @Column({ nullable: true, length: 40, - default: "00000000-0000-0000-0000-000000000000", + default: null, }) - orgRootId: string; + orgRootId?: string; @Column({ nullable: true, length: 40, - default: "00000000-0000-0000-0000-000000000000", + default: null, }) - orgChild1Id: string; + orgChild1Id?: string; @Column({ nullable: true, length: 40, - default: "00000000-0000-0000-0000-000000000000", + default: null, }) - orgChild2Id: string; + orgChild2Id?: string; @Column({ nullable: true, length: 40, - default: "00000000-0000-0000-0000-000000000000", + default: null, }) - orgChild3Id: string; + orgChild3Id?: string; @Column({ nullable: true, length: 40, - default: "00000000-0000-0000-0000-000000000000", + default: null, }) - orgChild4Id: string; + orgChild4Id?: string; @Column({ nullable: true, diff --git a/src/migration/1706696231054-add_table_posMaster2.ts b/src/migration/1706696231054-add_table_posMaster2.ts new file mode 100644 index 00000000..4a8d3a4e --- /dev/null +++ b/src/migration/1706696231054-add_table_posMaster2.ts @@ -0,0 +1,38 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTablePosMaster21706696231054 implements MigrationInterface { + name = 'AddTablePosMaster21706696231054' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`orgChild2\` varchar(36) NULL`); + await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`orgChild3OrgChild3Id\` varchar(36) NULL`); + await queryRunner.query(`ALTER TABLE \`posMaster\` ADD \`orgChild4\` varchar(36) NULL`); + await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgRootId\` \`orgRootId\` varchar(40) NULL`); + await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild1Id\` \`orgChild1Id\` varchar(40) NULL`); + await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild2Id\` \`orgChild2Id\` varchar(40) NULL`); + await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild3Id\` \`orgChild3Id\` varchar(40) NULL`); + await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild4Id\` \`orgChild4Id\` varchar(40) NULL`); + await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_7da46fc341b77ebd43f28a8cf47\` FOREIGN KEY (\`orgRootId\`) REFERENCES \`orgRoot\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_7e3ee4640d067c5563c060e2c6b\` FOREIGN KEY (\`orgChild1Id\`) REFERENCES \`orgChild1\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_685b7779aa6d8897d5f3c899bf2\` FOREIGN KEY (\`orgChild2\`) REFERENCES \`orgChild2\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_838fef6a73e9cc70147b8f85bf7\` FOREIGN KEY (\`orgChild3OrgChild3Id\`) REFERENCES \`orgChild3\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`posMaster\` ADD CONSTRAINT \`FK_0564eef8bec8347d6b782a67537\` FOREIGN KEY (\`orgChild4\`) REFERENCES \`orgChild4\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_0564eef8bec8347d6b782a67537\``); + await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_838fef6a73e9cc70147b8f85bf7\``); + await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_685b7779aa6d8897d5f3c899bf2\``); + await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_7e3ee4640d067c5563c060e2c6b\``); + await queryRunner.query(`ALTER TABLE \`posMaster\` DROP FOREIGN KEY \`FK_7da46fc341b77ebd43f28a8cf47\``); + await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild4Id\` \`orgChild4Id\` varchar(40) NULL DEFAULT '00000000-0000-0000-0000-000000000000'`); + await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild3Id\` \`orgChild3Id\` varchar(40) NULL DEFAULT '00000000-0000-0000-0000-000000000000'`); + await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild2Id\` \`orgChild2Id\` varchar(40) NULL DEFAULT '00000000-0000-0000-0000-000000000000'`); + await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgChild1Id\` \`orgChild1Id\` varchar(40) NULL DEFAULT '00000000-0000-0000-0000-000000000000'`); + await queryRunner.query(`ALTER TABLE \`posMaster\` CHANGE \`orgRootId\` \`orgRootId\` varchar(40) NULL DEFAULT '00000000-0000-0000-0000-000000000000'`); + await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`orgChild4\``); + await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`orgChild3OrgChild3Id\``); + await queryRunner.query(`ALTER TABLE \`posMaster\` DROP COLUMN \`orgChild2\``); + } + +}