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;