diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts new file mode 100644 index 00000000..ec42f64e --- /dev/null +++ b/src/controllers/CommandController.ts @@ -0,0 +1,281 @@ +import { + Controller, + Post, + Put, + Delete, + Route, + Security, + Tags, + Body, + Path, + Request, + SuccessResponse, + Response, + Get, + Query, +} from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import HttpSuccess from "../interfaces/http-success"; +import HttpStatusCode from "../interfaces/http-status"; +import HttpError from "../interfaces/http-error"; +import { Command } from "../entities/Command"; +import { Brackets } from "typeorm"; +import { CommandType } from "../entities/CommandType"; + +@Route("api/v1/org/command") +@Tags("Command") +@Security("bearerAuth") +@Response( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", +) +@SuccessResponse(HttpStatusCode.OK, "สำเร็จ") +export class CommandController extends Controller { + private commandRepository = AppDataSource.getRepository(Command); + private commandTypeRepository = AppDataSource.getRepository(CommandType); + + /** + * API list รายการคำสั่ง + * + * @summary API list รายการคำสั่ง + * + */ + @Get("list") + async GetResult( + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query() keyword: string = "", + @Query() commandTypeId?: string | null, + @Query() year?: number, + @Query() status?: string | null, + ) { + const [commands, total] = await this.commandRepository + .createQueryBuilder("command") + .andWhere( + new Brackets((qb) => { + qb.where(keyword != null && keyword != "" ? "command.commandNo LIKE :keyword" : "1=1", { + keyword: `%${keyword}%`, + }).orWhere( + keyword != null && keyword != "" ? "command.createdFullName LIKE :keyword" : "1=1", + { + keyword: `%${keyword}%`, + }, + ); + }), + ) + .andWhere( + status != null && status != undefined && status != "" + ? "command.status LIKE :status" + : "1=1", + { + status: + status == null || status == undefined || status == "" + ? null + : `${status.trim().toLocaleUpperCase()}`, + }, + ) + .andWhere(year != null && year != undefined && year != 0 ? "command.year = :year" : "1=1", { + year: year == null || year == undefined || year == 0 ? null : `${year}`, + }) + .andWhere( + commandTypeId != null && commandTypeId != undefined && commandTypeId != "" + ? "command.commandTypeId = :commandTypeId" + : "1=1", + { + commandTypeId: + commandTypeId == null || commandTypeId == undefined || commandTypeId == "" + ? null + : `${commandTypeId}`, + }, + ) + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + + const data = commands.map((_data) => ({ + id: _data.id, + commandNo: _data.commandNo, + commandYear: _data.commandYear, + commandAffectDate: _data.commandAffectDate, + commandExcecuteDate: _data.commandExcecuteDate, + assignFullName: _data.createdFullName, + createdFullName: _data.createdFullName, + status: _data.status, + })); + + return new HttpSuccess({ data, total }); + } + + /** + * API สร้างรายการ body คำสั่ง + * + * @summary API สร้างรายการ body คำสั่ง + * + */ + @Post() + async Post( + @Body() + requestBody: { + commandTypeId: string; + commandNo: string | null; + commandYear: number | null; + }, + @Request() request: { user: Record }, + ) { + const command = Object.assign(new Command(), requestBody); + + const commandType = await this.commandTypeRepository.findOne({ + where: { id: requestBody.commandTypeId }, + }); + + if (!commandType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ"); + } + command.status = "DRAFT"; + command.createdUserId = request.user.sub; + command.createdFullName = request.user.name; + command.createdAt = new Date(); + command.lastUpdateUserId = request.user.sub; + command.lastUpdateFullName = request.user.name; + command.lastUpdatedAt = new Date(); + await this.commandRepository.save(command); + return new HttpSuccess(command.id); + } + + /** + * API รายละเอียดรายการคำสั่ง tab1 + * + * @summary API รายละเอียดรายการคำสั่ง tab1 + * + * @param {string} id Id คำสั่ง + */ + @Get("tab1/{id}") + async GetByIdTab1(@Path() id: string) { + const command = await this.commandRepository.findOne({ + where: { id }, + select: [ + "id", + "status", + "commandNo", + "commandYear", + "issue", + "detailHeader", + "detailBody", + "detailFooter", + ], + }); + if (!command) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); + } + return new HttpSuccess(command); + } + + /** + * API แก้ไขรายการ body คำสั่ง Tab1 + * + * @summary API แก้ไขรายการ body คำสั่ง Tab1 + * + * @param {string} id Id คำสั่ง + */ + @Put("tab1/{id}") + async PutTab1( + @Path() id: string, + @Body() + requestBody: { + commandNo: string | null; + commandYear: number | null; + issue: string | null; + detailHeader: string | null; + detailBody: string | null; + detailFooter: string | null; + }, + @Request() request: { user: Record }, + ) { + const command = await this.commandRepository.findOne({ where: { id: id } }); + if (!command) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); + } + const data = new Command(); + Object.assign(data, { ...command, ...requestBody }); + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.lastUpdatedAt = new Date(); + await this.commandRepository.save(data); + return new HttpSuccess(); + } + + /** + * API คัดลอก + * + * @summary API คัดลอก + * + * @param {string} id Id คำสั่ง + */ + @Put("copy/{id}") + async PutCopy( + @Path() id: string, + @Body() + requestBody: { commandNo?: string | null; commandYear?: string | null }, + @Request() request: { user: Record }, + ) { + const command = await this.commandRepository.findOne({ where: { id: id } }); + if (!command) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); + } + const copy = new Command(); + Object.assign(copy, { ...command, ...requestBody, id: undefined }); + copy.createdUserId = request.user.sub; + copy.createdFullName = request.user.name; + copy.createdAt = new Date(); + copy.lastUpdateUserId = request.user.sub; + copy.lastUpdateFullName = request.user.name; + copy.lastUpdatedAt = new Date(); + await this.commandRepository.save(copy); + return new HttpSuccess(copy.id); + } + + /** + * API ยกเลิก + * + * @summary API ยกเลิก + * + * @param {string} id Id คำสั่ง + */ + @Put("cancel/{id}") + async PutCancel( + @Path() id: string, + @Body() + requestBody: { reason?: string | null }, + @Request() request: { user: Record }, + ) { + const command = await this.commandRepository.findOne({ where: { id: id } }); + if (!command) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); + } + command.status = "CANCEL"; + command.lastUpdateUserId = request.user.sub; + command.lastUpdateFullName = request.user.name; + command.lastUpdatedAt = new Date(); + await this.commandRepository.save(command); + return new HttpSuccess(); + } + + /** + * API ลบรายการคำสั่ง + * + * @summary API ลบรายการคำสั่ง + * + * @param {string} id Id คำสั่ง + */ + @Delete("{id}") + async Delete(@Path() id: string) { + const command = await this.commandRepository.findOne({ + where: { id: id }, + }); + if (!command) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); + } + await this.commandRepository.delete(command.id); + return new HttpSuccess(); + } +} diff --git a/src/controllers/CommandTypeController.ts b/src/controllers/CommandTypeController.ts new file mode 100644 index 00000000..ea71485e --- /dev/null +++ b/src/controllers/CommandTypeController.ts @@ -0,0 +1,163 @@ +import { + Controller, + Post, + Put, + Delete, + Route, + Security, + Tags, + Body, + Path, + Request, + SuccessResponse, + Response, + Get, +} from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import HttpSuccess from "../interfaces/http-success"; +import HttpStatusCode from "../interfaces/http-status"; +import HttpError from "../interfaces/http-error"; +import { CommandType, CreateCommandType, UpdateCommandType } from "../entities/CommandType"; +import { Not } from "typeorm"; + +@Route("api/v1/org/commandType") +@Tags("CommandType") +@Security("bearerAuth") +@Response( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", +) +@SuccessResponse(HttpStatusCode.OK, "สำเร็จ") +export class CommandTypeController extends Controller { + private commandTypeRepository = AppDataSource.getRepository(CommandType); + + /** + * API list รายการประเภทคำสั่ง + * + * @summary ORG_056 - CRUD ประเภทคำสั่ง (ADMIN) #61 + * + */ + @Get("list") + async Get() { + const _commandType = await this.commandTypeRepository.find({ + select: [ + "id", + "name", + "type", + "code", + "createdAt", + "lastUpdatedAt", + "createdFullName", + "lastUpdateFullName", + ], + order: { name: "ASC" }, + }); + return new HttpSuccess(_commandType); + } + + /** + * API รายละเอียดรายการประเภทคำสั่ง + * + * @summary ORG_056 - CRUD ประเภทคำสั่ง (ADMIN) #61 + * + * @param {string} id Id ประเภทคำสั่ง + */ + @Get("{id}") + async GetById(@Path() id: string) { + const _commandType = await this.commandTypeRepository.findOne({ + where: { id }, + select: ["id", "name", "type", "code"], + }); + if (!_commandType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(_commandType); + } + + /** + * API สร้างรายการ body ประเภทคำสั่ง + * + * @summary ORG_056 - CRUD ประเภทคำสั่ง (ADMIN) #61 + * + */ + @Post() + async Post( + @Body() + requestBody: CreateCommandType, + @Request() request: { user: Record }, + ) { + const _commandType = Object.assign(new CommandType(), requestBody); + if (!_commandType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const checkName = await this.commandTypeRepository.findOne({ + where: { name: requestBody.name }, + }); + + if (checkName) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); + } + + _commandType.createdUserId = request.user.sub; + _commandType.createdFullName = request.user.name; + _commandType.lastUpdateUserId = request.user.sub; + _commandType.lastUpdateFullName = request.user.name; + _commandType.createdAt = new Date(); + _commandType.lastUpdatedAt = new Date(); + await this.commandTypeRepository.save(_commandType); + return new HttpSuccess(); + } + + /** + * API แก้ไขรายการ body ประเภทคำสั่ง + * + * @summary ORG_056 - CRUD ประเภทคำสั่ง (ADMIN) #61 + * + * @param {string} id Id ประเภทคำสั่ง + */ + @Put("{id}") + async Put( + @Path() id: string, + @Body() + requestBody: UpdateCommandType, + @Request() request: { user: Record }, + ) { + const _commandType = await this.commandTypeRepository.findOne({ where: { id: id } }); + if (!_commandType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทคำสั่งชื่อนี้"); + } + const checkName = await this.commandTypeRepository.findOne({ + where: { id: Not(id), name: requestBody.name }, + }); + if (checkName) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); + } + + _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(); + } + + /** + * API ลบรายการประเภทคำสั่ง + * + * @summary ORG_056 - CRUD ประเภทคำสั่ง (ADMIN) #61 + * + * @param {string} id Id ประเภทคำสั่ง + */ + @Delete("{id}") + async Delete(@Path() id: string) { + const _delCommandType = await this.commandTypeRepository.findOne({ + where: { id: id }, + }); + if (!_delCommandType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทคำสั่งชื่อนี้"); + } + await this.commandTypeRepository.delete(_delCommandType.id); + return new HttpSuccess(); + } +} diff --git a/src/entities/Command.ts b/src/entities/Command.ts new file mode 100644 index 00000000..3d0188b4 --- /dev/null +++ b/src/entities/Command.ts @@ -0,0 +1,99 @@ +import { Entity, Column, JoinColumn, ManyToOne } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { CommandType } from "./CommandType"; + +@Entity("command") +export class Command extends EntityBase { + // DRAFT = แบบร่าง + // PENDING = รอผู้มีอำนาจ + // WAITING = รอออกคำสั่ง + // REPORTED = ออกคำสั่งเสร็จสิ้น + // CANCEL = ยกเลิก + @Column({ + nullable: true, + comment: "สถานะ", + length: 20, + default: null, + }) + status: string; + + @Column({ + nullable: true, + comment: "คำสั่งเรื่อง", + length: 255, + default: null, + }) + issue: string; + + @Column({ + nullable: true, + comment: "เลขที่คำสั่ง", + length: 255, + default: null, + }) + commandNo: string; + + @Column({ + nullable: true, + comment: "ปี", + default: null, + }) + commandYear: number; + + @Column({ + nullable: true, + type: "datetime", + comment: "วันที่ลงนาม", + default: null, + }) + commandAffectDate: Date; + + @Column({ + nullable: true, + type: "datetime", + comment: "วันที่คำสั่งมีผล", + default: null, + }) + commandExcecuteDate: Date; + + @Column({ + nullable: true, + comment: "เนื้อหาคำสั่งส่วนต้น", + type: "text", + default: null, + }) + detailHeader: string; + + @Column({ + nullable: true, + comment: "เนื้อหาคำสั่งส่วนกลาง", + type: "text", + default: null, + }) + detailBody: string; + + @Column({ + nullable: true, + comment: "เนื้อหาคำสั่งส่วนท้าย", + type: "text", + default: null, + }) + detailFooter: string; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง commandType", + }) + commandTypeId: string; + + @ManyToOne(() => CommandType, (commandType) => commandType.commands) + @JoinColumn({ name: "commandTypeId" }) + commandType: CommandType; +} + +export class CreateCommand { + @Column() + name: string; +} + +// export type UpdateCommand = Partial; diff --git a/src/entities/CommandType.ts b/src/entities/CommandType.ts new file mode 100644 index 00000000..ca734f50 --- /dev/null +++ b/src/entities/CommandType.ts @@ -0,0 +1,46 @@ +import { Entity, Column, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Command } from "./Command"; + +@Entity("commandType") +export class CommandType extends EntityBase { + @Column({ + nullable: true, + comment: "ชื่อคำสั่ง", + length: 255, + default: null, + }) + name: string; + + @Column({ + nullable: true, + comment: "ประเภทคำสั่ง", + length: 255, + default: null, + }) + type: string; + + @Column({ + nullable: true, + comment: "รหัสคำสั่ง", + length: 255, + default: null, + }) + code: string; + + @OneToMany(() => Command, (command) => command.commandType) + commands: Command[]; +} + +export class CreateCommandType { + @Column() + name: string; + + @Column() + type: string; + + @Column() + code: string; +} + +export type UpdateCommandType = Partial; diff --git a/src/migration/1726046987224-add_command.ts b/src/migration/1726046987224-add_command.ts new file mode 100644 index 00000000..c124d8fb --- /dev/null +++ b/src/migration/1726046987224-add_command.ts @@ -0,0 +1,40 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddCommand1726046987224 implements MigrationInterface { + name = 'AddCommand1726046987224' + + public async up(queryRunner: QueryRunner): Promise { + // await queryRunner.query(`CREATE TABLE \`subDistrictImport\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`PROVINCE_CODE\` varchar(255) NULL, \`AMPHUR_CODE\` varchar(255) NULL, \`DISTRICT_CODE\` varchar(255) NULL, \`DISTRICT_NAME\` varchar(255) NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + // await queryRunner.query(`CREATE TABLE \`provinceImport\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`PROVINCE_CODE\` varchar(255) NULL, \`PROVINCE_NAME\` varchar(255) NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + // await queryRunner.query(`CREATE TABLE \`HR_PERSONAL_OFFICER_FAMILY\` (\`CIT\` text NULL, \`id\` int NOT NULL AUTO_INCREMENT, \`FATHER_RANK_NAME\` text NULL, \`FATHER_FNAME\` text NULL, \`FATHER_LNAME\` text NULL, \`MOTHER_RANK_NAME\` text NULL, \`MOTHER_FNAME\` text NULL, \`MOTHER_LNAME\` text NULL, \`SPOUSE_RANK_NAME\` text NULL, \`SPOUSE_FNAME\` text NULL, \`SPOUSE_LNAME\` text NULL, \`SPOUSE_ID\` text NULL, \`MARRIAGE_STATE\` text NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + // await queryRunner.query(`CREATE TABLE \`HR_POSITION_OFFICER\` (\`CIT\` text NULL, \`id\` int NOT NULL AUTO_INCREMENT, \`MP_POS_DATE\` text NULL, \`SALARY\` text NULL, \`MP_COMMAND_NUM\` text NULL, \`POS_NUM_NAME\` text NULL, \`POS_NUM_CODE\` text NULL, \`FLAG_TO_NAME\` text NULL, \`WORK_LINE_NAME\` text NULL, \`SPECIALIST_NAME\` text NULL, \`ADMIN_NAME\` text NULL, \`REMARK\` text NULL, \`ORDER_MOVE_POSITION\` text NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + // await queryRunner.query(`CREATE TABLE \`HR_PERSONAL_EMP_FAMILY\` (\`CIT\` text NULL, \`id\` int NOT NULL AUTO_INCREMENT, \`FATHER_RANK_NAME\` text NULL, \`FATHER_FNAME\` text NULL, \`FATHER_LNAME\` text NULL, \`MOTHER_RANK_NAME\` text NULL, \`MOTHER_FNAME\` text NULL, \`MOTHER_LNAME\` text NULL, \`SPOUSE_RANK_NAME\` text NULL, \`SPOUSE_FNAME\` text NULL, \`SPOUSE_LNAME\` text NULL, \`SPOUSE_ID\` text NULL, \`MARRIAGE_STATE\` text NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + // await queryRunner.query(`CREATE TABLE \`HR_PERSONAL_OFFICER_ADDRESS\` (\`CIT\` text NULL, \`id\` int NOT NULL AUTO_INCREMENT, \`PROVINCE_CODE\` text NULL, \`AMPHUR_CODE\` text NULL, \`DISTRICT_CODE\` text NULL, \`CONTACT_PROVINCE_CODE\` text NULL, \`CONTACT_AMPHUR_CODE\` text NULL, \`CONTACT_DISTRICT_CODE\` text NULL, \`H_NUMBER\` text NULL, \`ZIPCODE\` text NULL, \`CONTACT_H_NUMBER\` text NULL, \`CONTACT_ZIPCODE\` text NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + // await queryRunner.query(`CREATE TABLE \`HR_EDUCATION\` (\`CIT\` text NULL, \`id\` int NOT NULL AUTO_INCREMENT, \`EDUCATION_CODE\` text NULL, \`START_EDUCATION_YEAR\` text NULL, \`EDUCATION_YEAR\` text NULL, \`INSTITUE\` text NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + // await queryRunner.query(`CREATE TABLE \`HR_EDUCATION_EMP\` (\`CIT\` text NULL, \`id\` int NOT NULL AUTO_INCREMENT, \`EDUCATION_CODE\` text NULL, \`START_EDUCATION_YEAR\` text NULL, \`EDUCATION_YEAR\` text NULL, \`INSTITUE\` text NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + // await queryRunner.query(`CREATE TABLE \`HR_PERSONAL_EMP_ADDRESS\` (\`CIT\` text NULL, \`id\` int NOT NULL AUTO_INCREMENT, \`PROVINCE_CODE\` text NULL, \`AMPHUR_CODE\` text NULL, \`DISTRICT_CODE\` text NULL, \`CONTACT_PROVINCE_CODE\` text NULL, \`CONTACT_AMPHUR_CODE\` text NULL, \`CONTACT_DISTRICT_CODE\` text NULL, \`H_NUMBER\` text NULL, \`ZIPCODE\` text NULL, \`CONTACT_H_NUMBER\` text NULL, \`CONTACT_ZIPCODE\` text NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + // await queryRunner.query(`CREATE TABLE \`educationMis\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`EDUCATION_CODE\` varchar(255) NULL, \`EDUCATION_NAME\` varchar(255) NULL, \`EDUCATION_ABB_NAME\` varchar(255) NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`commandType\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`name\` varchar(255) NULL COMMENT 'ชื่อคำสั่ง', \`type\` varchar(255) NULL COMMENT 'ประเภทคำสั่ง', \`code\` varchar(255) NULL COMMENT 'รหัสคำสั่ง', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`command\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`status\` varchar(20) NULL COMMENT 'สถานะ', \`issue\` varchar(255) NULL COMMENT 'คำสั่งเรื่อง', \`commandNo\` varchar(255) NULL COMMENT 'เลขที่คำสั่ง', \`commandYear\` int NULL COMMENT 'ปี', \`commandAffectDate\` datetime NULL COMMENT 'วันที่ลงนาม', \`commandExcecuteDate\` datetime NULL COMMENT 'วันที่คำสั่งมีผล', \`detailHeader\` text NULL COMMENT 'เนื้อหาคำสั่งส่วนต้น', \`detailBody\` text NULL COMMENT 'เนื้อหาคำสั่งส่วนกลาง', \`detailFooter\` text NULL COMMENT 'เนื้อหาคำสั่งส่วนท้าย', \`commandTypeId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง commandType', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + // await queryRunner.query(`CREATE TABLE \`amphurImport\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`PROVINCE_CODE\` varchar(255) NULL, \`AMPHUR_CODE\` varchar(255) NULL, \`AMPHUR_NAME\` varchar(255) NULL, PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`command\` ADD CONSTRAINT \`FK_c14ab4000e0fc4f43e066c3f5fd\` FOREIGN KEY (\`commandTypeId\`) REFERENCES \`commandType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`command\` DROP FOREIGN KEY \`FK_c14ab4000e0fc4f43e066c3f5fd\``); + // await queryRunner.query(`DROP TABLE \`amphurImport\``); + await queryRunner.query(`DROP TABLE \`command\``); + await queryRunner.query(`DROP TABLE \`commandType\``); + // await queryRunner.query(`DROP TABLE \`educationMis\``); + // await queryRunner.query(`DROP TABLE \`HR_PERSONAL_EMP_ADDRESS\``); + // await queryRunner.query(`DROP TABLE \`HR_EDUCATION_EMP\``); + // await queryRunner.query(`DROP TABLE \`HR_EDUCATION\``); + // await queryRunner.query(`DROP TABLE \`HR_PERSONAL_OFFICER_ADDRESS\``); + // await queryRunner.query(`DROP TABLE \`HR_PERSONAL_EMP_FAMILY\``); + // await queryRunner.query(`DROP TABLE \`HR_POSITION_OFFICER\``); + // await queryRunner.query(`DROP TABLE \`HR_PERSONAL_OFFICER_FAMILY\``); + // await queryRunner.query(`DROP TABLE \`provinceImport\``); + // await queryRunner.query(`DROP TABLE \`subDistrictImport\``); + } + +}