diff --git a/src/entities/BloodGroup.ts b/src/entities/BloodGroup.ts index 004c5095..11e3fb1e 100644 --- a/src/entities/BloodGroup.ts +++ b/src/entities/BloodGroup.ts @@ -1,6 +1,8 @@ -import { Entity, Column} from "typeorm"; +import { Entity, Column, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; +import { ProfileInformation } from "./ProfileInformation"; + @Entity("bloodGroup") export class BloodGroup extends EntityBase { @Column({ @@ -10,6 +12,9 @@ export class BloodGroup extends EntityBase { default: null, }) name: string; + + @OneToMany(() => ProfileInformation, (profileInformation) => profileInformation.bloodGroupId) + profileInformations: ProfileInformation[]; } export class CreateBloodGroup { diff --git a/src/entities/Gender.ts b/src/entities/Gender.ts index dd9cae1e..79d7e6b7 100644 --- a/src/entities/Gender.ts +++ b/src/entities/Gender.ts @@ -1,6 +1,8 @@ -import { Entity, Column} from "typeorm"; +import { Entity, Column, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; +import { ProfileInformation } from "./ProfileInformation"; + @Entity("gender") export class Gender extends EntityBase { @Column({ @@ -10,6 +12,9 @@ export class Gender extends EntityBase { default: null, }) name: string; + + @OneToMany(() => ProfileInformation, (profileInformation) => profileInformation.genderId) + profileInformations: ProfileInformation[]; } export class CreateGender { diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 3b01f4b3..b70a71b7 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -16,6 +16,7 @@ import { ProfileAbility } from "./ProfileAbility"; import { ProfileDuty } from "./ProfileDuty"; import { ProfileNopaid } from "./ProfileNopaid"; import { ProfileOther } from "./ProfileOther"; +import { ProfileInformation } from "./ProfileInformation"; import { ProfileFamilyHistory } from "./ProfileFamily"; @Entity("profile") @@ -192,6 +193,9 @@ export class Profile extends EntityBase { @ManyToOne(() => PosType, (posType) => posType.profiles) @JoinColumn({ name: "posTypeId" }) posType: PosType; + + @OneToMany(() => ProfileInformation, (profileInformation) => profileInformation.profile) + profileInformation: ProfileInformation[]; } export class CreateProfile { diff --git a/src/entities/ProfileInformation.ts b/src/entities/ProfileInformation.ts new file mode 100644 index 00000000..6ee1490a --- /dev/null +++ b/src/entities/ProfileInformation.ts @@ -0,0 +1,154 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; + +import { Profile } from "./Profile"; +import { ProfileInformationHistory } from "./ProfileInformationHistory"; +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; +}; diff --git a/src/entities/ProfileInformationHistory.ts b/src/entities/ProfileInformationHistory.ts new file mode 100644 index 00000000..c7c04b27 --- /dev/null +++ b/src/entities/ProfileInformationHistory.ts @@ -0,0 +1,18 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; + +import { ProfileInformation } from "./ProfileInformation"; + +@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 6a2bbc85..a9b3edd7 100644 --- a/src/entities/Relationship.ts +++ b/src/entities/Relationship.ts @@ -1,6 +1,8 @@ -import { Entity, Column} from "typeorm"; +import { Entity, Column, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; +import { ProfileInformation } from "./ProfileInformation"; + @Entity("relationship") export class Relationship extends EntityBase { @Column({ @@ -10,6 +12,9 @@ export class Relationship extends EntityBase { default: null, }) name: string; + + @OneToMany(() => ProfileInformation, (profileInformation) => profileInformation.relationshipId) + profileInformations: ProfileInformation[]; } export class CreateRelationship {