refactor: เพิ่ม table profileinformation และ profileinformationhistory

This commit is contained in:
Net 2024-03-20 09:08:42 +07:00
parent 1862b02a86
commit 049b591c77
2 changed files with 172 additions and 0 deletions

View file

@ -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;
};

View file

@ -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;
}