42 lines
1 KiB
TypeScript
42 lines
1 KiB
TypeScript
|
|
import { Entity, Column, JoinColumn, ManyToOne, OneToMany } from "typeorm";
|
||
|
|
import { EntityBase } from "./base/Base";
|
||
|
|
import { Province } from "./Province";
|
||
|
|
import { SubDistrict } from "./SubDistrict";
|
||
|
|
|
||
|
|
@Entity("district")
|
||
|
|
export class District extends EntityBase {
|
||
|
|
@Column({
|
||
|
|
nullable: true,
|
||
|
|
comment: "เขต",
|
||
|
|
length: 255,
|
||
|
|
default: null,
|
||
|
|
})
|
||
|
|
name: string;
|
||
|
|
|
||
|
|
@Column({
|
||
|
|
length: 40,
|
||
|
|
comment: "คีย์นอก(FK)ของตาราง province",
|
||
|
|
})
|
||
|
|
provinceId: string;
|
||
|
|
|
||
|
|
@ManyToOne(() => Province, (province) => province.districts)
|
||
|
|
@JoinColumn({ name: "provinceId" })
|
||
|
|
province: Province;
|
||
|
|
|
||
|
|
@OneToMany(() => SubDistrict, (subDistrict) => subDistrict.district)
|
||
|
|
subDistricts: SubDistrict[];
|
||
|
|
|
||
|
|
@OneToMany(() => District, (district) => district.registrationDistricts)
|
||
|
|
registrationDistricts: District[];
|
||
|
|
|
||
|
|
@OneToMany(() => District, (district) => district.currentDistricts)
|
||
|
|
currentDistricts: District[];
|
||
|
|
}
|
||
|
|
|
||
|
|
export class CreateDistrict {
|
||
|
|
@Column()
|
||
|
|
name: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export type UpdateDistrict = Partial<CreateDistrict>;
|