diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index bf63fe5..9981c45 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -799,12 +799,12 @@ export class DevelopmentController extends Controller { @Query() searchField?: "year" | "projectName", @Query() searchKeyword: string = "", ) { - let queryLike = "developer.projectName LIKE :keyword"; + let queryLike = "development.projectName LIKE :keyword"; if (searchField == "year") { - queryLike = "developer.year LIKE :keyword"; + queryLike = "development.year LIKE :keyword"; } const [record, total] = await this.developmentRepository - .createQueryBuilder("developer") + .createQueryBuilder("development") .andWhere( searchKeyword != undefined && searchKeyword != null && searchKeyword != "" ? queryLike @@ -899,6 +899,7 @@ export class DevelopmentController extends Controller { @Query("pageSize") pageSize: number = 10, @Query("year") year: number, @Query("status") status: string, + @Query("root") root?: string | null, @Query("keyword") keyword?: string, ) { const [development, total] = await AppDataSource.getRepository(Development) @@ -906,13 +907,16 @@ export class DevelopmentController extends Controller { .andWhere(year > 0 ? "development.year LIKE :year" : "1=1", { year: `${year.toString()}`, }) + .andWhere(root != undefined && root != null ? "development.root LIKE :root" : "1=1", { + root: `${root}`, + }) .andWhere(status != undefined ? "development.status LIKE :status" : "1=1", { status: `%${status}%`, }) .andWhere(keyword != undefined ? "development.projectName LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, }) - .select(["development.id", "development.projectName", "development.year"]) + .select(["development.id", "development.projectName", "development.year", "development.root"]) .orderBy("development.year", "DESC") .orderBy("development.createdAt", "DESC") .skip((page - 1) * pageSize) @@ -974,7 +978,17 @@ export class DevelopmentController extends Controller { async GetDevelopemtTab1ById(@Path() id: string) { const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, - select: ["id", "year", "projectName", "reason", "objective"], + select: [ + "id", + "year", + "projectName", + "reason", + "objective", + "root", + "rootId", + "orgRootShortName", + "orgRevisionId", + ], }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); @@ -1205,6 +1219,26 @@ export class DevelopmentController extends Controller { return new HttpSuccess(_getDevelopment); } + /** + * API list หน่วยงาน + * + * @summary DEV_00 - list หน่วยงาน # + * + */ + @Get("org/root") + async GetOrgDevelopemt(@Request() request: { user: Record }) { + const getOrg = await this.developmentRepository + .createQueryBuilder("development") + .select("development.root") + .groupBy("development.root") + .getRawMany(); + if (getOrg.length > 0) { + return new HttpSuccess(getOrg.map((x) => x.development_root)); + } + + return new HttpSuccess(getOrg); + } + /** * API upload User * diff --git a/src/entities/Development.ts b/src/entities/Development.ts index 3c1a34e..a708ece 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -14,6 +14,34 @@ import { DevelopmentProjectTechniqueActual } from "./DevelopmentProjectTechnique @Entity("development") export class Development extends EntityBase { + @Column({ + nullable: true, + comment: "id หน่วยงาน", + default: null, + }) + rootId: string; + + @Column({ + nullable: true, + comment: "ชื่อหน่วยงาน", + default: null, + }) + root: string; + + @Column({ + nullable: true, + comment: "ชื่อย่ิหน่วยงาน", + default: null, + }) + orgRootShortName: string; + + @Column({ + nullable: true, + comment: "id revision", + default: null, + }) + orgRevisionId: string; + @Column({ // กำลังดำเนินการ (ONGOING) // เสร็จสิ้น (FINISH) @@ -380,6 +408,14 @@ export class CreateDevelopment { year: number; @Column() projectName: string; + @Column() + root: string; + @Column() + rootId: string; + @Column() + orgRootShortName: string; + @Column() + orgRevisionId: string; } export class UpdateDevelopment1 { @@ -391,6 +427,14 @@ export class UpdateDevelopment1 { reason: string | null; @Column() objective: string | null; + @Column() + root: string; + @Column() + rootId: string; + @Column() + orgRootShortName: string; + @Column() + orgRevisionId: string; } export class UpdateDevelopment2_1 { @Column() diff --git a/src/migration/1712904313381-update_table_development_add_root.ts b/src/migration/1712904313381-update_table_development_add_root.ts new file mode 100644 index 0000000..1644d26 --- /dev/null +++ b/src/migration/1712904313381-update_table_development_add_root.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopmentAddRoot1712904313381 implements MigrationInterface { + name = 'UpdateTableDevelopmentAddRoot1712904313381' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` ADD \`rootId\` varchar(255) NULL COMMENT 'id หน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`root\` varchar(255) NULL COMMENT 'ชื่อหน่วยงาน'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`root\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`rootId\``); + } + +} diff --git a/src/migration/1712904744359-update_table_development_add_rootshortname.ts b/src/migration/1712904744359-update_table_development_add_rootshortname.ts new file mode 100644 index 0000000..2fa0f19 --- /dev/null +++ b/src/migration/1712904744359-update_table_development_add_rootshortname.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopmentAddRootshortname1712904744359 implements MigrationInterface { + name = 'UpdateTableDevelopmentAddRootshortname1712904744359' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` ADD \`orgRootShortName\` varchar(255) NULL COMMENT 'ชื่อย่ิหน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`orgRevisionId\` varchar(255) NULL COMMENT 'id revision'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`orgRevisionId\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`orgRootShortName\``); + } + +}