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