แก้path root

This commit is contained in:
Kittapath 2024-01-29 17:22:05 +07:00
parent af7608ec34
commit cd416a4ebb

View file

@ -21,7 +21,7 @@ import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status";
import { OrgRevision } from "../entities/OrgRevision";
@Route("api/v1/org")
@Route("api/v1/org/root")
@Tags("OrgRoot")
@Security("bearerAuth")
export class OrgRootController extends Controller {
@ -36,7 +36,7 @@ export class OrgRootController extends Controller {
*
* @param {string} id Id Root
*/
@Get("root/{id}")
@Get("{id}")
async GetRoot(@Path() id: string) {
try {
const orgRoot = await this.orgRootRepository.findOne({ where: { id } });
@ -44,30 +44,30 @@ export class OrgRootController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล โครงสร้างระดับ Root");
}
const getOrgRoot = {
"orgRootId" : orgRoot.id,
"orgRootName" : orgRoot.orgRootName,
"orgRootShortName" : orgRoot.orgRootShortName,
"orgRootCode" : orgRoot.orgRootCode,
"orgRootOrder" : orgRoot.orgRootOrder,
"orgRootPhoneEx" : orgRoot.orgRootPhoneEx,
"orgRootPhoneIn" : orgRoot.orgRootPhoneIn,
"orgRootFax" : orgRoot.orgRootFax,
"orgRevisionId" : orgRoot.orgRevisionId,
"orgCode" : orgRoot.orgRootCode+"00"
}
orgRootId: orgRoot.id,
orgRootName: orgRoot.orgRootName,
orgRootShortName: orgRoot.orgRootShortName,
orgRootCode: orgRoot.orgRootCode,
orgRootOrder: orgRoot.orgRootOrder,
orgRootPhoneEx: orgRoot.orgRootPhoneEx,
orgRootPhoneIn: orgRoot.orgRootPhoneIn,
orgRootFax: orgRoot.orgRootFax,
orgRevisionId: orgRoot.orgRevisionId,
orgCode: orgRoot.orgRootCode + "00",
};
return new HttpSuccess(getOrgRoot);
} catch (error) {
return error;
}
}
/**
* Root
*
* @summary ORG_001 - Root (ADMIN) #1
*
*/
@Post("root")
@Post()
@Example([
{
orgRootName: "string", //ชื่อหน่วยงาน
@ -104,7 +104,11 @@ export class OrgRootController extends Controller {
}
const orgRevision = await this.orgRevisionRepository.findOne({
where: { id: requestBody.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false },
where: {
id: requestBody.orgRevisionId,
orgRevisionIsDraft: true,
orgRevisionIsCurrent: false,
},
});
if (orgRevision) {
@ -131,7 +135,7 @@ export class OrgRootController extends Controller {
*
* @param {string} id Guid, *Id root
*/
@Put("root/{id}")
@Put("{id}")
@Example([
{
orgRootName: "string", //ชื่อหน่วยงาน
@ -156,7 +160,11 @@ export class OrgRootController extends Controller {
}
const revisionIdExits = await this.orgRevisionRepository.findOne({
where: { id: requestBody.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false },
where: {
id: requestBody.orgRevisionId,
orgRevisionIsDraft: true,
orgRevisionIsCurrent: false,
},
});
if (!revisionIdExits) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. RevisionId");
@ -193,7 +201,7 @@ export class OrgRootController extends Controller {
*
* @param {string} id Guid, *Id root
*/
@Delete("root/{id}")
@Delete("{id}")
async delete(@Path() id: string) {
try {
const orgRoot = await this.orgRootRepository.findOne({ where: { id } });
@ -202,10 +210,13 @@ export class OrgRootController extends Controller {
}
const orgChild1 = await this.orgChild1Repository.findOne({ where: { orgRootId: id } });
if(orgChild1 != null){
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR,"ไม่สามารถลบข้อมูลได้เมื่อมีข้อมูลโครงสร้างระดับ1",);
if (orgChild1 != null) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถลบข้อมูลได้เมื่อมีข้อมูลโครงสร้างระดับ1",
);
}
const revisionIdExits = await this.orgRevisionRepository.findOne({
where: { id: orgRoot.orgRevisionId, orgRevisionIsDraft: true, orgRevisionIsCurrent: false },
});