From 31a7357c19877fd530b8501242cd6306dc673bd4 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 6 Feb 2024 11:30:41 +0700 Subject: [PATCH] add field org_053 --- src/controllers/PositionController.ts | 4 +++- src/entities/PosMaster.ts | 14 ++++++-------- src/entities/Profile.ts | 12 +++++++----- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index f2325bc8..0cc0a9e5 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -712,7 +712,7 @@ export class PositionController extends Controller { const [posMaster, total] = await this.posMasterRepository.findAndCount({ where: keywordConditions, order: { posMasterOrder: "ASC" }, - relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4"], + relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4" ,"current_holder" ,"next_holder"], skip: (body.page - 1) * body.pageSize, take: body.pageSize, }); @@ -736,6 +736,8 @@ export class PositionController extends Controller { posMasterNoPrefix: posMaster.posMasterNoPrefix, posMasterNo: posMaster.posMasterNo, posMasterNoSuffix: posMaster.posMasterNoSuffix, + fullNameNextHolder: posMaster.current_holder.prefix+posMaster.current_holder.firstName+" "+posMaster.current_holder.lastName, + fullNameCurrentHolder: posMaster.next_holder.prefix+posMaster.next_holder.firstName+" "+posMaster.next_holder.lastName, orgShortname: body.type === 0 ? posMaster.orgRoot.orgRootShortName diff --git a/src/entities/PosMaster.ts b/src/entities/PosMaster.ts index 8191239e..461a97e1 100644 --- a/src/entities/PosMaster.ts +++ b/src/entities/PosMaster.ts @@ -137,15 +137,13 @@ export class PosMaster extends EntityBase { default: null, }) profileIdNextHolder: string; - + @Column({ length: 40, comment: "คีย์นอก(FK)ของตาราง orgRevision", }) orgRevisionId: string; //fk - - @ManyToOne(() => OrgRevision, (orgRevision) => orgRevision.posMasters) @JoinColumn({ name: "orgRevisionId" }) orgRevision: OrgRevision; @@ -170,12 +168,12 @@ export class PosMaster extends EntityBase { @JoinColumn({ name: "orgChild4Id" }) orgChild4: OrgChild4; - @ManyToOne(() => Profile, (profile) => profile.posMasters) - @JoinColumn({ name: "profileIdCurrentHolder" }) - profile: Profile; + @OneToOne(() => Profile) + @JoinColumn() + current_holder: Profile; - @ManyToOne(() => Profile, (profile) => profile.next_holder_posMasters) - @JoinColumn({ name: "profileIdNextHolder" }) + @OneToOne(() => Profile) + @JoinColumn() next_holder: Profile; @OneToMany(() => Position, (position) => position.posMaster) diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 38e328a7..44457737 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -1,4 +1,4 @@ -import { Entity, Column, OneToMany} from "typeorm"; +import { Entity, Column, OneToMany, OneToOne, JoinColumn} from "typeorm"; import { EntityBase } from "./base/Base"; import { PosMaster } from "./PosMaster"; @@ -36,11 +36,13 @@ export class Profile extends EntityBase { }) citizenId: string; - @OneToMany(() => PosMaster, (posMaster) => posMaster.profile) - posMasters: PosMaster[]; + @OneToOne(() => PosMaster) + @JoinColumn() + current_holder: PosMaster; - @OneToMany(() => PosMaster, (posMaster) => posMaster.next_holder) - next_holder_posMasters: PosMaster[]; + @OneToOne(() => PosMaster) + @JoinColumn() + next_holder: PosMaster; } export class CreateProfile {