add isDeputy

This commit is contained in:
kittapath 2024-10-21 17:11:21 +07:00
parent 96edba3c08
commit 7aeafcd723
4 changed files with 83 additions and 0 deletions

View file

@ -72,6 +72,7 @@ export class OrgRootController extends Controller {
orgRootPhoneIn: orgRoot.orgRootPhoneIn,
orgRootFax: orgRoot.orgRootFax,
orgRevisionId: orgRoot.orgRevisionId,
isDeputy: orgRoot.isDeputy,
orgCode: orgRoot.orgRootCode + "00",
};
return new HttpSuccess(getOrgRoot);
@ -102,6 +103,24 @@ export class OrgRootController extends Controller {
@Request() request: RequestWithUser,
) {
await new permission().PermissionCreate(request, "SYS_ORG");
if (requestBody.isDeputy == true) {
const orgRevision = await this.orgRevisionRepository.findOne({
where: { id: requestBody.orgRevisionId },
relations: ["orgRoots"],
});
if (orgRevision != null) {
await Promise.all(
orgRevision.orgRoots
.filter((x: OrgRoot) => x.isDeputy == true)
.map(async (item: OrgRoot) => {
item.isDeputy = false;
await this.orgRootRepository.save(item);
}),
);
}
}
const validOrgRootRanks = ["DEPARTMENT", "OFFICE", "DIVISION", "SECTION"];
if (!validOrgRootRanks.includes(requestBody.orgRootRank.toUpperCase())) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRootRank");
@ -193,6 +212,23 @@ export class OrgRootController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRo otRank");
}
if (requestBody.isDeputy == true) {
const orgRevision = await this.orgRevisionRepository.findOne({
where: { id: requestBody.orgRevisionId },
relations: ["orgRoots"],
});
if (orgRevision != null) {
await Promise.all(
orgRevision.orgRoots
.filter((x: OrgRoot) => x.isDeputy == true)
.map(async (item: OrgRoot) => {
item.isDeputy = false;
await this.orgRootRepository.save(item);
}),
);
}
}
const revisionIdExits = await this.orgRevisionRepository.findOne({
where: { id: requestBody.orgRevisionId },
});