checkpoint
This commit is contained in:
parent
42bd8cd77b
commit
5fbb2c5eea
4 changed files with 261 additions and 39 deletions
|
|
@ -1 +1,210 @@
|
|||
import { Controller, Get, Post, Put, Delete, Patch, Route, Security, Tags } from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Patch,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Path,
|
||||
Body,
|
||||
Request,
|
||||
Example,
|
||||
} from "tsoa";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { CreateOrgChild2, OrgChild2 } from "../entities/OrgChild2";
|
||||
|
||||
@Route("organization")
|
||||
@Tags("OrgChild2")
|
||||
@Security("bearerAuth")
|
||||
export class OrgChild2Controller extends Controller {
|
||||
private orgChild2Repository = AppDataSource.getRepository(OrgChild2);
|
||||
|
||||
/**
|
||||
* สร้างโครงสร้างระดับ2 Child2
|
||||
*
|
||||
* @summary ORG_007 - สร้างโครงสร้างระดับ2 (ADMIN) #7
|
||||
*
|
||||
* @param {string} id id ข้อมูลการประเมิน
|
||||
*/
|
||||
@Post("Child2")
|
||||
@Example([
|
||||
{
|
||||
orgChild2Name: "string", //ชื่อหน่วยงาน
|
||||
orgChild2ShortName: "string", //อักษรย่อ
|
||||
orgChild2Code: "string", //รหัสหน่วยงาน
|
||||
orgChild2Order: "number", //ลำดับที่ของหน่วยงาน
|
||||
orgChild2PhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
|
||||
orgChild2PhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
|
||||
orgChild2Fax: "string", //หมายเลขโทรสาร
|
||||
orgChild2IsNormal: "boolean", //สถานะของหน่วยงาน
|
||||
orgChild1Id: "Guid", //id Child1
|
||||
},
|
||||
])
|
||||
async create(
|
||||
@Body()
|
||||
requestBody: CreateOrgChild2,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
try {
|
||||
const orgChild1 = await this.orgChild2Repository.findOne({
|
||||
where: { id: requestBody.orgChild1Id },
|
||||
});
|
||||
const orgChild2 = Object.assign(new OrgChild2(), requestBody);
|
||||
if (!orgChild2) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
const chkOrder = await this.orgChild2Repository.findOne({
|
||||
where: { orgChild1Id:requestBody.orgChild1Id, orgChild2Order: requestBody.orgChild2Order },
|
||||
});
|
||||
if (chkOrder != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
const chkCode = await this.orgChild2Repository.findOne({
|
||||
where: { orgChild1Id:requestBody.orgChild1Id, orgChild2Code: requestBody.orgChild2Code },
|
||||
});
|
||||
if (chkCode != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
if(orgChild1){
|
||||
orgChild2.orgChild2Name = requestBody.orgChild2Name;
|
||||
orgChild2.orgChild2ShortName = requestBody.orgChild2ShortName;
|
||||
orgChild2.orgChild2Code = requestBody.orgChild2Code;
|
||||
orgChild2.orgChild2Order = requestBody.orgChild2Order;
|
||||
orgChild2.orgChild2PhoneEx = requestBody.orgChild2PhoneEx;
|
||||
orgChild2.orgChild2PhoneIn = requestBody.orgChild2PhoneIn;
|
||||
orgChild2.orgChild2Fax = requestBody.orgChild2Fax;
|
||||
orgChild2.orgChild2IsNormal = requestBody.orgChild2IsNormal;
|
||||
orgChild2.createdUserId = request.user.sub;
|
||||
orgChild2.createdFullName = request.user.name;
|
||||
orgChild2.lastUpdateUserId = request.user.sub;
|
||||
orgChild2.lastUpdateFullName = request.user.name;
|
||||
await this.orgChild2Repository.save(orgChild2);
|
||||
}else{
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีโครงสร้างระดับ1");
|
||||
}
|
||||
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* แก้ไขโครงสร้างระดับ Child2
|
||||
*
|
||||
* @summary ORG_002 - แก้ไขโครงสร้างระดับ Child2 (ADMIN) #2
|
||||
*
|
||||
* @param {string} id Guid, *Id Child2
|
||||
*/
|
||||
// @Put("Child2/{id}")
|
||||
// @Example([
|
||||
// {
|
||||
// orgChild2Name: "string", //ชื่อหน่วยงาน
|
||||
// orgChild2ShortName: "string", //อักษรย่อ
|
||||
// orgChild2Code: "string", //รหัสหน่วยงาน
|
||||
// orgChild2Order: "number", //ลำดับที่ของหน่วยงาน
|
||||
// orgChild2PhoneEx: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายนอก
|
||||
// orgChild2PhoneIn: "string", //หมายเลขโทรศัพท์ที่ติดต่อจากภายใน
|
||||
// orgChild2Fax: "string", //หมายเลขโทรสาร
|
||||
// orgChild2IsNormal: "boolean", //สถานะของหน่วยงาน
|
||||
// },
|
||||
// ])
|
||||
// async update(
|
||||
// @Path() id: string,
|
||||
// @Body()
|
||||
// requestBody: CreateOrgChild2,
|
||||
// @Request() request: { user: Record<string, any> },
|
||||
// ) {
|
||||
// try {
|
||||
// const orgChild2 = await this.orgChild2Repository.findOne({ where: { id } });
|
||||
// if (!orgChild2) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
// const chkOrder = await this.orgChild2Repository.findOne({
|
||||
// where: { orgChild2Order: requestBody.orgChild2Order },
|
||||
// });
|
||||
// if (chkOrder != null) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
// }
|
||||
// const chkCode = await this.orgChild2Repository.findOne({
|
||||
// where: { orgChild2Code: requestBody.orgChild2Code },
|
||||
// });
|
||||
// if (chkCode != null) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
// }
|
||||
|
||||
// orgChild2.orgChild2Name = requestBody.orgChild2Name;
|
||||
// orgChild2.orgChild2ShortName = requestBody.orgChild2ShortName;
|
||||
// orgChild2.orgChild2Code = requestBody.orgChild2Code;
|
||||
// orgChild2.orgChild2Order = requestBody.orgChild2Order;
|
||||
// orgChild2.orgChild2PhoneEx = requestBody.orgChild2PhoneEx;
|
||||
// orgChild2.orgChild2PhoneIn = requestBody.orgChild2PhoneIn;
|
||||
// orgChild2.orgChild2Fax = requestBody.orgChild2Fax;
|
||||
// orgChild2.orgChild2IsNormal = requestBody.orgChild2IsNormal;
|
||||
// orgChild2.lastUpdateUserId = request.user.sub;
|
||||
// orgChild2.lastUpdateFullName = request.user.name;
|
||||
// await this.orgChild2Repository.save(orgChild2);
|
||||
|
||||
// return new HttpSuccess();
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* ลบโครงสร้างระดับ Child2
|
||||
*
|
||||
* @summary ORG_003 - ลบโครงสร้างระดับ Child2 (ADMIN) #3
|
||||
*
|
||||
* @param {string} id Guid, *Id Child2
|
||||
*/
|
||||
// @Delete("Child2/{id}")
|
||||
// async delete(@Path() id: string) {
|
||||
// try {
|
||||
// const orgChild2 = await this.orgChild2Repository.findOne({ where: { id } });
|
||||
// const orgChild1 = await await this.orgChild2Repository.findOne({ where: { id: id } });
|
||||
|
||||
// if (!orgChild2) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
|
||||
// if (!orgChild1) {
|
||||
// await this.orgChild2Repository.remove(orgChild2);
|
||||
// } else {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบข้อมูลได้");
|
||||
// }
|
||||
|
||||
// return new HttpSuccess();
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* รายละเอียดโครงสร้างระดับ Child2
|
||||
*
|
||||
* @summary ORG_016 - รายละเอียดโครงสร้างระดับ Child2 (ADMIN) #16
|
||||
*
|
||||
* @param {string} id Guid, *Id Child2
|
||||
*/
|
||||
// @Get("Child2/{id}")
|
||||
// async detail(@Path() id: string) {
|
||||
// try {
|
||||
// const orgChild2 = await this.orgChild2Repository.findOne({ where: { id } });
|
||||
|
||||
// if (!orgChild2) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
|
||||
// return new HttpSuccess(orgChild2);
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue