edit status code
This commit is contained in:
parent
1384b41b9b
commit
4abee90c38
4 changed files with 309 additions and 321 deletions
|
|
@ -46,15 +46,15 @@ export class OrgChild3Controller {
|
|||
*/
|
||||
@Get("{id}")
|
||||
async GetChild3(@Path() id: string) {
|
||||
const orgChild3 = await this.child3Repository.findOne({ where: { id } });
|
||||
if (!orgChild3) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 3");
|
||||
}
|
||||
const orgRoot = await this.orgRootRepository.findOne({ where: { id: orgChild3.orgRootId } });
|
||||
if (!orgRoot) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root");
|
||||
}
|
||||
try {
|
||||
const orgChild3 = await this.child3Repository.findOne({ where: { id } });
|
||||
if (!orgChild3) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ 3");
|
||||
}
|
||||
const orgRoot = await this.orgRootRepository.findOne({ where: { id: orgChild3.orgRootId } });
|
||||
if (!orgRoot) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root");
|
||||
}
|
||||
const getOrgChild3 = {
|
||||
"orgChild3Id" : orgChild3.id,
|
||||
"orgChild3Name" : orgChild3.orgChild3Name,
|
||||
|
|
@ -85,30 +85,28 @@ export class OrgChild3Controller {
|
|||
@Body() requestBody: CreateOrgChild3,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const child2 = await this.child2Repository.findOne({
|
||||
where: { id: requestBody.orgChild2Id },
|
||||
});
|
||||
if (!child2) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child2.orgRevisionId },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
if(revisionIdExits.orgRevisionIsDraft != true && revisionIdExits.orgRevisionIsCurrent != false){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false");
|
||||
}
|
||||
|
||||
const validOrgChild3Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||
if (!validOrgChild3Ranks.includes(requestBody.orgChild3Rank.toUpperCase())) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild3Rank");
|
||||
}
|
||||
try {
|
||||
//BE ใช้ orgChild2Id หา orgChild1Id, orgRootId
|
||||
const child2 = await this.child2Repository.findOne({
|
||||
where: { id: requestBody.orgChild2Id },
|
||||
});
|
||||
if (!child2) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child2.orgRevisionId },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
if(revisionIdExits.orgRevisionIsDraft != true && revisionIdExits.orgRevisionIsCurrent != false){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false");
|
||||
}
|
||||
|
||||
const validOrgChild3Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||
if (!validOrgChild3Ranks.includes(requestBody.orgChild3Rank.toUpperCase())) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild3Rank");
|
||||
}
|
||||
|
||||
const child3 = Object.assign(new OrgChild3(), requestBody) as OrgChild3;
|
||||
child3.orgChild3Name = requestBody.orgChild3Name;
|
||||
child3.createdUserId = request.user.sub;
|
||||
|
|
@ -139,37 +137,36 @@ export class OrgChild3Controller {
|
|||
@Body() requestBody: UpdateOrgChild3,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const child2IdExits = await this.child2Repository.findOne({
|
||||
where: { id: requestBody.orgChild2Id },
|
||||
});
|
||||
if (!child2IdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child2Id");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child2IdExits.orgRevisionId },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
if(revisionIdExits.orgRevisionIsDraft != true && revisionIdExits.orgRevisionIsCurrent != false){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false");
|
||||
}
|
||||
|
||||
const validOrgChild3Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||
if (
|
||||
requestBody.orgChild3Rank == null ||
|
||||
!validOrgChild3Ranks.includes(requestBody.orgChild3Rank.toUpperCase())
|
||||
) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild2Rank");
|
||||
}
|
||||
|
||||
const child3 = await this.child3Repository.findOne({ where: { id } });
|
||||
if (!child3) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
try {
|
||||
const child2IdExits = await this.child2Repository.findOne({
|
||||
where: { id: requestBody.orgChild2Id },
|
||||
});
|
||||
if (!child2IdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. Child2Id");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child2IdExits.orgRevisionId },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
if(revisionIdExits.orgRevisionIsDraft != true && revisionIdExits.orgRevisionIsCurrent != false){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false");
|
||||
}
|
||||
|
||||
const validOrgChild3Ranks = ["OFFICE", "DIVISION", "SECTION"];
|
||||
if (
|
||||
requestBody.orgChild3Rank == null ||
|
||||
!validOrgChild3Ranks.includes(requestBody.orgChild3Rank.toUpperCase())
|
||||
) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgChild2Rank");
|
||||
}
|
||||
|
||||
const child3 = await this.child3Repository.findOne({ where: { id } });
|
||||
if (!child3) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
|
||||
child3.lastUpdateUserId = request.user.sub;
|
||||
child3.lastUpdateFullName = request.user.name;
|
||||
child3.lastUpdatedAt = new Date();
|
||||
|
|
@ -194,29 +191,29 @@ export class OrgChild3Controller {
|
|||
*/
|
||||
@Delete("{id}")
|
||||
async delete(@Path() id: string) {
|
||||
try {
|
||||
const child3 = await this.child3Repository.findOne({ where: { id } });
|
||||
if (!child3) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child3.orgRevisionId },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
if(revisionIdExits.orgRevisionIsDraft != true && revisionIdExits.orgRevisionIsCurrent != false){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false");
|
||||
}
|
||||
const child3 = await this.child3Repository.findOne({ where: { id } });
|
||||
if (!child3) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
|
||||
}
|
||||
|
||||
const revisionIdExits = await this.orgRevisionRepository.findOne({
|
||||
where: { id: child3.orgRevisionId },
|
||||
});
|
||||
if (!revisionIdExits) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
|
||||
}
|
||||
if(revisionIdExits.orgRevisionIsDraft != true && revisionIdExits.orgRevisionIsCurrent != false){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. orgRevisionIsDraft:true, orgRevisionIsCurrent:false");
|
||||
}
|
||||
|
||||
const exitsChild4 = await this.child4Repository.findOne({ where: { orgChild3Id: id } });
|
||||
if (exitsChild4) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ4",
|
||||
);
|
||||
}
|
||||
const exitsChild4 = await this.child4Repository.findOne({ where: { orgChild3Id: id } });
|
||||
if (exitsChild4) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ4",
|
||||
);
|
||||
}
|
||||
try {
|
||||
await this.child3Repository.remove(child3);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue