diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 8c383207..f134b7dd 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -944,7 +944,7 @@ export class PositionController extends Controller { let checkChildConditions: any = {}; let keywordAsInt: any; let searchShortName = ""; - let labelName = ""; + let labelName = ""; let searchShortName0 = `CONCAT(orgRoot.orgRootShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let searchShortName1 = `CONCAT(orgChild1.orgChild1ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; let searchShortName2 = `CONCAT(orgChild2.orgChild2ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix)`; @@ -1067,6 +1067,7 @@ export class PositionController extends Controller { .leftJoinAndSelect("posMaster.orgChild4", "orgChild4") .leftJoinAndSelect("posMaster.current_holder", "current_holder") .leftJoinAndSelect("posMaster.next_holder", "next_holder") + .leftJoinAndSelect("posMaster.orgRevision", "orgRevision") .where(conditions) .orWhere( new Brackets((qb) => { @@ -1079,7 +1080,7 @@ export class PositionController extends Controller { ) .andWhere(checkChildConditions) .andWhere(typeCondition) - .andWhere(revisionCondition) + .andWhere(revisionCondition); }), ) .orWhere( @@ -1101,7 +1102,7 @@ export class PositionController extends Controller { new Brackets((qb) => { qb.andWhere( body.keyword != null && body.keyword != "" - ? `CONCAT(next_holder.prefix, next_holder.firstName," ",next_holder.lastName) like '%${body.keyword}%'` + ? `CASE WHEN orgRevision.orgRevisionIsDraft = true THEN CONCAT(next_holder.prefix, next_holder.firstName,' ', next_holder.lastName) ELSE CONCAT(current_holder.prefix, current_holder.firstName,' ' , current_holder.lastName) END LIKE '%${body.keyword}%'` : "1=1", { keyword: `%${body.keyword}%`, @@ -1513,51 +1514,56 @@ export class PositionController extends Controller { posMaster.orgChild4Id = org.id; posMaster.orgRevisionId = org.orgRevisionId; } - } - const type0LastPosMasterNo = requestBody.type == 0 - ? await this.posMasterRepository.find({ - where: { - orgRootId: requestBody.id, - orgChild1Id: IsNull(), - }, - }) - : []; - - const type1LastPosMasterNo = requestBody.type == 1 - ? await this.posMasterRepository.find({ - where: { - orgChild1Id: requestBody.id, - orgChild2Id: IsNull(), - }, - }) - : []; - - const type2LastPosMasterNo = requestBody.type == 2 - ? await this.posMasterRepository.find({ - where: { - orgChild2Id: requestBody.id, - orgChild3Id: IsNull(), - }, - }) - : []; - - const type3LastPosMasterNo = requestBody.type == 3 - ? await this.posMasterRepository.find({ - where: { - orgChild3Id: requestBody.id, - orgChild4Id: IsNull(), - }, - }) - : []; - - const type4LastPosMasterNo = requestBody.type == 4 - ? await this.posMasterRepository.find({ - where: { - orgChild4Id: requestBody.id, - }, - }) - : []; - + } + const type0LastPosMasterNo = + requestBody.type == 0 + ? await this.posMasterRepository.find({ + where: { + orgRootId: requestBody.id, + orgChild1Id: IsNull(), + }, + }) + : []; + + const type1LastPosMasterNo = + requestBody.type == 1 + ? await this.posMasterRepository.find({ + where: { + orgChild1Id: requestBody.id, + orgChild2Id: IsNull(), + }, + }) + : []; + + const type2LastPosMasterNo = + requestBody.type == 2 + ? await this.posMasterRepository.find({ + where: { + orgChild2Id: requestBody.id, + orgChild3Id: IsNull(), + }, + }) + : []; + + const type3LastPosMasterNo = + requestBody.type == 3 + ? await this.posMasterRepository.find({ + where: { + orgChild3Id: requestBody.id, + orgChild4Id: IsNull(), + }, + }) + : []; + + const type4LastPosMasterNo = + requestBody.type == 4 + ? await this.posMasterRepository.find({ + where: { + orgChild4Id: requestBody.id, + }, + }) + : []; + const allLastPosMasterNo = [ ...type0LastPosMasterNo, ...type1LastPosMasterNo, @@ -1565,16 +1571,10 @@ export class PositionController extends Controller { ...type3LastPosMasterNo, ...type4LastPosMasterNo, ]; - - const maxPosMasterNo = Math.max( - ...allLastPosMasterNo.map((pos) => pos.posMasterNo), - 0 - ); - const maxPosMasterOrder = Math.max( - ...allLastPosMasterNo.map((pos) => pos.posMasterOrder), - 0 - ); + const maxPosMasterNo = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterNo), 0); + + const maxPosMasterOrder = Math.max(...allLastPosMasterNo.map((pos) => pos.posMasterOrder), 0); posMaster.posMasterNo = maxPosMasterNo + 1; posMaster.posMasterOrder = maxPosMasterOrder + 1; diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 3da9ec80..3e44e046 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -384,7 +384,7 @@ export class ProfileController extends Controller { .andWhere( new Brackets((qb) => { qb.where("next_holders.id IS NULL").orWhere("next_holders.id NOT IN (:...ids)", { - ids: orgRevision.posMasters.map((x) => x.id), + ids: orgRevision.posMasters.map((x) => x.next_holderId), }); }), ) diff --git a/src/entities/PosDict.ts b/src/entities/PosDict.ts index 51bb8199..544d860a 100644 --- a/src/entities/PosDict.ts +++ b/src/entities/PosDict.ts @@ -79,25 +79,25 @@ export class PosDict extends EntityBase { export class CreatePosDict { @Column() - posDictName: string; + posDictName: string | null; @Column() - posDictField: string; + posDictField: string | null; @Column("uuid") - posTypeId: string; + posTypeId: string | null; @Column("uuid") - posLevelId: string; + posLevelId: string | null; @Column() - posExecutiveId?: string; + posExecutiveId?: string | null; @Column() - posDictExecutiveField: string; + posDictExecutiveField: string | null; @Column() - posDictArea: string; + posDictArea: string | null; @Column() isSpecial: boolean;