Merge branch 'develop' into adiDev
This commit is contained in:
commit
414d695903
2 changed files with 98 additions and 16 deletions
|
|
@ -1 +1,63 @@
|
|||
import { Controller, Get, Post, Put, Delete, Patch, Route, Security, Tags } from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { CreateOrgChild1, OrgChild1 } from "../entities/OrgChild1";
|
||||
import {
|
||||
Body,
|
||||
Delete,
|
||||
Get,
|
||||
Path,
|
||||
Post,
|
||||
Put,
|
||||
Response,
|
||||
Route,
|
||||
SuccessResponse,
|
||||
Tags,
|
||||
Query,
|
||||
Request,
|
||||
Security,
|
||||
} from "tsoa";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
@Route("api/v1/organization/child1")
|
||||
@Tags("OrgChild1")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
|
||||
export class OrgChild1Controller {
|
||||
private child1Repository = AppDataSource.getRepository(OrgChild1)
|
||||
/**
|
||||
* API สร้างโครงสร้างระดับ1
|
||||
*
|
||||
* @summary ORG_004 - สร้างโครงสร้างระดับ1 (ADMIN)
|
||||
*
|
||||
*/
|
||||
@Post()
|
||||
async save(
|
||||
@Body() requestBody: CreateOrgChild1,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
){
|
||||
const chkOrder = await this.child1Repository.findOne({ where: { orgRootId:requestBody.orgRootId, orgChild1Order:requestBody.orgChild1Order }});
|
||||
if (chkOrder != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับที่ของหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
const chkCode = await this.child1Repository.findOne({ where: { orgRootId:requestBody.orgRootId, orgChild1Code:requestBody.orgChild1Code }});
|
||||
if (chkCode != null) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "รหัสหน่วยงานนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
const child1 = Object.assign(new OrgChild1(), requestBody) as OrgChild1;
|
||||
child1.orgChild1Name = requestBody.orgChild1Name
|
||||
child1.createdUserId = request.user.sub
|
||||
child1.createdFullName = request.user.name
|
||||
child1.createdAt = new Date()
|
||||
child1.lastUpdateUserId = request.user.sub
|
||||
child1.lastUpdateFullName= request.user.name
|
||||
child1.lastUpdatedAt = new Date()
|
||||
await this.child1Repository.save(child1);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue