From 0b2650e17c26de5c4ed3562456ec972d3715b1a1 Mon Sep 17 00:00:00 2001 From: kittapath Date: Fri, 1 Nov 2024 17:21:57 +0700 Subject: [PATCH] table sign --- src/entities/Command.ts | 4 + src/entities/CommandSign.ts | 80 +++++++++++++++++++ src/entities/Profile.ts | 6 +- .../1730456393834-add_table_commandSign.ts | 18 +++++ 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 src/entities/CommandSign.ts create mode 100644 src/migration/1730456393834-add_table_commandSign.ts diff --git a/src/entities/Command.ts b/src/entities/Command.ts index eda2d20d..c3f55958 100644 --- a/src/entities/Command.ts +++ b/src/entities/Command.ts @@ -6,6 +6,7 @@ import { CommandSalary } from "./CommandSalary"; import { CommandRecive } from "./CommandRecive"; import { ProfileSalary } from "./ProfileSalary"; import { ProfileSalaryHistory } from "./ProfileSalaryHistory"; +import { CommandSign } from "./CommandSign"; @Entity("command") export class Command extends EntityBase { @@ -151,6 +152,9 @@ export class Command extends EntityBase { @OneToMany(() => CommandSend, (commandSend) => commandSend.command) commandSends: CommandSend[]; + @OneToMany(() => CommandSign, (commandSign) => commandSign.command) + commandSigns: CommandSign[]; + @OneToMany(() => CommandRecive, (commandRecive) => commandRecive.command) commandRecives: CommandRecive[]; diff --git a/src/entities/CommandSign.ts b/src/entities/CommandSign.ts new file mode 100644 index 00000000..85cb1e31 --- /dev/null +++ b/src/entities/CommandSign.ts @@ -0,0 +1,80 @@ +import { Entity, Column, JoinColumn, ManyToOne, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Command } from "./Command"; +import { Profile } from "./Profile"; + +@Entity("commandSign") +export class CommandSign extends EntityBase { + @Column({ + nullable: true, + comment: "คำนำหน้า", + length: 255, + default: null, + }) + prefix: string; + + @Column({ + nullable: true, + comment: "ชื่อ", + length: 255, + default: null, + }) + firstName: string; + + @Column({ + nullable: true, + comment: "สกุล", + length: 255, + default: null, + }) + lastName: string; + + @Column({ + nullable: true, + comment: "ตำแหน่ง", + length: 255, + default: null, + }) + position: string; + + @Column({ + nullable: true, + comment: "ความเห็น", + length: 255, + default: null, + }) + comment: string; + + @Column({ + comment: "เป็นผู้มีอำนาจลงนาม", + default: false, + }) + isActive: boolean; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง command", + }) + commandId: string; + + @ManyToOne(() => Command, (command) => command.commandSigns) + @JoinColumn({ name: "commandId" }) + command: Command; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง profile", + }) + profileId: string; + + @ManyToOne(() => Profile, (profile) => profile.commandSigns) + @JoinColumn({ name: "profileId" }) + profile: Profile; +} + +export class CreateCommandSign { + @Column() + name: string; +} + +// export type UpdateCommandSign = Partial; diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 5426a665..dedb7834 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -34,6 +34,7 @@ import { CommandSend } from "./CommandSend"; import { DevelopmentRequest } from "./DevelopmentRequest"; import { StateOperatorUser } from "./StateOperatorUser"; import { StateUserComment } from "./StateUserComment"; +import { CommandSign } from "./CommandSign"; @Entity("profile") export class Profile extends EntityBase { @@ -122,7 +123,7 @@ export class Profile extends EntityBase { @Column({ nullable: true, - comment: "สถานะอีเมล",//VERIFIED = ยืนยัน, NOT_VERIFIED = ไม่ได้ยืนยัน + comment: "สถานะอีเมล", //VERIFIED = ยืนยัน, NOT_VERIFIED = ไม่ได้ยืนยัน default: null, }) statusEmail: string; @@ -387,6 +388,9 @@ export class Profile extends EntityBase { @OneToMany(() => CommandSend, (v) => v.profile) commandSends: CommandSend[]; + @OneToMany(() => CommandSign, (v) => v.profile) + commandSigns: CommandSign[]; + @OneToMany(() => StateOperatorUser, (v) => v.profile) stateOperatorUsers: StateOperatorUser[]; diff --git a/src/migration/1730456393834-add_table_commandSign.ts b/src/migration/1730456393834-add_table_commandSign.ts new file mode 100644 index 00000000..1d260cb0 --- /dev/null +++ b/src/migration/1730456393834-add_table_commandSign.ts @@ -0,0 +1,18 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableCommandSign1730456393834 implements MigrationInterface { + name = 'AddTableCommandSign1730456393834' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`commandSign\` (\`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', \`prefix\` varchar(255) NULL COMMENT 'คำนำหน้า', \`firstName\` varchar(255) NULL COMMENT 'ชื่อ', \`lastName\` varchar(255) NULL COMMENT 'สกุล', \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง', \`comment\` varchar(255) NULL COMMENT 'ความเห็น', \`isActive\` tinyint NOT NULL COMMENT 'เป็นผู้มีอำนาจลงนาม' DEFAULT 0, \`commandId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง command', \`profileId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง profile', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`commandSign\` ADD CONSTRAINT \`FK_143488a80d2317daa9333e1a726\` FOREIGN KEY (\`commandId\`) REFERENCES \`command\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`commandSign\` ADD CONSTRAINT \`FK_748a443f8f9d4fa32dfddad0b2e\` FOREIGN KEY (\`profileId\`) REFERENCES \`profile\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`commandSign\` DROP FOREIGN KEY \`FK_748a443f8f9d4fa32dfddad0b2e\``); + await queryRunner.query(`ALTER TABLE \`commandSign\` DROP FOREIGN KEY \`FK_143488a80d2317daa9333e1a726\``); + await queryRunner.query(`DROP TABLE \`commandSign\``); + } + +}