validate orgRevisionId (child2, 3, 4)
This commit is contained in:
parent
93683f897b
commit
5b5970cda2
3 changed files with 73 additions and 1 deletions
|
|
@ -19,6 +19,7 @@ import {
|
|||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
import { CreateOrgChild4, OrgChild4, UpdateOrgChild4 } from "../entities/OrgChild4";
|
||||
import { OrgChild1 } from "../entities/OrgChild1";
|
||||
import { OrgChild3 } from "../entities/OrgChild3";
|
||||
|
|
@ -34,6 +35,7 @@ import { OrgChild3 } from "../entities/OrgChild3";
|
|||
export class OrgChild4Controller extends Controller {
|
||||
private child3Repository = AppDataSource.getRepository(OrgChild3);
|
||||
private child4Repository = AppDataSource.getRepository(OrgChild4);
|
||||
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
|
||||
|
||||
/**
|
||||
* สร้างโครงสร้างระดับ4 Child4
|
||||
|
|
@ -68,6 +70,13 @@ export class OrgChild4Controller extends Controller {
|
|||
if (!child3) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child3.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
|
||||
const validOrgChild4Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||
if (!validOrgChild4Ranks.includes(requestBody.orgChild4Rank.toUpperCase())) {
|
||||
|
|
@ -128,6 +137,13 @@ export class OrgChild4Controller extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child3Id");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child3IdExits.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
|
||||
const validOrgChild4Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||
if (
|
||||
requestBody.orgChild4Rank == null ||
|
||||
|
|
@ -171,6 +187,14 @@ export class OrgChild4Controller extends Controller {
|
|||
if (!child4) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child4.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
|
||||
await this.child4Repository.remove(child4);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue