fix api org_053 isAll ทำงานผิดพลาด

This commit is contained in:
AdisakKanthawilang 2024-02-12 10:57:35 +07:00
parent 0819836932
commit 1ed37b770c

View file

@ -36,7 +36,7 @@ import { Position } from "../entities/Position";
import { Brackets } from "typeorm/browser"; import { Brackets } from "typeorm/browser";
@Route("api/v1/org/pos") @Route("api/v1/org/pos")
@Tags("Position") @Tags("Position")
@Security("bearerAuth") // @Security("bearerAuth")
@Response( @Response(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
@ -426,7 +426,7 @@ export class PositionController extends Controller {
requestBody: CreatePosMaster, requestBody: CreatePosMaster,
@Request() request: { user: Record<string, any> }, @Request() request: { user: Record<string, any> },
) { ) {
let posMaster = await this.posMasterRepository.findOne({ where: { id: id } }); const posMaster = await this.posMasterRepository.findOne({ where: { id: id } });
if (!posMaster) { if (!posMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลอัตรากำลัง");
} }
@ -435,9 +435,6 @@ export class PositionController extends Controller {
posMaster.orgChild2Id = null; posMaster.orgChild2Id = null;
posMaster.orgChild3Id = null; posMaster.orgChild3Id = null;
posMaster.orgChild4Id = null; posMaster.orgChild4Id = null;
posMaster.posMasterNo = requestBody.posMasterNo;
posMaster.posMasterNoPrefix = requestBody.posMasterNoPrefix;
posMaster.posMasterNoSuffix = requestBody.posMasterNoSuffix;
let orgRoot: any = null; let orgRoot: any = null;
if (requestBody.orgRootId != null) if (requestBody.orgRootId != null)
@ -517,7 +514,7 @@ export class PositionController extends Controller {
position.positionExecutiveField = x.posDictExecutiveField; position.positionExecutiveField = x.posDictExecutiveField;
position.positionArea = x.posDictArea; position.positionArea = x.posDictArea;
position.positionIsSelected = false; position.positionIsSelected = false;
position.posMasterId = posMaster?.id; position.posMasterId = posMaster.id;
position.createdUserId = request.user.sub; position.createdUserId = request.user.sub;
position.createdFullName = request.user.name; position.createdFullName = request.user.name;
position.lastUpdateUserId = request.user.sub; position.lastUpdateUserId = request.user.sub;
@ -745,49 +742,52 @@ export class PositionController extends Controller {
relations: ["posLevel", "posType", "posExecutive"], relations: ["posLevel", "posType", "posExecutive"],
}); });
let shortName = "-";
if (body.isAll === true) { if (body.isAll === true) {
if ( if (
posMaster.orgRootId !== null && posMaster.orgRootId !== null &&
posMaster.orgChild1Id == null && posMaster.orgChild1Id == null &&
posMaster.orgChild2Id == null && posMaster.orgChild2Id == null &&
posMaster.orgChild2Id == null &&
posMaster.orgChild3Id == null posMaster.orgChild3Id == null
) { ) {
body.type = 0; body.type = 0;
shortName = posMaster.orgRoot.orgRootShortName;
} else if ( } else if (
posMaster.orgRootId !== null && posMaster.orgRootId !== null &&
posMaster.orgChild1Id !== null && posMaster.orgChild1Id !== null &&
posMaster.orgChild2Id == null && posMaster.orgChild2Id == null &&
posMaster.orgChild2Id == null &&
posMaster.orgChild3Id == null posMaster.orgChild3Id == null
) { ) {
body.type = 1; body.type = 1;
shortName = posMaster.orgChild1.orgChild1ShortName;
} else if ( } else if (
posMaster.orgRootId !== null && posMaster.orgRootId !== null &&
posMaster.orgChild1Id !== null && posMaster.orgChild1Id !== null &&
posMaster.orgChild2Id !== null && posMaster.orgChild2Id !== null &&
posMaster.orgChild2Id == null &&
posMaster.orgChild3Id == null posMaster.orgChild3Id == null
) { ) {
body.type = 2; body.type = 2;
shortName = posMaster.orgChild2.orgChild2ShortName;
} else if ( } else if (
posMaster.orgRootId !== null && posMaster.orgRootId !== null &&
posMaster.orgChild1Id !== null && posMaster.orgChild1Id !== null &&
posMaster.orgChild2Id !== null && posMaster.orgChild2Id !== null &&
posMaster.orgChild2Id !== null && posMaster.orgChild3Id !== null
posMaster.orgChild3Id == null
) { ) {
body.type = 3; body.type = 3;
shortName = posMaster.orgChild3.orgChild3ShortName;
} else if ( } else if (
posMaster.orgRootId !== null && posMaster.orgRootId !== null &&
posMaster.orgChild1Id !== null && posMaster.orgChild1Id !== null &&
posMaster.orgChild2Id !== null && posMaster.orgChild2Id !== null &&
posMaster.orgChild2Id !== null &&
posMaster.orgChild3Id !== null posMaster.orgChild3Id !== null
) { ) {
body.type = 4; body.type = 4;
shortName = posMaster.orgChild4.orgChild4ShortName;
} }
} }
return { return {
id: posMaster.id, id: posMaster.id,
orgRootId: posMaster.orgRootId, orgRootId: posMaster.orgRootId,
@ -806,18 +806,7 @@ export class PositionController extends Controller {
posMaster.next_holder == null posMaster.next_holder == null
? null ? null
: `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`, : `${posMaster.next_holder.prefix}${posMaster.next_holder.firstName} ${posMaster.next_holder.lastName}`,
orgShortname: orgShortname: shortName,
body.type === 0
? posMaster.orgRoot.orgRootShortName
: body.type === 1
? posMaster.orgChild1.orgChild1ShortName
: body.type === 2
? posMaster.orgChild2.orgChild2ShortName
: body.type === 3
? posMaster.orgChild3.orgChild3ShortName
: body.type === 4
? posMaster.orgChild4.orgChild4ShortName
: "-",
positions: positions.map((position) => ({ positions: positions.map((position) => ({
id: position.id, id: position.id,
positionName: position.positionName, positionName: position.positionName,
@ -1140,7 +1129,7 @@ export class PositionController extends Controller {
* *
*/ */
@Post("summary") @Post("summary")
async PositionSummary(@Body() requestBody: { id: string; type: number; isNode: boolean }) { async PositionSummary(@Body() requestBody: { id: string; type: number }) {
try { try {
let summary: any; let summary: any;
let totalPosition: any; let totalPosition: any;
@ -1149,517 +1138,204 @@ export class PositionController extends Controller {
let totalPositionNextUse: any; let totalPositionNextUse: any;
let totalPositionNextVacant: any; let totalPositionNextVacant: any;
if(requestBody.isNode === true){ switch (requestBody.type) {
switch (requestBody.type) { case 0: {
case 0: { const NodeId = await this.posMasterRepository.findOne({
const NodeId = await this.posMasterRepository.findOne({ where: { orgRootId: requestBody.id },
where: { orgRootId: requestBody.id }, });
}); if (!NodeId) {
if (!NodeId) { throw new HttpError(
throw new HttpError( HttpStatusCode.NOT_FOUND,
HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id, );
);
}
totalPosition = await this.posMasterRepository.count({
where: { orgRootId: requestBody.id },
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
next_holderId: IsNull() && "",
},
});
break;
} }
case 1: { totalPosition = await this.posMasterRepository.count({
const NodeId = await this.posMasterRepository.findOne({ where: { orgRootId: requestBody.id },
where: { orgChild1Id: requestBody.id }, });
}); totalPositionCurrentUse = await this.posMasterRepository.count({
if (!NodeId) { where: {
throw new HttpError( orgRootId: requestBody.id,
HttpStatusCode.NOT_FOUND, current_holderId: Not(IsNull()) && Not(""),
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id, },
); });
} totalPositionCurrentVacant = await this.posMasterRepository.count({
totalPosition = await this.posMasterRepository.count({ where: {
where: { orgChild1Id: requestBody.id }, orgRootId: requestBody.id,
}); current_holderId: IsNull() && "",
totalPositionCurrentUse = await this.posMasterRepository.count({ },
where: { });
orgChild1Id: requestBody.id, totalPositionNextUse = await this.posMasterRepository.count({
current_holderId: Not(IsNull()) && Not(""), where: {
}, orgRootId: requestBody.id,
}); next_holderId: Not(IsNull()) && Not(""),
totalPositionCurrentVacant = await this.posMasterRepository.count({ },
where: { });
orgChild1Id: requestBody.id, totalPositionNextVacant = await this.posMasterRepository.count({
current_holderId: IsNull() && "", where: {
}, orgRootId: requestBody.id,
}); next_holderId: IsNull() && "",
totalPositionNextUse = await this.posMasterRepository.count({ },
where: { });
orgChild1Id: requestBody.id, break;
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild1Id: requestBody.id,
next_holderId: IsNull() && "",
},
});
break;
}
case 2: {
const NodeId = await this.posMasterRepository.findOne({
where: { orgChild2Id: requestBody.id },
});
if (!NodeId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
);
}
totalPosition = await this.posMasterRepository.count({
where: { orgChild2Id: requestBody.id },
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
next_holderId: IsNull() && "",
},
});
break;
}
case 3: {
const NodeId = await this.posMasterRepository.findOne({
where: { orgChild3Id: requestBody.id },
});
if (!NodeId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
);
}
totalPosition = await this.posMasterRepository.count({
where: { orgChild3Id: requestBody.id },
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
next_holderId: IsNull() && "",
},
});
break;
}
case 4: {
const NodeId = await this.posMasterRepository.findOne({
where: { orgChild4Id: requestBody.id },
});
if (!NodeId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
);
}
totalPosition = await this.posMasterRepository.count({
where: { orgChild4Id: requestBody.id },
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
next_holderId: IsNull() && "",
},
});
break;
}
default:
break;
} }
} case 1: {
else { const NodeId = await this.posMasterRepository.findOne({
switch (requestBody.type) { where: { orgChild1Id: requestBody.id },
case 0: { });
const NodeId = await this.posMasterRepository.findOne({ if (!NodeId) {
where: { orgRootId: requestBody.id }, throw new HttpError(
}); HttpStatusCode.NOT_FOUND,
if (!NodeId) { "ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
throw new HttpError( );
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
);
}
totalPosition = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
orgChild1Id : IsNull() || "",
orgChild2Id : IsNull() || "",
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
},
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
orgChild1Id : IsNull() || "",
orgChild2Id : IsNull() || "",
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
current_holderId: Not(IsNull()) || Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
orgChild1Id : IsNull() || "",
orgChild2Id : IsNull() || "",
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
current_holderId: IsNull() || "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
orgChild1Id : IsNull() || "",
orgChild2Id : IsNull() || "",
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
next_holderId: Not(IsNull()) || Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgRootId: requestBody.id,
orgChild1Id : IsNull() || "",
orgChild2Id : IsNull() || "",
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
next_holderId: IsNull() || "",
},
});
break;
} }
case 1: { totalPosition = await this.posMasterRepository.count({
const NodeId = await this.posMasterRepository.findOne({ where: { orgChild1Id: requestBody.id },
where: { orgChild1Id: requestBody.id }, });
}); totalPositionCurrentUse = await this.posMasterRepository.count({
if (!NodeId) { where: {
throw new HttpError( orgChild1Id: requestBody.id,
HttpStatusCode.NOT_FOUND, current_holderId: Not(IsNull()) && Not(""),
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id, },
); });
} totalPositionCurrentVacant = await this.posMasterRepository.count({
totalPosition = await this.posMasterRepository.count({ where: {
where: { orgChild1Id: requestBody.id,
orgRootId: Not(IsNull()) || Not(""), current_holderId: IsNull() && "",
orgChild1Id : requestBody.id, },
orgChild2Id : IsNull() || "", });
orgChild3Id : IsNull() || "", totalPositionNextUse = await this.posMasterRepository.count({
orgChild4Id : IsNull() || "", where: {
}, orgChild1Id: requestBody.id,
}); next_holderId: Not(IsNull()) && Not(""),
totalPositionCurrentUse = await this.posMasterRepository.count({ },
where: { });
orgRootId: Not(IsNull()) || Not(""), totalPositionNextVacant = await this.posMasterRepository.count({
orgChild1Id : requestBody.id, where: {
orgChild2Id : IsNull() || "", orgChild1Id: requestBody.id,
orgChild3Id : IsNull() || "", next_holderId: IsNull() && "",
orgChild4Id : IsNull() || "", },
current_holderId: Not(IsNull()) && Not(""), });
}, break;
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : requestBody.id,
orgChild2Id : IsNull() || "",
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : requestBody.id,
orgChild2Id : IsNull() || "",
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : requestBody.id,
orgChild2Id : IsNull() || "",
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
next_holderId: IsNull() && "",
},
});
break;
}
case 2: {
const NodeId = await this.posMasterRepository.findOne({
where: { orgChild2Id: requestBody.id },
});
if (!NodeId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
);
}
totalPosition = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : requestBody.id,
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
},
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : requestBody.id,
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : requestBody.id,
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : requestBody.id,
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : requestBody.id,
orgChild3Id : IsNull() || "",
orgChild4Id : IsNull() || "",
next_holderId: IsNull() && "",
},
});
break;
}
case 3: {
const NodeId = await this.posMasterRepository.findOne({
where: { orgChild3Id: requestBody.id },
});
if (!NodeId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
);
}
totalPosition = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : requestBody.id,
orgChild4Id : IsNull() || "",
},
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : requestBody.id,
orgChild4Id : IsNull() || "",
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : requestBody.id,
orgChild4Id : IsNull() || "",
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : requestBody.id,
orgChild4Id : IsNull() || "",
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : requestBody.id,
orgChild4Id : IsNull() || "",
next_holderId: IsNull() && "",
},
});
break;
}
case 4: {
const NodeId = await this.posMasterRepository.findOne({
where: { orgChild4Id: requestBody.id },
});
if (!NodeId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
);
}
totalPosition = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : Not(IsNull()) || Not(""),
orgChild4Id : requestBody.id,
},
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : Not(IsNull()) || Not(""),
orgChild4Id : requestBody.id,
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : Not(IsNull()) || Not(""),
orgChild4Id : requestBody.id,
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : Not(IsNull()) || Not(""),
orgChild4Id : requestBody.id,
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgRootId: Not(IsNull()) || Not(""),
orgChild1Id : Not(IsNull()) || Not(""),
orgChild2Id : Not(IsNull()) || Not(""),
orgChild3Id : Not(IsNull()) || Not(""),
orgChild4Id : requestBody.id,
next_holderId: IsNull() && "",
},
});
break;
}
default:
break;
} }
case 2: {
const NodeId = await this.posMasterRepository.findOne({
where: { orgChild2Id: requestBody.id },
});
if (!NodeId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
);
}
totalPosition = await this.posMasterRepository.count({
where: { orgChild2Id: requestBody.id },
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild2Id: requestBody.id,
next_holderId: IsNull() && "",
},
});
break;
}
case 3: {
const NodeId = await this.posMasterRepository.findOne({
where: { orgChild3Id: requestBody.id },
});
if (!NodeId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
);
}
totalPosition = await this.posMasterRepository.count({
where: { orgChild3Id: requestBody.id },
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild3Id: requestBody.id,
next_holderId: IsNull() && "",
},
});
break;
}
case 4: {
const NodeId = await this.posMasterRepository.findOne({
where: { orgChild4Id: requestBody.id },
});
if (!NodeId) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลตามไอดีนี้ : " + requestBody.id,
);
}
totalPosition = await this.posMasterRepository.count({
where: { orgChild4Id: requestBody.id },
});
totalPositionCurrentUse = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
current_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionCurrentVacant = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
current_holderId: IsNull() && "",
},
});
totalPositionNextUse = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
next_holderId: Not(IsNull()) && Not(""),
},
});
totalPositionNextVacant = await this.posMasterRepository.count({
where: {
orgChild4Id: requestBody.id,
next_holderId: IsNull() && "",
},
});
break;
}
default:
break;
} }
summary = { summary = {