From 8cb8b449b49c03bc42adc60d1f893f7543fa026b Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Wed, 31 Jan 2024 15:31:20 +0700 Subject: [PATCH] relation posMaster to Root and Child1-4 --- src/entities/OrgChild1.ts | 4 ++++ src/entities/OrgChild2.ts | 4 ++++ src/entities/OrgChild3.ts | 4 ++++ src/entities/OrgChild4.ts | 6 +++++- src/entities/OrgRoot.ts | 4 ++++ src/entities/PosMaster.ts | 27 ++++++++++++++++++++++++++- 6 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/entities/OrgChild1.ts b/src/entities/OrgChild1.ts index a75cf6ea..ef1c78c5 100644 --- a/src/entities/OrgChild1.ts +++ b/src/entities/OrgChild1.ts @@ -5,6 +5,7 @@ import { OrgChild2 } from "./OrgChild2"; import { OrgRevision } from "./OrgRevision"; import { OrgChild3 } from "./OrgChild3"; import { OrgChild4 } from "./OrgChild4"; +import { PosMaster } from "./PosMaster"; enum OrgChild1Rank { DEPARTMENT = "DEPARTMENT", @@ -108,6 +109,9 @@ export class OrgChild1 extends EntityBase { @OneToMany(() => OrgChild4, (orgChild4) => orgChild4.orgChild1) orgChild4s: OrgChild4[]; + + @OneToMany(() => PosMaster, (posMaster) => posMaster.orgChild1) + posMasters: PosMaster[]; } export class CreateOrgChild1 { diff --git a/src/entities/OrgChild2.ts b/src/entities/OrgChild2.ts index d41b3abe..8c66b684 100644 --- a/src/entities/OrgChild2.ts +++ b/src/entities/OrgChild2.ts @@ -5,6 +5,7 @@ import { OrgChild1 } from "./OrgChild1"; import { OrgChild3 } from "./OrgChild3"; import { OrgChild4 } from "./OrgChild4"; import { OrgRevision } from "./OrgRevision"; +import { PosMaster } from "./PosMaster"; // ENUM orgChild2Rank enum OrgChild2Rank { @@ -123,6 +124,9 @@ export class OrgChild2 extends EntityBase { @OneToMany(() => OrgChild4, (orgChild4) => orgChild4.orgChild2) orgChild4s: OrgChild4[]; + + @OneToMany(() => PosMaster, (posMaster) => posMaster.orgChild2) + posMasters: PosMaster[]; } export class CreateOrgChild2 { diff --git a/src/entities/OrgChild3.ts b/src/entities/OrgChild3.ts index edc92bf0..f666c753 100644 --- a/src/entities/OrgChild3.ts +++ b/src/entities/OrgChild3.ts @@ -5,6 +5,7 @@ import { OrgChild4 } from "./OrgChild4"; import { OrgRevision } from "./OrgRevision"; import { OrgChild1 } from "./OrgChild1"; import { OrgRoot } from "./OrgRoot"; +import { PosMaster } from "./PosMaster"; enum OrgChild3Rank { DEPARTMENT = "DEPARTMENT", @@ -122,6 +123,9 @@ export class OrgChild3 extends EntityBase { @OneToMany(() => OrgChild4, (orgChild4) => orgChild4.orgChild3) orgChild4s: OrgChild4[]; + + @OneToMany(() => PosMaster, (posMaster) => posMaster.orgChild3) + posMasters: PosMaster[]; } export class CreateOrgChild3 { diff --git a/src/entities/OrgChild4.ts b/src/entities/OrgChild4.ts index bcf61cc1..a47803e5 100644 --- a/src/entities/OrgChild4.ts +++ b/src/entities/OrgChild4.ts @@ -1,10 +1,11 @@ -import { Entity, Column, ManyToOne, JoinColumn, OneToOne } from "typeorm"; +import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { OrgRoot } from "./OrgRoot"; import { OrgChild1 } from "./OrgChild1"; import { OrgChild2 } from "./OrgChild2"; import { OrgChild3 } from "./OrgChild3"; import { OrgRevision } from "./OrgRevision"; +import { PosMaster } from "./PosMaster"; // ENUM orgChild4Rank enum OrgChild4Rank { DEPARTMENT = "DEPARTMENT", @@ -136,6 +137,9 @@ export class OrgChild4 extends EntityBase { @ManyToOne(() => OrgChild3, (orgChild3) => orgChild3.orgChild4s) @JoinColumn({ name: "orgChild3Id" }) orgChild3: OrgChild3; + + @OneToMany(() => PosMaster, (posMaster) => posMaster.orgChild4) + posMasters: PosMaster[] } export class CreateOrgChild4 { diff --git a/src/entities/OrgRoot.ts b/src/entities/OrgRoot.ts index 730167b5..4c5e62f8 100644 --- a/src/entities/OrgRoot.ts +++ b/src/entities/OrgRoot.ts @@ -5,6 +5,7 @@ import { OrgRevision } from "./OrgRevision"; import { OrgChild2 } from "./OrgChild2"; import { OrgChild3 } from "./OrgChild3"; import { OrgChild4 } from "./OrgChild4"; +import { PosMaster } from "./PosMaster"; // ENUM orgRootRank enum OrgRootRank { @@ -92,6 +93,9 @@ export class OrgRoot extends EntityBase { @JoinColumn({ name: "orgRevisionId" }) orgRevision: OrgRevision; + @OneToMany(() => PosMaster, (posMaster) => posMaster.orgRoot) + posMasters: PosMaster[]; + @OneToMany(() => OrgChild1, (orgChild1) => orgChild1.orgRoot) orgChild1s: OrgChild1[]; diff --git a/src/entities/PosMaster.ts b/src/entities/PosMaster.ts index 2f1326bd..674860c1 100644 --- a/src/entities/PosMaster.ts +++ b/src/entities/PosMaster.ts @@ -3,6 +3,11 @@ import { EntityBase } from "./base/Base"; import { CreatePosDict } from "./PosDict"; import { OrgRevision } from "./OrgRevision"; import { Position } from "./Position"; +import { OrgRoot } from "./OrgRoot"; +import { OrgChild1 } from "./OrgChild1"; +import { OrgChild2 } from "./OrgChild2"; +import { OrgChild3 } from "./OrgChild3"; +import { OrgChild4 } from "./OrgChild4"; enum PosMasterLine { MAIN = "MAIN", @@ -130,10 +135,30 @@ export class PosMaster extends EntityBase { }) orgRevisionId: string; //fk - @ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.orgRoots) + @ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.posMasters) @JoinColumn({ name: "orgRevisionId" }) orgRevision: OrgRevision; + @ManyToOne(() => OrgRoot, (orgRoot) => orgRoot.posMasters) + @JoinColumn({ name: "orgRootId" }) + orgRoot: OrgRoot; + + @ManyToOne(() => OrgChild1, (orgChild1) => orgChild1.posMasters) + @JoinColumn({ name: "orgChild1Id" }) + orgChild1: OrgChild1; + + @ManyToOne(() => OrgChild2, (orgChild2) => orgChild2.posMasters) + @JoinColumn({ name: "orgChild2" }) + orgChild2: OrgChild2; + + @ManyToOne(() => OrgChild3, (orgChild3) => orgChild3.posMasters) + @JoinColumn({ name: "orgChild3OrgChild3Id" }) + orgChild3: OrgChild3; + + @ManyToOne(() => OrgChild4, (orgChild4) => orgChild4.posMasters) + @JoinColumn({ name: "orgChild4" }) + orgChild4: OrgChild4; + @OneToMany(() => Position, (position) => position.posMaster) positions: Position[]; }