Merge branch 'adiDev' into develop
This commit is contained in:
commit
ca8a150faf
3 changed files with 195 additions and 4 deletions
171
src/controllers/EducationLevelController.ts
Normal file
171
src/controllers/EducationLevelController.ts
Normal file
|
|
@ -0,0 +1,171 @@
|
||||||
|
import {
|
||||||
|
Controller,
|
||||||
|
Post,
|
||||||
|
Put,
|
||||||
|
Delete,
|
||||||
|
Route,
|
||||||
|
Security,
|
||||||
|
Tags,
|
||||||
|
Body,
|
||||||
|
Path,
|
||||||
|
Request,
|
||||||
|
SuccessResponse,
|
||||||
|
Response,
|
||||||
|
Get,
|
||||||
|
} from "tsoa";
|
||||||
|
import { AppDataSource } from "../database/data-source";
|
||||||
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
|
import HttpError from "../interfaces/http-error";
|
||||||
|
import { CreateEducationLevel, EducationLevel } from "../entities/EducationLevel";
|
||||||
|
@Route("api/v1/org/educationLevel")
|
||||||
|
@Tags("EducationLevel")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
@Response(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||||
|
)
|
||||||
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||||
|
export class EducationLevelController extends Controller {
|
||||||
|
private educationLevelRepository = AppDataSource.getRepository(EducationLevel);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API สร้างระดับการศึกษา
|
||||||
|
*
|
||||||
|
* @summary ORG_061 - สร้างระดับการศึกษา (ADMIN) #65
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Post()
|
||||||
|
async createEducationLevel(
|
||||||
|
@Body()
|
||||||
|
requestBody: CreateEducationLevel,
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
) {
|
||||||
|
const checkName = await this.educationLevelRepository.findOne({
|
||||||
|
where: { name: requestBody.name },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (checkName) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const educationLevel = Object.assign(new EducationLevel(), requestBody);
|
||||||
|
educationLevel.createdUserId = request.user.sub;
|
||||||
|
educationLevel.createdFullName = request.user.name;
|
||||||
|
educationLevel.lastUpdateUserId = request.user.sub;
|
||||||
|
educationLevel.lastUpdateFullName = request.user.name;
|
||||||
|
await this.educationLevelRepository.save(educationLevel);
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API แก้ไขระดับการศึกษา
|
||||||
|
*
|
||||||
|
* @summary ORG_061 - แก้ไขระดับการศึกษา (ADMIN) #65
|
||||||
|
*
|
||||||
|
* @param {string} id Id ระดับการศึกษา
|
||||||
|
*/
|
||||||
|
@Put("{id}")
|
||||||
|
async updateEducationLevel(
|
||||||
|
@Path() id: string,
|
||||||
|
@Body()
|
||||||
|
requestBody: CreateEducationLevel,
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
) {
|
||||||
|
const educationLevel = await this.educationLevelRepository.findOne({ where: { id: id } });
|
||||||
|
if (!educationLevel) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkName = await this.educationLevelRepository.findOne({
|
||||||
|
where: { name: requestBody.name },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (checkName) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
educationLevel.lastUpdateUserId = request.user.sub;
|
||||||
|
educationLevel.lastUpdateFullName = request.user.name;
|
||||||
|
this.educationLevelRepository.merge(educationLevel, requestBody);
|
||||||
|
await this.educationLevelRepository.save(educationLevel);
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API ลบระดับการศึกษา
|
||||||
|
*
|
||||||
|
* @summary ORG_061 - ลบระดับการศึกษา (ADMIN) #65
|
||||||
|
*
|
||||||
|
* @param {string} id Id ระดับการศึกษา
|
||||||
|
*/
|
||||||
|
@Delete("{id}")
|
||||||
|
async deleteEducationLevel(@Path() id: string) {
|
||||||
|
const delEducationLevel = await this.educationLevelRepository.findOne({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
if (!delEducationLevel) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await this.educationLevelRepository.delete({ id: id });
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API รายละเอียดรายการระดับการศึกษา
|
||||||
|
*
|
||||||
|
* @summary ORG_061 - รายละเอียดรายการระดับการศึกษา (ADMIN) #65
|
||||||
|
*
|
||||||
|
* @param {string} id Id ระดับการศึกษา
|
||||||
|
*/
|
||||||
|
@Get("{id}")
|
||||||
|
async detailEducationLevel(@Path() id: string) {
|
||||||
|
const educationLevel = await this.educationLevelRepository.findOne({
|
||||||
|
where: { id },
|
||||||
|
select: ["id", "name" ,"rank"],
|
||||||
|
});
|
||||||
|
if (!educationLevel) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new HttpSuccess(educationLevel);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API รายการระดับการศึกษา
|
||||||
|
*
|
||||||
|
* @summary ORG_061 - รายการระดับการศึกษา (ADMIN) #65
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get()
|
||||||
|
async listEducationLevel() {
|
||||||
|
console.log("11111111111111111111111111111");
|
||||||
|
const educationLevel = await this.educationLevelRepository.find({
|
||||||
|
select: ["id", "name" ],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!educationLevel) {
|
||||||
|
return new HttpSuccess([]);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new HttpSuccess(educationLevel);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -67,7 +67,7 @@ export class RelationshipController extends Controller {
|
||||||
*
|
*
|
||||||
* @summary ORG_060 - แก้ไขสถานภาพ (ADMIN) #65
|
* @summary ORG_060 - แก้ไขสถานภาพ (ADMIN) #65
|
||||||
*
|
*
|
||||||
* @param {string} id Id ตำแหน่งทางการบริหาร
|
* @param {string} id Id สถานภาพ
|
||||||
*/
|
*/
|
||||||
@Put("{id}")
|
@Put("{id}")
|
||||||
async updateRelationship(
|
async updateRelationship(
|
||||||
|
|
@ -105,7 +105,7 @@ export class RelationshipController extends Controller {
|
||||||
*
|
*
|
||||||
* @summary ORG_060 - ลบสถานภาพ (ADMIN) #65
|
* @summary ORG_060 - ลบสถานภาพ (ADMIN) #65
|
||||||
*
|
*
|
||||||
* @param {string} id Id ตำแหน่งทางการบริหาร
|
* @param {string} id Id สถานภาพ
|
||||||
*/
|
*/
|
||||||
@Delete("{id}")
|
@Delete("{id}")
|
||||||
async deleteRelationship(@Path() id: string) {
|
async deleteRelationship(@Path() id: string) {
|
||||||
|
|
@ -128,7 +128,7 @@ export class RelationshipController extends Controller {
|
||||||
*
|
*
|
||||||
* @summary ORG_060 - รายละเอียดรายการสถานภาพ (ADMIN) #65
|
* @summary ORG_060 - รายละเอียดรายการสถานภาพ (ADMIN) #65
|
||||||
*
|
*
|
||||||
* @param {string} id Id ตำแหน่งทางการบริหาร
|
* @param {string} id Id สถานภาพ
|
||||||
*/
|
*/
|
||||||
@Get("{id}")
|
@Get("{id}")
|
||||||
async detailRelationship(@Path() id: string) {
|
async detailRelationship(@Path() id: string) {
|
||||||
|
|
@ -151,7 +151,6 @@ export class RelationshipController extends Controller {
|
||||||
*
|
*
|
||||||
* @summary ORG_060 - รายการสถานภาพ (ADMIN) #65
|
* @summary ORG_060 - รายการสถานภาพ (ADMIN) #65
|
||||||
*
|
*
|
||||||
* @param {string} id Id ตำแหน่งทางการบริหาร
|
|
||||||
*/
|
*/
|
||||||
@Get()
|
@Get()
|
||||||
async listRelationship() {
|
async listRelationship() {
|
||||||
|
|
|
||||||
21
tsoa.json
21
tsoa.json
|
|
@ -55,6 +55,27 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "PosExecutive", "description": "ตำแหน่งทางการบริหาร"
|
"name": "PosExecutive", "description": "ตำแหน่งทางการบริหาร"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Prefix", "description": "คำนำหน้า"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Rank", "description": "ยศ"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "BloodGroup", "description": "กลุ่มเลือด"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Gender", "description": "เพศ"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Religion", "description": "ศาสนา"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Relationship", "description": "สถานภาพ"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "EducationLevel", "description": "ระดับการศึกษา"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue