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 { CreateOrgChild2, OrgChild2, UpdateOrgChild2 } from "../entities/OrgChild2";
|
||||
import { OrgChild1 } from "../entities/OrgChild1";
|
||||
import { OrgChild3 } from "../entities/OrgChild3";
|
||||
|
|
@ -34,6 +35,7 @@ export class OrgChild2Controller extends Controller {
|
|||
private child1Repository = AppDataSource.getRepository(OrgChild1);
|
||||
private child2Repository = AppDataSource.getRepository(OrgChild2);
|
||||
private child3Repository = AppDataSource.getRepository(OrgChild3);
|
||||
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
|
||||
|
||||
/**
|
||||
* สร้างโครงสร้างระดับ2 Child2
|
||||
|
|
@ -69,6 +71,13 @@ export class OrgChild2Controller extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child1.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
|
||||
const validOrgChild2Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||
if (!validOrgChild2Ranks.includes(requestBody.orgChild2Rank.toUpperCase())) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild2Rank");
|
||||
|
|
@ -125,6 +134,13 @@ export class OrgChild2Controller extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child1Id");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child1IdExits.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
|
||||
const validOrgChild2Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||
if (
|
||||
requestBody.orgChild2Rank == null ||
|
||||
|
|
@ -166,6 +182,14 @@ export class OrgChild2Controller extends Controller {
|
|||
if (!child2) {
|
||||
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 exitsChild3 = await this.child3Repository.findOne({ where: { orgChild2Id: id } });
|
||||
if (exitsChild3) {
|
||||
throw new HttpError(
|
||||
|
|
|
|||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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