Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop
This commit is contained in:
commit
ff7080ba17
11 changed files with 431 additions and 8 deletions
274
src/controllers/PosLevelController.ts
Normal file
274
src/controllers/PosLevelController.ts
Normal file
|
|
@ -0,0 +1,274 @@
|
|||
import {
|
||||
Controller,
|
||||
Get,
|
||||
Post,
|
||||
Put,
|
||||
Delete,
|
||||
Patch,
|
||||
Route,
|
||||
Security,
|
||||
Tags,
|
||||
Body,
|
||||
Path,
|
||||
Request,
|
||||
Example,
|
||||
SuccessResponse,
|
||||
Response,
|
||||
Query,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { PosType } from "../entities/PosType";
|
||||
import { PosLevel, CreatePosLevel, UpdatePosLevel } from "../entities/PosLevel";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import { Not } from "typeorm";
|
||||
|
||||
@Route("api/v1/org/pos/level")
|
||||
@Tags("PosLevel")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
|
||||
export class PosLevelController extends Controller {
|
||||
|
||||
private posTypeRepository = AppDataSource.getRepository(PosType);
|
||||
private posLevelRepository = AppDataSource.getRepository(PosLevel);
|
||||
|
||||
/**
|
||||
* API เพิ่มระดับตำแหน่ง
|
||||
*
|
||||
* @summary ORG_049 - เพิ่มระดับตำแหน่ง (ADMIN) #52
|
||||
*
|
||||
*/
|
||||
@Post()
|
||||
@Example(
|
||||
{
|
||||
posLevelName: "นักบริหาร",
|
||||
posLevelRank: 1,
|
||||
posLevelAuthority: "HEAD",
|
||||
posTypeId: "08db9e81-fc46-4e95-8b33-be4ca0016abf"
|
||||
},
|
||||
)
|
||||
async createLevel(
|
||||
@Body()
|
||||
requestBody: CreatePosLevel,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const posLevel = Object.assign(new PosLevel(), requestBody);
|
||||
if (!posLevel) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
const chkPosTypeId = await this.posTypeRepository.findOne({ where: {
|
||||
id: requestBody.posTypeId }
|
||||
})
|
||||
if(!chkPosTypeId){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล posTypeId ไอดีนี้ : " + requestBody.posTypeId);
|
||||
}
|
||||
|
||||
const chkPosLevelName = await this.posLevelRepository.findOne({ where: {
|
||||
posTypeId: requestBody.posTypeId, //ระดับประเภทเดียวกัน ชื่อระดับตำแหน่ง ห้ามซ้ำ
|
||||
posLevelName: requestBody.posLevelName }
|
||||
})
|
||||
if(chkPosLevelName){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อระดับตำแหน่ง: " + requestBody.posLevelName + " มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const validPosLevelAuthority = ["HEAD", "DEPUTY", "GOVERNOR"];
|
||||
if (
|
||||
requestBody.posLevelAuthority == null ||
|
||||
!validPosLevelAuthority.includes(requestBody.posLevelAuthority.toUpperCase())
|
||||
) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. posLevelAuthority");
|
||||
}
|
||||
|
||||
try {
|
||||
posLevel.createdUserId = request.user.sub;
|
||||
posLevel.createdFullName = request.user.name;
|
||||
posLevel.lastUpdateUserId = request.user.sub;
|
||||
posLevel.lastUpdateFullName = request.user.name;
|
||||
await this.posLevelRepository.save(posLevel);
|
||||
return new HttpSuccess(posLevel);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขระดับตำแหน่ง
|
||||
*
|
||||
* @summary ORG_050 - แก้ไขระดับตำแหน่ง (ADMIN) #53
|
||||
*
|
||||
* @param {string} id Id ระดับตำแหน่ง
|
||||
*/
|
||||
@Put("{id}")
|
||||
@Example(
|
||||
{
|
||||
positionName: "นักบริหาร",
|
||||
posTypeRank: 1,
|
||||
},
|
||||
)
|
||||
async editLevel(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: UpdatePosLevel,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const posLevel = await this.posLevelRepository.findOne({ where: { id } });
|
||||
if (!posLevel) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||
}
|
||||
|
||||
const chkPosTypeId = await this.posTypeRepository.findOne({ where: {
|
||||
id: requestBody.posTypeId }
|
||||
})
|
||||
if(!chkPosTypeId){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล posTypeId ไอดีนี้ : " + requestBody.posTypeId);
|
||||
}
|
||||
|
||||
const chkPosLevelName = await this.posLevelRepository.findOne({ where: {
|
||||
id: Not(id),
|
||||
posTypeId: requestBody.posTypeId,
|
||||
posLevelName: requestBody.posLevelName }
|
||||
})
|
||||
if(chkPosLevelName){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อระดับตำแหน่ง: " + requestBody.posLevelName + " มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
const validPosLevelAuthority = ["HEAD", "DEPUTY", "GOVERNOR"];
|
||||
if (
|
||||
requestBody.posLevelAuthority == null ||
|
||||
!validPosLevelAuthority.includes(requestBody.posLevelAuthority.toUpperCase())
|
||||
) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. posLevelAuthority");
|
||||
}
|
||||
|
||||
try {
|
||||
posLevel.lastUpdateUserId = request.user.sub;
|
||||
posLevel.lastUpdateFullName = request.user.name;
|
||||
this.posLevelRepository.merge(posLevel, requestBody);
|
||||
await this.posLevelRepository.save(posLevel);
|
||||
return new HttpSuccess(posLevel.id);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API ลบระดับตำแหน่ง
|
||||
*
|
||||
* @summary ORG_051 - ลบระดับตำแหน่ง (ADMIN) #54
|
||||
*
|
||||
* @param {string} id Id ระดับตำแหน่ง
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteLevel(@Path() id: string) {
|
||||
const delPosLevel = await this.posLevelRepository.findOne({ where: { id } });
|
||||
if (!delPosLevel) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||
}
|
||||
try {
|
||||
await this.posLevelRepository.remove(delPosLevel);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายละเอียดระดับตำแหน่ง
|
||||
*
|
||||
* @summary ORG_052 - รายละเอียดระดับตำแหน่ง (ADMIN) #55
|
||||
*
|
||||
* @param {string} id Id ระดับตำแหน่ง
|
||||
*/
|
||||
@Get("{id}")
|
||||
@Example(
|
||||
{
|
||||
id: "00000000-0000-0000-0000-000000000000",
|
||||
posLevelName: "นักบริหาร",
|
||||
posLevelRank: 1,
|
||||
posLevelAuthority: "HEAD",
|
||||
posTypes: {
|
||||
id: "00000000-0000-0000-0000-000000000000",
|
||||
posTypeName: "นักบริหาร",
|
||||
posTypeRank: 1,
|
||||
},
|
||||
},
|
||||
)
|
||||
async GetLevelDetail(@Path() id: string) {
|
||||
try {
|
||||
const getPosType = await this.posLevelRepository.findOne({
|
||||
select: ["id", "posLevelName", "posLevelRank", "posLevelAuthority"],
|
||||
relations: ["posType"],
|
||||
where: { id: id }
|
||||
});
|
||||
if (!getPosType) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||
}
|
||||
|
||||
const mapPosLevel = {
|
||||
id: getPosType.id,
|
||||
posLevelName: getPosType.posLevelName,
|
||||
posLevelRank: getPosType.posLevelRank,
|
||||
posLevelAuthority: getPosType.posLevelAuthority,
|
||||
posTypes:{
|
||||
id: getPosType.posType.id,
|
||||
posTypeName: getPosType.posType.posTypeName,
|
||||
posTypeRank: getPosType.posType.posTypeRank
|
||||
}
|
||||
}
|
||||
|
||||
return new HttpSuccess(mapPosLevel);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายการระดับตำแหน่ง
|
||||
*
|
||||
* @summary ORG_028 - รายการระดับตำแหน่ง (ADMIN) #30
|
||||
*
|
||||
*/
|
||||
@Get()
|
||||
@Example([
|
||||
{
|
||||
id: "00000000-0000-0000-0000-000000000000",
|
||||
posLevelName: "นักบริหาร",
|
||||
posLevelRank: 1,
|
||||
posLevelAuthority: "HEAD",
|
||||
posTypes: {
|
||||
id: "00000000-0000-0000-0000-000000000000",
|
||||
posTypeName: "นักบริหาร",
|
||||
posTypeRank: 1,
|
||||
},
|
||||
},
|
||||
])
|
||||
async GetPosLevel() {
|
||||
try {
|
||||
const posLevel = await this.posLevelRepository.find({
|
||||
select: ["id", "posLevelName", "posLevelRank", "posLevelAuthority", "posTypeId"],
|
||||
relations: ["posType"],
|
||||
});
|
||||
if (!posLevel) {
|
||||
return new HttpSuccess([]);
|
||||
}
|
||||
const mapPosLevel = posLevel.map((item) => ({
|
||||
id: item.id,
|
||||
posLevelName: item.posLevelName,
|
||||
posLevelRank: item.posLevelRank,
|
||||
posLevelAuthority: item.posLevelAuthority,
|
||||
posTypes: {
|
||||
id: item.posType.id,
|
||||
posTypeName: item.posType.posTypeName,
|
||||
posTypeRank: item.posType.posTypeRank,
|
||||
}
|
||||
}));
|
||||
return new HttpSuccess(mapPosLevel);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -132,6 +132,13 @@ export class PosTypeController extends Controller {
|
|||
if (!delPosType) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||
}
|
||||
const IdExitsInLevel = await this.posLevelRepository.find({
|
||||
where: { posTypeId: id }
|
||||
})
|
||||
if(IdExitsInLevel.length > 0){
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถลบได้ เนื่องจาก id ผูกกับ posLevel",);
|
||||
}
|
||||
|
||||
try {
|
||||
await this.posTypeRepository.remove(delPosType);
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
141
src/controllers/RelationshipController.ts
Normal file
141
src/controllers/RelationshipController.ts
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
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 { CreateRelationship, Relationship } from "../entities/Relationship";
|
||||
@Route("api/v1/org/relationship")
|
||||
@Tags("Relationship")
|
||||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||
export class RelationshipController extends Controller {
|
||||
private relationshipRepository = AppDataSource.getRepository(Relationship);
|
||||
|
||||
/**
|
||||
* API สร้างสถานภาพ
|
||||
*
|
||||
* @summary ORG_060 - สร้างสถานภาพ (ADMIN) #65
|
||||
*
|
||||
*/
|
||||
@Post("relationship")
|
||||
async createRelationship(
|
||||
@Body()
|
||||
requestBody: CreateRelationship,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const relationship = Object.assign(new Relationship(), requestBody);
|
||||
if (!relationship) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
try {
|
||||
relationship.createdUserId = request.user.sub;
|
||||
relationship.createdFullName = request.user.name;
|
||||
relationship.lastUpdateUserId = request.user.sub;
|
||||
relationship.lastUpdateFullName = request.user.name;
|
||||
await this.relationshipRepository.save(relationship);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขสถานภาพ
|
||||
*
|
||||
* @summary ORG_060 - แก้ไขสถานภาพ (ADMIN) #65
|
||||
*
|
||||
* @param {string} id Id ตำแหน่งทางการบริหาร
|
||||
*/
|
||||
@Put("relationship/{id}")
|
||||
async updateRelationship(
|
||||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: CreateRelationship,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const relationship = await this.relationshipRepository.findOne({where: {id: id}});
|
||||
if (!relationship) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
|
||||
}
|
||||
try {
|
||||
relationship.lastUpdateUserId = request.user.sub;
|
||||
relationship.lastUpdateFullName = request.user.name;
|
||||
this.relationshipRepository.merge(relationship, requestBody);
|
||||
await this.relationshipRepository.save(relationship);
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * API ลบอัตรากำลัง
|
||||
// *
|
||||
// * @summary ORG_043 - ลบตำแหน่งทางการบริหาร (ADMIN) #46
|
||||
// *
|
||||
// * @param {string} id Id ตำแหน่งทางการบริหาร
|
||||
// */
|
||||
// @Delete("executive/{id}")
|
||||
// async deletePosExecutive(@Path() id: string) {
|
||||
// const delPosExecutive = await this.posExecutiveRepository.findOne({
|
||||
// where: { id },
|
||||
// });
|
||||
// if (!delPosExecutive) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
|
||||
// }
|
||||
// try {
|
||||
// await this.positionRepository.delete({ posExecutiveId: id });
|
||||
// await this.posExecutiveRepository.delete({ id });
|
||||
// return new HttpSuccess();
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * API รายละเอียดตำแหน่งทางการบริหาร
|
||||
// *
|
||||
// * @summary ORG_044 - รายละเอียดตำแหน่งทางการบริหาร (ADMIN) #47
|
||||
// *
|
||||
// * @param {string} id Id ตำแหน่งทางการบริหาร
|
||||
// */
|
||||
// @Get("executive/{id}")
|
||||
// async detailPosExecutive(@Path() id: string) {
|
||||
|
||||
// const posExecutive = await this.posExecutiveRepository.findOne({
|
||||
// where: { id },
|
||||
// select:[
|
||||
// "id",
|
||||
// "posExecutiveName",
|
||||
// "posExecutivePriority"
|
||||
// ]
|
||||
// });
|
||||
// if (!posExecutive) {
|
||||
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
// }
|
||||
// try {
|
||||
// return new HttpSuccess(posExecutive);
|
||||
// } catch (error) {
|
||||
// return error;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ export class BloodGroup extends EntityBase {
|
|||
|
||||
export class CreateBloodGroup {
|
||||
@Column()
|
||||
bloodGroup: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export type UpdateBloodGroup = Partial<CreateBloodGroup>;
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ export class EducationLevel extends EntityBase {
|
|||
|
||||
export class CreateEducationLevel {
|
||||
@Column()
|
||||
educationLevel: string;
|
||||
name: string;
|
||||
|
||||
@Column()
|
||||
rank: number;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export class Gender extends EntityBase {
|
|||
|
||||
export class CreateGender {
|
||||
@Column()
|
||||
gender: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export type UpdateGender = Partial<CreateGender>;
|
||||
|
|
|
|||
|
|
@ -66,4 +66,5 @@ export class CreatePosLevel {
|
|||
posTypeId: string;
|
||||
}
|
||||
|
||||
export type UpdatePosLevel = Partial<CreatePosLevel>;
|
||||
export type UpdatePosLevel = Partial<CreatePosLevel> & { posLevelAuthority?: PosLevelAuthority };
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export class Prefixe extends EntityBase {
|
|||
|
||||
export class CreatePrefixe {
|
||||
@Column()
|
||||
prefixe: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export type UpdatePrefixe = Partial<CreatePrefixe>;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export class Rank extends EntityBase {
|
|||
|
||||
export class CreateRank {
|
||||
@Column()
|
||||
rank: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export type UpdateRank = Partial<CreateRank>;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export class Relationship extends EntityBase {
|
|||
|
||||
export class CreateRelationship {
|
||||
@Column()
|
||||
relationship: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export type UpdateRelationship = Partial<CreateRelationship>;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export class Religion extends EntityBase {
|
|||
|
||||
export class CreateReligion {
|
||||
@Column()
|
||||
religion: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export type UpdateReligion = Partial<CreateReligion>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue