org_010 - 012

This commit is contained in:
Bright 2024-01-25 15:54:03 +07:00
parent 55119a72f5
commit 6d136f8a97
4 changed files with 195 additions and 28 deletions

View file

@ -1,7 +1,6 @@
import { AppDataSource } from "../database/data-source";
import { OrgChild1, CreateOrgChild1, UpdateOrgChild1 } from "../entities/OrgChild1";
import { OrgChild2 } from "../entities/OrgChild2";
import {
Body,
Delete,
@ -28,7 +27,6 @@ import HttpError from "../interfaces/http-error";
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class OrgChild1Controller {
private child1Repository = AppDataSource.getRepository(OrgChild1);
private child2Repository = AppDataSource.getRepository(OrgChild2);
@ -84,6 +82,14 @@ export class OrgChild1Controller {
@Request() request: { user: Record<string, any> },
) {
try {
const chkOrder = await this.child1Repository.findOne({ where: { id: id, orgChild1Order:requestBody.orgChild1Order }});
if (chkOrder != null){
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const chkCode = await this.child1Repository.findOne({ where: { id: id, orgChild1Code:requestBody.orgChild1Code }});
if (chkCode != null){
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const child1 = await this.child1Repository.findOne({ where: { id } });
if (!child1){
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
@ -115,9 +121,9 @@ export class OrgChild1Controller {
if (!child1) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const exitsChild2 = await this.child2Repository.findOne({ where: { orgChild1Id: id } });
const exitsChild2 = await this.child2Repository.findOne({ where: { orgChild1Id: id } });
if(exitsChild2){
throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ2");
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้ เนื่องจาก id ผูกกับโครงสร้างระดับ2");
}
await this.child1Repository.remove(child1);
return new HttpSuccess();