This commit is contained in:
AdisakKanthawilang 2024-04-25 18:45:22 +07:00
parent 404f4afb61
commit 72ac021b16

View file

@ -822,83 +822,85 @@ export class PositionController extends Controller {
SName = orgRoot.orgRootShortName; SName = orgRoot.orgRootShortName;
} }
const chk_SName0 = await this.posMasterRepository.findOne({ if (posMaster.orgRootId != null) {
where: { const chk_SName0 = await this.posMasterRepository.findOne({
orgRevisionId: posMaster.orgRevisionId, where: {
orgRoot: { orgRootShortName: SName }, orgRevisionId: posMaster.orgRevisionId,
orgChild1Id: IsNull(), orgRoot: { orgRootShortName: SName },
posMasterNo: requestBody.posMasterNo, orgChild1Id: IsNull(),
}, posMasterNo: requestBody.posMasterNo,
relations: ["orgRoot"], },
}); relations: ["orgRoot"],
if (chk_SName0 != null) { });
throw new HttpError( if (chk_SName0 != null) {
HttpStatusCode.INTERNAL_SERVER_ERROR, throw new HttpError(
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", HttpStatusCode.INTERNAL_SERVER_ERROR,
); "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
} );
}
const chk_SName1 = await this.posMasterRepository.findOne({ } else if (posMaster.orgChild1Id != null) {
where: { const chk_SName1 = await this.posMasterRepository.findOne({
orgRevisionId: posMaster.orgRevisionId, where: {
orgChild1: { orgChild1ShortName: SName }, orgRevisionId: posMaster.orgRevisionId,
orgChild2Id: IsNull(), orgChild1: { orgChild1ShortName: SName },
posMasterNo: requestBody.posMasterNo, orgChild2Id: IsNull(),
}, posMasterNo: requestBody.posMasterNo,
relations: ["orgChild1"], },
}); relations: ["orgChild1"],
if (chk_SName1 != null) { });
throw new HttpError( if (chk_SName1 != null) {
HttpStatusCode.INTERNAL_SERVER_ERROR, throw new HttpError(
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", HttpStatusCode.INTERNAL_SERVER_ERROR,
); "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
} );
}
const chk_SName2 = await this.posMasterRepository.findOne({ } else if (posMaster.orgChild2Id != null) {
where: { const chk_SName2 = await this.posMasterRepository.findOne({
orgRevisionId: posMaster.orgRevisionId, where: {
orgChild2: { orgChild2ShortName: SName }, orgRevisionId: posMaster.orgRevisionId,
orgChild3Id: IsNull(), orgChild2: { orgChild2ShortName: SName },
posMasterNo: requestBody.posMasterNo, orgChild3Id: IsNull(),
}, posMasterNo: requestBody.posMasterNo,
relations: ["orgChild2"], },
}); relations: ["orgChild2"],
if (chk_SName2 != null) { });
throw new HttpError( if (chk_SName2 != null) {
HttpStatusCode.INTERNAL_SERVER_ERROR, throw new HttpError(
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", HttpStatusCode.INTERNAL_SERVER_ERROR,
); "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
} );
}
const chk_SName3 = await this.posMasterRepository.findOne({ } else if (posMaster.orgChild3Id != null) {
where: { const chk_SName3 = await this.posMasterRepository.findOne({
orgRevisionId: posMaster.orgRevisionId, where: {
orgChild3: { orgChild3ShortName: SName }, orgRevisionId: posMaster.orgRevisionId,
orgChild4Id: IsNull(), orgChild3: { orgChild3ShortName: SName },
posMasterNo: requestBody.posMasterNo, orgChild4Id: IsNull(),
}, posMasterNo: requestBody.posMasterNo,
relations: ["orgChild3"], },
}); relations: ["orgChild3"],
if (chk_SName3 != null) { });
throw new HttpError( if (chk_SName3 != null) {
HttpStatusCode.INTERNAL_SERVER_ERROR, throw new HttpError(
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", HttpStatusCode.INTERNAL_SERVER_ERROR,
); "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
} );
}
const chk_SName4 = await this.posMasterRepository.findOne({ } else if (posMaster.orgChild4Id != null) {
where: { const chk_SName4 = await this.posMasterRepository.findOne({
orgRevisionId: posMaster.orgRevisionId, where: {
orgChild4: { orgChild4ShortName: SName }, orgRevisionId: posMaster.orgRevisionId,
posMasterNo: requestBody.posMasterNo, orgChild4: { orgChild4ShortName: SName },
}, posMasterNo: requestBody.posMasterNo,
relations: ["orgChild4"], },
}); relations: ["orgChild4"],
if (chk_SName4 != null) { });
throw new HttpError( if (chk_SName4 != null) {
HttpStatusCode.INTERNAL_SERVER_ERROR, throw new HttpError(
"ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้", HttpStatusCode.INTERNAL_SERVER_ERROR,
); "ไม่สามารถใส่เลขที่ตำแหน่งซ้ำกันได้",
);
}
} }
posMaster.createdUserId = request.user.sub; posMaster.createdUserId = request.user.sub;
@ -1065,7 +1067,7 @@ export class PositionController extends Controller {
orgChild3Id: body.id, orgChild3Id: body.id,
}; };
if (!body.isAll) { if (!body.isAll) {
checkChildConditions = { checkChildConditions = {
orgChild4Id: IsNull(), orgChild4Id: IsNull(),
}; };
searchShortName = `CONCAT(orgChild3.orgChild3ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`; searchShortName = `CONCAT(orgChild3.orgChild3ShortName,posMaster.posMasterNoPrefix,posMaster.posMasterNo,posMaster.posMasterNoSuffix) like '%${body.keyword}%'`;