Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop
This commit is contained in:
commit
0acdee9bbc
7 changed files with 886 additions and 5 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";
|
||||||
|
import { Not } from "typeorm";
|
||||||
|
@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: { id:Not(id),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() {
|
||||||
|
const educationLevel = await this.educationLevelRepository.find({
|
||||||
|
select: ["id", "name" ],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!educationLevel) {
|
||||||
|
return new HttpSuccess([]);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new HttpSuccess(educationLevel);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
173
src/controllers/GenderController.ts
Normal file
173
src/controllers/GenderController.ts
Normal file
|
|
@ -0,0 +1,173 @@
|
||||||
|
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 { Gender, CreateGender, UpdateGender } from "../entities/Gender";
|
||||||
|
import { Not } from "typeorm";
|
||||||
|
|
||||||
|
@Route("api/v1/org/gender")
|
||||||
|
@Tags("Gender")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
@Response(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||||
|
)
|
||||||
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||||
|
export class GenderController extends Controller {
|
||||||
|
private genderRepository = AppDataSource.getRepository(Gender);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API list รายการเพศ
|
||||||
|
*
|
||||||
|
* @summary ORG_058 - CRUD เพศ (ADMIN) #62
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get()
|
||||||
|
async Get() {
|
||||||
|
const _gender = await this.genderRepository.find({
|
||||||
|
select: ["id", "name"],
|
||||||
|
});
|
||||||
|
if (!_gender) {
|
||||||
|
return new HttpSuccess([]);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new HttpSuccess(_gender);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API รายละเอียดรายการเพศ
|
||||||
|
*
|
||||||
|
* @summary ORG_058 - CRUD เพศ (ADMIN) #62
|
||||||
|
*
|
||||||
|
* @param {string} id Id เพศ
|
||||||
|
*/
|
||||||
|
@Get("{id}")
|
||||||
|
async GetById(@Path() id: string) {
|
||||||
|
const _gender = await this.genderRepository.findOne({
|
||||||
|
where: { id },
|
||||||
|
select: ["id", "name"],
|
||||||
|
});
|
||||||
|
if (!_gender) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new HttpSuccess(_gender);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API สร้างรายการ body เพศ
|
||||||
|
*
|
||||||
|
* @summary ORG_058 - CRUD เพศ (ADMIN) #62
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Post()
|
||||||
|
async Post(
|
||||||
|
@Body()
|
||||||
|
requestBody: CreateGender,
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
) {
|
||||||
|
const _gender = Object.assign(new Gender(), requestBody);
|
||||||
|
if (!_gender) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkName = await this.genderRepository.findOne({
|
||||||
|
where: { name: requestBody.name },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (checkName) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
_gender.createdUserId = request.user.sub;
|
||||||
|
_gender.createdFullName = request.user.name;
|
||||||
|
_gender.lastUpdateUserId = request.user.sub;
|
||||||
|
_gender.lastUpdateFullName = request.user.name;
|
||||||
|
await this.genderRepository.save(_gender);
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API แก้ไขรายการ body เพศ
|
||||||
|
*
|
||||||
|
* @summary ORG_058 - CRUD เพศ (ADMIN) #62
|
||||||
|
*
|
||||||
|
* @param {string} id Id เพศ
|
||||||
|
*/
|
||||||
|
@Put("{id}")
|
||||||
|
async Put(
|
||||||
|
@Path() id: string,
|
||||||
|
@Body()
|
||||||
|
requestBody: UpdateGender,
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
) {
|
||||||
|
const _gender = await this.genderRepository.findOne({ where: { id: id } });
|
||||||
|
if (!_gender) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + id);
|
||||||
|
}
|
||||||
|
const checkName = await this.genderRepository.findOne({
|
||||||
|
where: { id: Not(id), name: requestBody.name },
|
||||||
|
});
|
||||||
|
if (checkName) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
_gender.lastUpdateUserId = request.user.sub;
|
||||||
|
_gender.lastUpdateFullName = request.user.name;
|
||||||
|
this.genderRepository.merge(_gender, requestBody);
|
||||||
|
await this.genderRepository.save(_gender);
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API ลบรายการเพศ
|
||||||
|
*
|
||||||
|
* @summary ORG_058 - CRUD เพศ (ADMIN) #62
|
||||||
|
*
|
||||||
|
* @param {string} id Id เพศ
|
||||||
|
*/
|
||||||
|
@Delete("{id}")
|
||||||
|
async Delete(@Path() id: string) {
|
||||||
|
const _delGender = await this.genderRepository.findOne({
|
||||||
|
where: { id: id },
|
||||||
|
});
|
||||||
|
if (!_delGender) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + id);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await this.genderRepository.delete(_delGender.id);
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
173
src/controllers/PrefixController.ts
Normal file
173
src/controllers/PrefixController.ts
Normal file
|
|
@ -0,0 +1,173 @@
|
||||||
|
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 { Prefixe, CreatePrefixe, UpdatePrefixe } from "../entities/Prefixe";
|
||||||
|
import { Not } from "typeorm";
|
||||||
|
|
||||||
|
@Route("api/v1/org/prefix")
|
||||||
|
@Tags("Prefix")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
@Response(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||||
|
)
|
||||||
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||||
|
export class PrefixController extends Controller {
|
||||||
|
private prefixRepository = AppDataSource.getRepository(Prefixe);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API list รายการคำนำหน้า
|
||||||
|
*
|
||||||
|
* @summary ORG_056 - CRUD คำนำหน้า (ADMIN) #61
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get()
|
||||||
|
async Get() {
|
||||||
|
const _prefix = await this.prefixRepository.find({
|
||||||
|
select: ["id", "name"],
|
||||||
|
});
|
||||||
|
if (!_prefix) {
|
||||||
|
return new HttpSuccess([]);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new HttpSuccess(_prefix);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API รายละเอียดรายการคำนำหน้า
|
||||||
|
*
|
||||||
|
* @summary ORG_056 - CRUD คำนำหน้า (ADMIN) #61
|
||||||
|
*
|
||||||
|
* @param {string} id Id คำนำหน้า
|
||||||
|
*/
|
||||||
|
@Get("{id}")
|
||||||
|
async GetById(@Path() id: string) {
|
||||||
|
const _prefix = await this.prefixRepository.findOne({
|
||||||
|
where: { id },
|
||||||
|
select: ["id", "name"],
|
||||||
|
});
|
||||||
|
if (!_prefix) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new HttpSuccess(_prefix);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API สร้างรายการ body คำนำหน้า
|
||||||
|
*
|
||||||
|
* @summary ORG_056 - CRUD คำนำหน้า (ADMIN) #61
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Post()
|
||||||
|
async Post(
|
||||||
|
@Body()
|
||||||
|
requestBody: CreatePrefixe,
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
) {
|
||||||
|
const _prefix = Object.assign(new Prefixe(), requestBody);
|
||||||
|
if (!_prefix) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkName = await this.prefixRepository.findOne({
|
||||||
|
where: { name: requestBody.name },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (checkName) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
_prefix.createdUserId = request.user.sub;
|
||||||
|
_prefix.createdFullName = request.user.name;
|
||||||
|
_prefix.lastUpdateUserId = request.user.sub;
|
||||||
|
_prefix.lastUpdateFullName = request.user.name;
|
||||||
|
await this.prefixRepository.save(_prefix);
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API แก้ไขรายการ body คำนำหน้า
|
||||||
|
*
|
||||||
|
* @summary ORG_056 - CRUD คำนำหน้า (ADMIN) #61
|
||||||
|
*
|
||||||
|
* @param {string} id Id คำนำหน้า
|
||||||
|
*/
|
||||||
|
@Put("{id}")
|
||||||
|
async Put(
|
||||||
|
@Path() id: string,
|
||||||
|
@Body()
|
||||||
|
requestBody: UpdatePrefixe,
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
) {
|
||||||
|
const _prefix = await this.prefixRepository.findOne({ where: { id: id } });
|
||||||
|
if (!_prefix) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + id);
|
||||||
|
}
|
||||||
|
const checkName = await this.prefixRepository.findOne({
|
||||||
|
where: { id: Not(id), name: requestBody.name },
|
||||||
|
});
|
||||||
|
if (checkName) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
_prefix.lastUpdateUserId = request.user.sub;
|
||||||
|
_prefix.lastUpdateFullName = request.user.name;
|
||||||
|
this.prefixRepository.merge(_prefix, requestBody);
|
||||||
|
await this.prefixRepository.save(_prefix);
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API ลบรายการคำนำหน้า
|
||||||
|
*
|
||||||
|
* @summary ORG_056 - CRUD คำนำหน้า (ADMIN) #61
|
||||||
|
*
|
||||||
|
* @param {string} id Id คำนำหน้า
|
||||||
|
*/
|
||||||
|
@Delete("{id}")
|
||||||
|
async Delete(@Path() id: string) {
|
||||||
|
const _delPrefix = await this.prefixRepository.findOne({
|
||||||
|
where: { id: id },
|
||||||
|
});
|
||||||
|
if (!_delPrefix) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตามไอดีนี้ : " + id);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await this.prefixRepository.delete(_delPrefix.id);
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
172
src/controllers/RankController.ts
Normal file
172
src/controllers/RankController.ts
Normal file
|
|
@ -0,0 +1,172 @@
|
||||||
|
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 { CreateRank, Rank } from "../entities/Rank";
|
||||||
|
import { Not } from "typeorm";
|
||||||
|
@Route("api/v1/org/rank")
|
||||||
|
@Tags("Rank")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
@Response(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||||
|
)
|
||||||
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||||
|
export class RankController extends Controller {
|
||||||
|
private rankRepository = AppDataSource.getRepository(Rank);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API สร้างยศ
|
||||||
|
*
|
||||||
|
* @summary ORG_059 - สร้างยศ (ADMIN) #65
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Post()
|
||||||
|
async createRank(
|
||||||
|
@Body()
|
||||||
|
requestBody: CreateRank,
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
) {
|
||||||
|
const checkName = await this.rankRepository.findOne({
|
||||||
|
where: { name: requestBody.name },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (checkName) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const rank = Object.assign(new Rank(), requestBody);
|
||||||
|
rank.createdUserId = request.user.sub;
|
||||||
|
rank.createdFullName = request.user.name;
|
||||||
|
rank.lastUpdateUserId = request.user.sub;
|
||||||
|
rank.lastUpdateFullName = request.user.name;
|
||||||
|
await this.rankRepository.save(rank);
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API แก้ไขยศ
|
||||||
|
*
|
||||||
|
* @summary ORG_059 - แก้ไขยศ (ADMIN) #65
|
||||||
|
*
|
||||||
|
* @param {string} id Id ยศ
|
||||||
|
*/
|
||||||
|
@Put("{id}")
|
||||||
|
async updateRank(
|
||||||
|
@Path() id: string,
|
||||||
|
@Body()
|
||||||
|
requestBody: CreateRank,
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
) {
|
||||||
|
const rank = await this.rankRepository.findOne({ where: { id: id } });
|
||||||
|
if (!rank) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkName = await this.rankRepository.findOne({
|
||||||
|
where: { id:Not(id),name: requestBody.name },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (checkName) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
rank.lastUpdateUserId = request.user.sub;
|
||||||
|
rank.lastUpdateFullName = request.user.name;
|
||||||
|
this.rankRepository.merge(rank, requestBody);
|
||||||
|
await this.rankRepository.save(rank);
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API ลบยศ
|
||||||
|
*
|
||||||
|
* @summary ORG_059 - ลบยศ (ADMIN) #65
|
||||||
|
*
|
||||||
|
* @param {string} id Id ยศ
|
||||||
|
*/
|
||||||
|
@Delete("{id}")
|
||||||
|
async deleteRank(@Path() id: string) {
|
||||||
|
const delRank = await this.rankRepository.findOne({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
if (!delRank) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await this.rankRepository.delete({ id: id });
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API รายละเอียดรายการยศ
|
||||||
|
*
|
||||||
|
* @summary ORG_059 - รายละเอียดรายการยศ (ADMIN) #65
|
||||||
|
*
|
||||||
|
* @param {string} id Id ยศ
|
||||||
|
*/
|
||||||
|
@Get("{id}")
|
||||||
|
async detailRank(@Path() id: string) {
|
||||||
|
const rank = await this.rankRepository.findOne({
|
||||||
|
where: { id },
|
||||||
|
select: ["id", "name"],
|
||||||
|
});
|
||||||
|
if (!rank) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new HttpSuccess(rank);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API รายการยศ
|
||||||
|
*
|
||||||
|
* @summary ORG_059 - รายการยศ (ADMIN) #65
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get()
|
||||||
|
async listRank() {
|
||||||
|
const rank = await this.rankRepository.find({
|
||||||
|
select: ["id", "name" ],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!rank) {
|
||||||
|
return new HttpSuccess([]);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new HttpSuccess(rank);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
@ -18,6 +18,7 @@ import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import { CreateRelationship, Relationship } from "../entities/Relationship";
|
import { CreateRelationship, Relationship } from "../entities/Relationship";
|
||||||
|
import { Not } from "typeorm";
|
||||||
@Route("api/v1/org/relationship")
|
@Route("api/v1/org/relationship")
|
||||||
@Tags("Relationship")
|
@Tags("Relationship")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
|
|
@ -67,7 +68,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(
|
||||||
|
|
@ -82,7 +83,7 @@ export class RelationshipController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkName = await this.relationshipRepository.findOne({
|
const checkName = await this.relationshipRepository.findOne({
|
||||||
where: { name: requestBody.name },
|
where: {id:Not(id),name: requestBody.name },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (checkName) {
|
if (checkName) {
|
||||||
|
|
@ -105,7 +106,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 +129,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 +152,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() {
|
||||||
|
|
|
||||||
171
src/controllers/ReligionController.ts
Normal file
171
src/controllers/ReligionController.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 { CreateReligion, Religion } from "../entities/Religion";
|
||||||
|
import { Not } from "typeorm";
|
||||||
|
@Route("api/v1/org/religion")
|
||||||
|
@Tags("Religion")
|
||||||
|
@Security("bearerAuth")
|
||||||
|
@Response(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||||
|
)
|
||||||
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||||
|
export class ReligionController extends Controller {
|
||||||
|
private religionRepository = AppDataSource.getRepository(Religion);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API สร้างศาสนา
|
||||||
|
*
|
||||||
|
* @summary ORG_059 - สร้างศาสนา (ADMIN) #65
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Post()
|
||||||
|
async createReligion(
|
||||||
|
@Body()
|
||||||
|
requestBody: CreateReligion,
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
) {
|
||||||
|
const checkName = await this.religionRepository.findOne({
|
||||||
|
where: { name: requestBody.name },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (checkName) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const religion = Object.assign(new Religion(), requestBody);
|
||||||
|
religion.createdUserId = request.user.sub;
|
||||||
|
religion.createdFullName = request.user.name;
|
||||||
|
religion.lastUpdateUserId = request.user.sub;
|
||||||
|
religion.lastUpdateFullName = request.user.name;
|
||||||
|
await this.religionRepository.save(religion);
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API แก้ไขศาสนา
|
||||||
|
*
|
||||||
|
* @summary ORG_059 - แก้ไขศาสนา (ADMIN) #65
|
||||||
|
*
|
||||||
|
* @param {string} id Id ศาสนา
|
||||||
|
*/
|
||||||
|
@Put("{id}")
|
||||||
|
async updateReligion(
|
||||||
|
@Path() id: string,
|
||||||
|
@Body()
|
||||||
|
requestBody: CreateReligion,
|
||||||
|
@Request() request: { user: Record<string, any> },
|
||||||
|
) {
|
||||||
|
const religion = await this.religionRepository.findOne({ where: { id: id } });
|
||||||
|
if (!religion) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkName = await this.religionRepository.findOne({
|
||||||
|
where: { id:Not(id),name: requestBody.name },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (checkName) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
religion.lastUpdateUserId = request.user.sub;
|
||||||
|
religion.lastUpdateFullName = request.user.name;
|
||||||
|
this.religionRepository.merge(religion, requestBody);
|
||||||
|
await this.religionRepository.save(religion);
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API ลบศาสนา
|
||||||
|
*
|
||||||
|
* @summary ORG_059 - ลบศาสนา (ADMIN) #65
|
||||||
|
*
|
||||||
|
* @param {string} id Id ศาสนา
|
||||||
|
*/
|
||||||
|
@Delete("{id}")
|
||||||
|
async deleteReligion(@Path() id: string) {
|
||||||
|
const delReligion = await this.religionRepository.findOne({
|
||||||
|
where: { id },
|
||||||
|
});
|
||||||
|
if (!delReligion) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await this.religionRepository.delete({ id: id });
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API รายละเอียดรายการศาสนา
|
||||||
|
*
|
||||||
|
* @summary ORG_059 - รายละเอียดรายการศาสนา (ADMIN) #65
|
||||||
|
*
|
||||||
|
* @param {string} id Id ศาสนา
|
||||||
|
*/
|
||||||
|
@Get("{id}")
|
||||||
|
async detailReligion(@Path() id: string) {
|
||||||
|
const religion = await this.religionRepository.findOne({
|
||||||
|
where: { id },
|
||||||
|
select: ["id", "name"],
|
||||||
|
});
|
||||||
|
if (!religion) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new HttpSuccess(religion);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API รายการศาสนา
|
||||||
|
*
|
||||||
|
* @summary ORG_059 - รายการศาสนา (ADMIN) #65
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get()
|
||||||
|
async listReligion() {
|
||||||
|
const religion = await this.religionRepository.find({
|
||||||
|
select: ["id", "name" ],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!religion) {
|
||||||
|
return new HttpSuccess([]);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
return new HttpSuccess(religion);
|
||||||
|
} catch (error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
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