120 lines
4.1 KiB
TypeScript
120 lines
4.1 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Delete,
|
|
Patch,
|
|
Route,
|
|
Security,
|
|
Tags,
|
|
Body,
|
|
Path,
|
|
Example,
|
|
} from "tsoa";
|
|
import { CreateOrgRoot, OrgRoot } from "../entities/OrgRoot";
|
|
import { AppDataSource } from "../database/data-source";
|
|
import HttpSuccess from "../interfaces/http-success";
|
|
|
|
@Route("organization")
|
|
@Tags("OrgRoot")
|
|
// @Security("bearerAuth")
|
|
export class OrgRootController extends Controller {
|
|
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
|
|
|
|
/**
|
|
* สร้างโครงสร้างระดับ Root
|
|
*
|
|
* @summary ORG_001 - สร้างโครงสร้างระดับ Root (ADMIN) #1
|
|
*
|
|
* @param {string} id id ข้อมูลการประเมิน
|
|
*/
|
|
@Post("root")
|
|
@Example([
|
|
{
|
|
orgRootName: "string", //ชื่อหน่วยงาน
|
|
orgRootShortName: "string", //อักษรย่อ
|
|
orgRootCode: "string", //รหัสหน่วยงาน
|
|
orgRootOrder: "number", //ลำดับที่ของหน่วยงาน
|
|
orgRootPhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
|
|
orgRootPhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
|
|
orgRootFax: "string", //หมายเลขโทรสาร
|
|
orgRootIsNormal: "boolean", //สถานะของหน่วยงาน
|
|
},
|
|
])
|
|
async create(
|
|
// @Path() id: string,
|
|
@Body()
|
|
requestBody: CreateOrgRoot,
|
|
) {
|
|
try {
|
|
const orgRoot = Object.assign(new OrgRoot(), requestBody);
|
|
if (!orgRoot) {
|
|
return `not found data`;
|
|
}
|
|
|
|
orgRoot.orgRootName = requestBody.orgRootName;
|
|
orgRoot.orgRootShortName = requestBody.orgRootShortName;
|
|
orgRoot.orgRootCode = requestBody.orgRootCode;
|
|
orgRoot.orgRootOrder = requestBody.orgRootOrder;
|
|
orgRoot.orgRootPhoneEx = requestBody.orgRootPhoneEx;
|
|
orgRoot.orgRootPhoneIn = requestBody.orgRootPhoneIn;
|
|
orgRoot.orgRootFax = requestBody.orgRootFax;
|
|
orgRoot.orgRootIsNormal = requestBody.orgRootIsNormal;
|
|
await this.orgRootRepository.save(orgRoot);
|
|
|
|
return new HttpSuccess();
|
|
} catch (error) {
|
|
return error;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* แก้ไขโครงสร้างระดับ Root
|
|
*
|
|
* @summary ORG_002 - แก้ไขโครงสร้างระดับ Root (ADMIN) #2
|
|
*
|
|
* @param {string} id Guid, *Id root
|
|
*/
|
|
@Put("root/{id}")
|
|
@Example([
|
|
{
|
|
orgRootName: "string", //ชื่อหน่วยงาน
|
|
orgRootShortName: "string", //อักษรย่อ
|
|
orgRootCode: "string", //รหัสหน่วยงาน
|
|
orgRootOrder: "number", //ลำดับที่ของหน่วยงาน
|
|
orgRootPhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
|
|
orgRootPhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
|
|
orgRootFax: "string", //หมายเลขโทรสาร
|
|
orgRootIsNormal: "boolean", //สถานะของหน่วยงาน
|
|
},
|
|
])
|
|
async update(
|
|
@Path() id: string,
|
|
@Body()
|
|
requestBody: CreateOrgRoot,
|
|
) {
|
|
try {
|
|
const orgRoot = await this.orgRootRepository.findOne({ where: { id } });
|
|
if (!orgRoot) {
|
|
return `not found data`;
|
|
}
|
|
|
|
orgRoot.orgRootName = requestBody.orgRootName;
|
|
orgRoot.orgRootShortName = requestBody.orgRootShortName;
|
|
orgRoot.orgRootCode = requestBody.orgRootCode;
|
|
orgRoot.orgRootOrder = requestBody.orgRootOrder;
|
|
orgRoot.orgRootPhoneEx = requestBody.orgRootPhoneEx;
|
|
orgRoot.orgRootPhoneIn = requestBody.orgRootPhoneIn;
|
|
orgRoot.orgRootFax = requestBody.orgRootFax;
|
|
orgRoot.orgRootIsNormal = requestBody.orgRootIsNormal;
|
|
await this.orgRootRepository.save(orgRoot);
|
|
|
|
return new HttpSuccess();
|
|
} catch (error) {
|
|
return error;
|
|
}
|
|
}
|
|
}
|