fix Orgcontroller

This commit is contained in:
AdisakKanthawilang 2024-01-26 12:00:43 +07:00
parent aca680f4f4
commit 22324853db
4 changed files with 7 additions and 12 deletions

View file

@ -82,7 +82,7 @@ export class OrgChild1Controller {
const chkCode = await this.child1Repository.findOne({
where: { id: id, orgChild1Code: requestBody.orgChild1Code },
});
if (chkCode != null) {
if (chkCode?.id != id && chkCode != null) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
const child1 = await this.child1Repository.findOne({ where: { id } });

View file

@ -157,7 +157,7 @@ export class OrgChild2Controller extends Controller {
async delete(@Path() id: string) {
try {
const orgChild2 = await this.orgChild2Repository.findOne({ where: { id } });
const orgChild3 = await this.orgChild3Repository.findOne({ where: { id: id } });
const orgChild3 = await this.orgChild3Repository.findOne({ where: { orgChild2Id: id } });
if (!orgChild2) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");

View file

@ -54,7 +54,6 @@ export class OrgChild4Controller extends Controller {
@Request() request: { user: Record<string, any> },
) {
try {
const orgChild3 = await this.orgChild3Repository.findOne({
where: { id: requestBody.orgChild3Id },
});
@ -159,17 +158,12 @@ export class OrgChild4Controller extends Controller {
async delete(@Path() id: string) {
try {
const orgChild4 = await this.orgChild4Repository.findOne({ where: { id } });
const orgChild3 = await this.orgChild3Repository.findOne({ where: { id: id } });
if (!orgChild4) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
if (!orgChild3) {
await this.orgChild4Repository.remove(orgChild4);
} else {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบข้อมูลได้");
}
await this.orgChild4Repository.remove(orgChild4);
return new HttpSuccess();
} catch (error) {

View file

@ -25,6 +25,7 @@ import HttpStatusCode from "../interfaces/http-status";
@Security("bearerAuth")
export class OrgRootController extends Controller {
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private orgChild1Repository = AppDataSource.getRepository(OrgChild1);
/**
* Root
@ -118,7 +119,7 @@ export class OrgRootController extends Controller {
const chkCode = await this.orgRootRepository.findOne({
where: { orgRootCode: requestBody.orgRootCode },
});
if (chkCode != null) {
if (chkCode?.id != id && chkCode != null ) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
}
@ -151,7 +152,7 @@ export class OrgRootController extends Controller {
async delete(@Path() id: string) {
try {
const orgRoot = await this.orgRootRepository.findOne({ where: { id } });
const orgChild1 = await this.orgRootRepository.findOne({ where: { id: id } });
const orgChild1 = await this.orgChild1Repository.findOne({ where: { orgRootId: id } });
if (!orgRoot) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");