Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop

This commit is contained in:
Kittapath 2024-02-03 13:44:45 +07:00
commit 0acdee9bbc
7 changed files with 886 additions and 5 deletions

View 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;
}
}
}

View 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;
}
}
}

View 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;
}
}
}

View 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;
}
}
}

View file

@ -18,6 +18,7 @@ import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { CreateRelationship, Relationship } from "../entities/Relationship";
import { Not } from "typeorm";
@Route("api/v1/org/relationship")
@Tags("Relationship")
@Security("bearerAuth")
@ -67,7 +68,7 @@ export class RelationshipController extends Controller {
*
* @summary ORG_060 - (ADMIN) #65
*
* @param {string} id Id
* @param {string} id Id
*/
@Put("{id}")
async updateRelationship(
@ -82,7 +83,7 @@ export class RelationshipController extends Controller {
}
const checkName = await this.relationshipRepository.findOne({
where: { name: requestBody.name },
where: {id:Not(id),name: requestBody.name },
});
if (checkName) {
@ -105,7 +106,7 @@ export class RelationshipController extends Controller {
*
* @summary ORG_060 - (ADMIN) #65
*
* @param {string} id Id
* @param {string} id Id
*/
@Delete("{id}")
async deleteRelationship(@Path() id: string) {
@ -128,7 +129,7 @@ export class RelationshipController extends Controller {
*
* @summary ORG_060 - (ADMIN) #65
*
* @param {string} id Id
* @param {string} id Id
*/
@Get("{id}")
async detailRelationship(@Path() id: string) {
@ -151,7 +152,6 @@ export class RelationshipController extends Controller {
*
* @summary ORG_060 - (ADMIN) #65
*
* @param {string} id Id
*/
@Get()
async listRelationship() {

View 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;
}
}
}

View file

@ -55,6 +55,27 @@
},
{
"name": "PosExecutive", "description": "ตำแหน่งทางการบริหาร"
},
{
"name": "Prefix", "description": "คำนำหน้า"
},
{
"name": "Rank", "description": "ยศ"
},
{
"name": "BloodGroup", "description": "กลุ่มเลือด"
},
{
"name": "Gender", "description": "เพศ"
},
{
"name": "Religion", "description": "ศาสนา"
},
{
"name": "Relationship", "description": "สถานภาพ"
},
{
"name": "EducationLevel", "description": "ระดับการศึกษา"
}
]
},