diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 4e862e9b..cef27dcb 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -99,7 +99,10 @@ export class PositionController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล PosLevelId"); } - if (requestBody.posExecutiveId != "") requestBody.posExecutiveId = null; + if (requestBody.posExecutiveId == "") { + requestBody.posExecutiveId = null; + posDict.posExecutiveId = null; + } if (requestBody.posExecutiveId != null) { const checkPosExecutiveId = await this.posExecutiveRepository.findOne({ diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index d1eba316..98a33072 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -82,6 +82,10 @@ export class ReportController extends Controller { relations: [ "posMasters", "posMasters.next_holder", + "posMasters.next_holder.posLevel", + "posMasters.next_holder.posType", + "posMasters.next_holder.current_holders", + "posMasters.next_holder.current_holders.positions", "posMasters.positions", "posMasters.positions.posLevel", "posMasters.positions.posType", @@ -181,18 +185,18 @@ export class ReportController extends Controller { if (_orgRevisionActive.length > 0) orgRevisionActive = _orgRevisionActive[0]; } - const posMasterOlds = await this.posMasterRepository.find({ - where: { - orgRevisionId: orgRevisionActive.id, - }, - relations: ["next_holder", "current_holder"], - }); - const positionOlds = await this.positionRepository.find({ - where: { - posMasterId: In(posMasterOlds.map((posMaster: any) => posMaster.id)), - }, - relations: ["posLevel", "posType", "posExecutive"], - }); + // const posMasterOlds = await this.posMasterRepository.find({ + // where: { + // orgRevisionId: orgRevisionActive.id, + // }, + // relations: ["next_holder", "current_holder"], + // }); + // const positionOlds = await this.positionRepository.find({ + // where: { + // posMasterId: In(posMasterOlds.map((posMaster: any) => posMaster.id)), + // }, + // relations: ["posLevel", "posType", "posExecutive"], + // }); let data = new Array(); for (let orgRoot of orgRootData) { @@ -237,6 +241,11 @@ export class ReportController extends Controller { ...new Set(posMaster.positions.map((x) => x.posLevel.posLevelName)), ]; const positionField = [...new Set(posMaster.positions.map((x) => x.positionField))]; + const positionMasterOld = posMaster.next_holder.current_holders.find( + (x) => x == orgRevisionActive, + ); + console.log(orgRevisionActive); + console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); return { posMasterNoPrefix: posMaster.posMasterNoPrefix, posMasterNo: posMaster.posMasterNo, @@ -245,13 +254,37 @@ export class ReportController extends Controller { posMaster.next_holder == null ? "- ว่าง -" : `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, - profilePosMasterNo: posMaster.next_holder == null ? null : "xxx", + + // profilePosMasterNo: + // posMaster.next_holder == null + // ? posMaster.posMasterNo + // : positionMasterOld == null + // ? null + // : positionMasterOld.posMasterNo, profilePositionName: - posMaster.next_holder == null ? positionName.join(" หรือ ") : "xxx", - profilePosType: posMaster.next_holder == null ? posType.join(" หรือ ") : "xxx", - profilePosLevel: posMaster.next_holder == null ? posLevel.join(" หรือ ") : "xxx", - profilePositionField: - posMaster.next_holder == null ? positionField.join(" หรือ ") : "xxx", + posMaster.next_holder == null + ? positionName.join(" หรือ ") + : posMaster.next_holder.position, + profilePosType: + posMaster.next_holder == null + ? posType.join(" หรือ ") + : posMaster.next_holder.posType == null + ? null + : posMaster.next_holder.posType.posTypeName, + profilePosLevel: + posMaster.next_holder == null + ? posLevel.join(" หรือ ") + : posMaster.next_holder.posLevel == null + ? null + : posMaster.next_holder.posLevel.posLevelName, + // profilePositionField: + // posMaster.next_holder == null + // ? positionField.join(" หรือ ") + // : positionMasterOld == null + // ? null + // : positionMasterOld.positions.find((x) => (x.positionIsSelected = true)) + // ?.positionField, + // profilePosMasterNo: (posMasterOld == null ? null : posMasterOld.posMasterNo), // profilePositionName: (positionOld == null ? null : positionOld.positionName), // profilePosType: (positionOld == null ? null : positionOld.posType.posTypeName), diff --git a/src/entities/PosDict.ts b/src/entities/PosDict.ts index b00c08eb..f005d84a 100644 --- a/src/entities/PosDict.ts +++ b/src/entities/PosDict.ts @@ -40,7 +40,7 @@ export class PosDict extends EntityBase { comment: "ตำแหน่งทางการบริหาร", default: null, }) - posExecutiveId: string; + posExecutiveId: string | null; @Column({ nullable: true, @@ -85,7 +85,7 @@ export class CreatePosDict { posLevelId: string; @Column() - posExecutiveId?: string | null; + posExecutiveId: string | null; @Column() posDictExecutiveField: string; diff --git a/src/entities/PosLevel.ts b/src/entities/PosLevel.ts index 7aa39537..94683855 100644 --- a/src/entities/PosLevel.ts +++ b/src/entities/PosLevel.ts @@ -54,8 +54,8 @@ export class PosLevel extends EntityBase { @OneToMany(() => PosDict, (posDict) => posDict.posLevel) posDicts: PosDict[]; - @OneToMany(() => Profile, (profile) => profile.posLevelsId) - posLevelId: Profile; + @OneToMany(() => Profile, (profile) => profile.posLevel) + posLevels: Profile[]; } export class CreatePosLevel { @@ -73,4 +73,3 @@ export class CreatePosLevel { } export type UpdatePosLevel = Partial & { posLevelAuthority?: PosLevelAuthority }; - diff --git a/src/entities/PosType.ts b/src/entities/PosType.ts index 3dd7934a..e8fc862f 100644 --- a/src/entities/PosType.ts +++ b/src/entities/PosType.ts @@ -32,8 +32,8 @@ export class PosType extends EntityBase { @OneToMany(() => PosDict, (posDict) => posDict.posType) posDicts: PosDict[]; - @OneToMany(() => Profile, (profile) => profile.posTypesId) - posTypeId: Profile; + @OneToMany(() => Profile, (profile) => profile.posType) + posTypes: Profile[]; } export class CreatePosType { diff --git a/src/entities/Profile.ts b/src/entities/Profile.ts index 3976af93..9741cb11 100644 --- a/src/entities/Profile.ts +++ b/src/entities/Profile.ts @@ -86,13 +86,13 @@ export class Profile extends EntityBase { @OneToMany(() => PosMaster, (posMaster) => posMaster.next_holder) next_holders: PosMaster[]; - @ManyToOne(() => PosLevel, (posLevel) => posLevel.posLevelId) + @ManyToOne(() => PosLevel, (posLevel) => posLevel.posLevels) @JoinColumn({ name: "posLevelId" }) - posLevelsId: PosLevel; + posLevel: PosLevel; - @ManyToOne(() => PosType, (posType) => posType.posTypeId) + @ManyToOne(() => PosType, (posType) => posType.posTypes) @JoinColumn({ name: "posTypeId" }) - posTypesId: PosType; + posType: PosType; } export class CreateProfile {