checkpoint

This commit is contained in:
AdisakKanthawilang 2024-01-25 11:24:50 +07:00
parent d7926538ae
commit 4c269d5011

View file

@ -15,12 +15,14 @@ import {
import { CreateOrgRoot, OrgRoot } from "../entities/OrgRoot";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import { OrgChild1 } from "../entities/OrgChild1";
@Route("organization")
@Tags("OrgRoot")
// @Security("bearerAuth")
export class OrgRootController extends Controller {
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
private orgChild1Repository = AppDataSource.getRepository(OrgChild1);
/**
* Root
@ -117,4 +119,38 @@ export class OrgRootController extends Controller {
return error;
}
}
/**
* Root
*
* @summary ORG_003 - Root (ADMIN) #3
*
* @param {string} id Guid, *Id root
*/
@Delete("root/{id}")
async delete(
@Path() id: string,
) {
try {
const orgRoot = await this.orgRootRepository.findOne({ where: { id } });
const orgChild1 = await AppDataSource.getRepository(OrgChild1)
.createQueryBuilder("orgChild1")
.where("orgChild1.orgRootId", { id })
.getOne();
if (!orgRoot) {
return `not found data`;
}
if(!orgChild1){
await this.orgRootRepository.remove(orgRoot);
}else{
return 'ไม่สามารถลบข้อมูลได้'
}
return new HttpSuccess();
} catch (error) {
return error;
}
}
}