diff --git a/src/entities/BloodGroup.ts b/src/entities/BloodGroup.ts index 11e3fb1e..1c4fcc9d 100644 --- a/src/entities/BloodGroup.ts +++ b/src/entities/BloodGroup.ts @@ -1,7 +1,6 @@ import { Entity, Column, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; - -import { ProfileInformation } from "./ProfileInformation"; +import { Profile } from "./Profile"; @Entity("bloodGroup") export class BloodGroup extends EntityBase { @@ -13,8 +12,8 @@ export class BloodGroup extends EntityBase { }) name: string; - @OneToMany(() => ProfileInformation, (profileInformation) => profileInformation.bloodGroupId) - profileInformations: ProfileInformation[]; + @OneToMany(() => Profile, (v) => v.bloodGroup) + profile: Profile[]; } export class CreateBloodGroup { diff --git a/src/entities/Gender.ts b/src/entities/Gender.ts index 79d7e6b7..960ff541 100644 --- a/src/entities/Gender.ts +++ b/src/entities/Gender.ts @@ -1,7 +1,6 @@ import { Entity, Column, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; - -import { ProfileInformation } from "./ProfileInformation"; +import { Profile } from "./Profile"; @Entity("gender") export class Gender extends EntityBase { @@ -13,8 +12,8 @@ export class Gender extends EntityBase { }) name: string; - @OneToMany(() => ProfileInformation, (profileInformation) => profileInformation.genderId) - profileInformations: ProfileInformation[]; + @OneToMany(() => Profile, (v) => v.gender) + profile: Profile[]; } export class CreateGender { diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 55a300f5..c2f7fe44 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -1,4 +1,4 @@ -import { Entity, Column, OneToMany, OneToOne, JoinColumn, ManyToMany, ManyToOne } from "typeorm"; +import { Entity, Column, OneToMany, JoinColumn, ManyToOne } from "typeorm"; import { EntityBase } from "./base/Base"; import { PosMaster } from "./PosMaster"; import { PosLevel } from "./PosLevel"; @@ -16,9 +16,11 @@ import { ProfileAbility } from "./ProfileAbility"; import { ProfileDuty } from "./ProfileDuty"; import { ProfileNopaid } from "./ProfileNopaid"; import { ProfileOther } from "./ProfileOther"; -import { ProfileInformation } from "./ProfileInformation"; import { ProfileFamilyHistory } from "./ProfileFamily"; import { ProfileGovernment } from "./ProfileGovernment"; +import { Gender } from "./Gender"; +import { Relationship } from "./Relationship"; +import { BloodGroup } from "./BloodGroup"; @Entity("profile") export class Profile extends EntityBase { @@ -139,6 +141,63 @@ export class Profile extends EntityBase { }) birthDate: Date; + @Column({ + nullable: true, + comment: "เชื้อชาติ", + length: 255, + default: null, + }) + ethnicity: string; + + @Column({ + nullable: true, + comment: "ศาสนา", + length: 255, + default: null, + }) + religion: string; + + @Column({ + nullable: true, + comment: "เบอร์โทร", + length: 255, + default: null, + }) + telephoneNumber: string; + + @Column({ + nullable: true, + comment: "เพศ", + length: 40, + default: null, + }) + genderId: string; + + @ManyToOne(() => Gender, (v) => v.profile) + gender: Gender; + + @Column({ + nullable: true, + comment: "ความสัมพันธ์", + length: 40, + default: null, + }) + relationshipId: string; + + @ManyToOne(() => Relationship, (v) => v.profile) + relationship: Relationship; + + @Column({ + nullable: true, + comment: "กรุ๊ปเลือด", + length: 40, + default: null, + }) + bloodGroupId: string; + + @ManyToOne(() => BloodGroup, (v) => v.profile) + bloodGroup: BloodGroup; + @OneToMany(() => PosMaster, (posMaster) => posMaster.current_holder) current_holders: PosMaster[]; @@ -190,6 +249,9 @@ export class Profile extends EntityBase { @OneToMany(() => ProfileGovernment, (profileGovernment) => profileGovernment.profile) profileGovernment: ProfileGovernment[]; + @OneToMany(() => ProfileHistory, (v) => v.profile) + histories: ProfileHistory[]; + @ManyToOne(() => PosLevel, (posLevel) => posLevel.profiles) @JoinColumn({ name: "posLevelId" }) posLevel: PosLevel; @@ -197,32 +259,61 @@ export class Profile extends EntityBase { @ManyToOne(() => PosType, (posType) => posType.profiles) @JoinColumn({ name: "posTypeId" }) posType: PosType; +} - @OneToMany(() => ProfileInformation, (profileInformation) => profileInformation.profile) - profileInformation: ProfileInformation[]; +@Entity("profileHistory") +export class ProfileHistory extends Profile { + @Column({ + nullable: true, + length: 40, + comment: "คีย์นอก(FK)ของตาราง ProfileInformation", + default: null, + }) + profileId: string; + + @ManyToOne(() => Profile, (v) => v.histories, { onDelete: "CASCADE" }) + profile: Profile; } export class CreateProfile { - @Column() prefix: string; - - @Column() firstName: string; - - @Column() lastName: string; - - @Column() - citizenId: string; - - @Column() position: string; - - @Column("uuid") + email: string | null; + phone: string | null; + isProbation: boolean | null; + dateRetire: Date | null; + birthDate: Date | null; + ethnicity: string | null; + religion: string | null; + telephoneNumber: string | null; + citizenId: string; posLevelId: string | null; - - @Column("uuid") posTypeId: string | null; + genderId: string | null; + relationshipId: string | null; + bloodGroupId: string | null; } -export type UpdateProfile = Partial; +export type UpdateProfile = { + prefix?: string | null; + firstName?: string | null; + lastName?: string | null; + position?: string | null; + email?: string | null; + phone?: string | null; + keycloak?: string | null; + isProbation?: boolean | null; + dateRetire?: Date | null; + birthDate?: Date | null; + ethnicity?: string | null; + religion?: string | null; + telephoneNumber?: string | null; + citizenId?: string | null; + posLevelId?: string | null; + posTypeId?: string | null; + genderId?: string | null; + relationshipId?: string | null; + bloodGroupId?: string | null; +}; diff --git a/src/entities/ProfileInformation.ts b/src/entities/ProfileInformation.ts deleted file mode 100644 index e6157a5e..00000000 --- a/src/entities/ProfileInformation.ts +++ /dev/null @@ -1,169 +0,0 @@ -import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; -import { EntityBase } from "./base/Base"; - -import { Profile } from "./Profile"; -import { BloodGroup } from "./BloodGroup"; -import { Relationship } from "./Relationship"; -import { Gender } from "./Gender"; - -@Entity("profileInformation") -export class ProfileInformation extends EntityBase { - @Column({ - nullable: true, - comment: "เลขประจำตัวประชาชน", - default: null, - length: 13, - }) - citizenId: string; - - @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, - type: "datetime", - comment: "วันเกิด", - default: null, - }) - birthDate: Date; - - @Column({ - nullable: true, - comment: "เชื้อชาติ", - length: 255, - default: null, - }) - ethnicity: string; - - @Column({ - nullable: true, - comment: "ศาสนา", - length: 255, - default: null, - }) - religion: string; - - @Column({ - nullable: true, - comment: "เบอร์โทร", - length: 255, - default: null, - }) - telephoneNumber: string; - - @OneToMany(() => ProfileInformationHistory, (v) => v.profileInformation) - profileInformationHistory: ProfileInformationHistory[]; - - @Column({ - nullable: true, - comment: "เพศ", - length: 40, - default: null, - }) - genderId: string; - - @ManyToOne(() => Gender, (v) => v.profileInformations) - @JoinColumn({ name: "genderId" }) - gender: Gender; - - @Column({ - nullable: true, - comment: "ความสัมพันธ์", - length: 40, - default: null, - }) - relationshipId: string; - - @ManyToOne(() => Relationship, (v) => v.profileInformations) - @JoinColumn({ name: "relationshipId" }) - relationship: Relationship; - - @Column({ - nullable: true, - comment: "กรุ๊ปเลือด", - length: 40, - default: null, - }) - bloodGroupId: string; - - @ManyToOne(() => BloodGroup, (v) => v.profileInformations) - @JoinColumn({ name: "bloodGroupId" }) - bloodGroup: BloodGroup; - - @Column({ - nullable: true, - length: 40, - comment: "คีย์นอก(FK)ของตาราง Profile", - default: null, - }) - profileId: string; - - @ManyToOne(() => Profile, (v) => v.profileInformation) - @JoinColumn({ name: "profileId" }) - profile: Profile; -} - -export class CreateProfileInformation { - profileId: string | null; - citizenId: string | null; - prefix: string | null; - firstName: string | null; - lastName: string | null; - birthDate: Date | null; - ethnicity: string | null; - religion: string | null; - telephoneNumber: string | null; - genderId: string | null; - relationshipId: string | null; - bloodGroupId: string | null; -} - -export type UpdateProfileInformation = { - citizenId?: string | null; - prefix?: string | null; - firstName?: string | null; - lastName?: string | null; - birthDate?: Date | null; - ethnicity?: string | null; - religion?: string | null; - telephoneNumber?: string | null; - genderId?: string | null; - relationshipId?: string | null; - bloodGroupId?: string | null; -}; - -@Entity("profileInformationHistory") -export class ProfileInformationHistory extends ProfileInformation { - @Column({ - nullable: true, - length: 40, - comment: "คีย์นอก(FK)ของตาราง ProfileInformation", - default: null, - }) - profileInformationId: string; - - @ManyToOne(() => ProfileInformation, (v) => v.profileInformationHistory, { onDelete: "CASCADE" }) - @JoinColumn({ name: "profileInformationId" }) - profileInformation: ProfileInformation; -} diff --git a/src/entities/Relationship.ts b/src/entities/Relationship.ts index a9b3edd7..7e84710f 100644 --- a/src/entities/Relationship.ts +++ b/src/entities/Relationship.ts @@ -1,7 +1,7 @@ import { Entity, Column, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; -import { ProfileInformation } from "./ProfileInformation"; +import { Profile } from "./Profile"; @Entity("relationship") export class Relationship extends EntityBase { @@ -13,12 +13,11 @@ export class Relationship extends EntityBase { }) name: string; - @OneToMany(() => ProfileInformation, (profileInformation) => profileInformation.relationshipId) - profileInformations: ProfileInformation[]; + @OneToMany(() => Profile, (v) => v.relationship) + profile: Profile[]; } export class CreateRelationship { - @Column() name: string; }