validate orgRevisionId (child2, 3, 4)
This commit is contained in:
parent
93683f897b
commit
5b5970cda2
3 changed files with 73 additions and 1 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { AppDataSource } from "../database/data-source";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
import { OrgChild2 } from "../entities/OrgChild2";
|
||||
import { OrgChild3, CreateOrgChild3, UpdateOrgChild3 } from "../entities/OrgChild3";
|
||||
import { OrgChild4 } from "../entities/OrgChild4";
|
||||
|
|
@ -32,7 +33,8 @@ export class OrgChild3Controller {
|
|||
private child2Repository = AppDataSource.getRepository(OrgChild2);
|
||||
private child3Repository = AppDataSource.getRepository(OrgChild3);
|
||||
private child4Repository = AppDataSource.getRepository(OrgChild4);
|
||||
|
||||
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
|
||||
|
||||
/**
|
||||
* API สร้างโครงสร้างระดับ3
|
||||
*
|
||||
|
|
@ -53,6 +55,13 @@ export class OrgChild3Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child2.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
|
||||
const validOrgChild3Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||
if (!validOrgChild3Ranks.includes(requestBody.orgChild3Rank.toUpperCase())) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild3Rank");
|
||||
|
|
@ -96,6 +105,13 @@ export class OrgChild3Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child2Id");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child2IdExits.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
|
||||
const validOrgChild3Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||
if (
|
||||
requestBody.orgChild3Rank == null ||
|
||||
|
|
@ -138,6 +154,14 @@ export class OrgChild3Controller {
|
|||
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 exitsChild4 = await this.child4Repository.findOne({ where: { orgChild3Id: id } });
|
||||
if (exitsChild4) {
|
||||
throw new HttpError(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue