From 6804332f40d6bb4e89d12ef7f396ae904fc234bf Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 6 Feb 2024 10:12:41 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88=E0=B8=A1?= =?UTF-8?q?=20table=20Profile=20=E0=B8=97=E0=B8=B3=20relation=202=20field?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/entities/PosMaster.ts | 13 ++++++++- src/entities/Profile.ts | 61 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 src/entities/Profile.ts diff --git a/src/entities/PosMaster.ts b/src/entities/PosMaster.ts index 3ccaaaed..8191239e 100644 --- a/src/entities/PosMaster.ts +++ b/src/entities/PosMaster.ts @@ -8,6 +8,7 @@ import { OrgChild1 } from "./OrgChild1"; import { OrgChild2 } from "./OrgChild2"; import { OrgChild3 } from "./OrgChild3"; import { OrgChild4 } from "./OrgChild4"; +import { Profile } from "./Profile"; enum PosMasterLine { MAIN = "MAIN", @@ -136,13 +137,15 @@ export class PosMaster extends EntityBase { default: null, }) profileIdNextHolder: string; - + @Column({ length: 40, comment: "คีย์นอก(FK)ของตาราง orgRevision", }) orgRevisionId: string; //fk + + @ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.posMasters) @JoinColumn({ name: "orgRevisionId" }) orgRevision: OrgRevision; @@ -167,6 +170,14 @@ export class PosMaster extends EntityBase { @JoinColumn({ name: "orgChild4Id" }) orgChild4: OrgChild4; + @ManyToOne(() => Profile, (profile) => profile.posMasters) + @JoinColumn({ name: "profileIdCurrentHolder" }) + profile: Profile; + + @ManyToOne(() => Profile, (profile) => profile.next_holder_posMasters) + @JoinColumn({ name: "profileIdNextHolder" }) + next_holder: Profile; + @OneToMany(() => Position, (position) => position.posMaster) positions: Position[]; } diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts new file mode 100644 index 00000000..fe3fb1e7 --- /dev/null +++ b/src/entities/Profile.ts @@ -0,0 +1,61 @@ +import { Entity, Column, OneToMany} from "typeorm"; +import { EntityBase } from "./base/Base"; +import { PosMaster } from "./PosMaster"; + +@Entity("profile") +export class Profile extends EntityBase { + @Column({ + nullable: true, + comment: "คำนำหน้าชื่อ", + length: 40, + 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: "เลขประจำตัวประชาชน", + default: null, + }) + citizenId: number; + + @OneToMany(() => PosMaster, (posMaster) => posMaster.profile) + posMasters: PosMaster[]; + + @OneToMany(() => PosMaster, (posMaster) => posMaster.next_holder) + next_holder_posMasters: PosMaster[]; +} + +export class CreateProfile { + @Column() + prefix: string; + + @Column() + firstName: string; + + @Column() + lastName: string; + + @Column() + citizenId: number; +} + + + +export type UpdateProfile = Partial;