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

This commit is contained in:
Kittapath 2024-02-05 12:50:12 +07:00
commit 15192f8f0d
8 changed files with 208 additions and 25 deletions

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 { CreateBloodGroup, BloodGroup } from "../entities/BloodGroup";
import { Not } from "typeorm";
@Route("api/v1/org/bloodGroup")
@Tags("BloodGroup")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class BloodGroupController extends Controller {
private bloodGroupRepository = AppDataSource.getRepository(BloodGroup);
/**
* API
*
* @summary ORG_062 - (ADMIN) #66
*
*/
@Post()
async createBloodGroup(
@Body()
requestBody: CreateBloodGroup,
@Request() request: { user: Record<string, any> },
) {
const checkName = await this.bloodGroupRepository.findOne({
where: { name: requestBody.name },
});
if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
}
try {
const bloodGroup = Object.assign(new BloodGroup(), requestBody);
bloodGroup.createdUserId = request.user.sub;
bloodGroup.createdFullName = request.user.name;
bloodGroup.lastUpdateUserId = request.user.sub;
bloodGroup.lastUpdateFullName = request.user.name;
await this.bloodGroupRepository.save(bloodGroup);
return new HttpSuccess();
} catch (error) {
return error;
}
}
/**
* API
*
* @summary ORG_062 - (ADMIN) #66
*
* @param {string} id Id
*/
@Put("{id}")
async updateBloodGroup(
@Path() id: string,
@Body()
requestBody: CreateBloodGroup,
@Request() request: { user: Record<string, any> },
) {
const bloodGroup = await this.bloodGroupRepository.findOne({ where: { id: id } });
if (!bloodGroup) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลไอดีนี้ : " + id);
}
const checkName = await this.bloodGroupRepository.findOne({
where: { id:Not(id),name: requestBody.name },
});
if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
}
try {
bloodGroup.lastUpdateUserId = request.user.sub;
bloodGroup.lastUpdateFullName = request.user.name;
this.bloodGroupRepository.merge(bloodGroup, requestBody);
await this.bloodGroupRepository.save(bloodGroup);
return new HttpSuccess();
} catch (error) {
return error;
}
}
/**
* API
*
* @summary ORG_062 - (ADMIN) #66
*
* @param {string} id Id
*/
@Delete("{id}")
async deleteBloodGroup(@Path() id: string) {
const delBloodGroup = await this.bloodGroupRepository.findOne({
where: { id },
});
if (!delBloodGroup) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งตามไอดีนี้ : " + id);
}
try {
await this.bloodGroupRepository.delete({ id: id });
return new HttpSuccess();
} catch (error) {
return error;
}
}
/**
* API
*
* @summary ORG_062 - (ADMIN) #66
*
* @param {string} id Id
*/
@Get("{id}")
async detailBloodGroup(@Path() id: string) {
const bloodGroup = await this.bloodGroupRepository.findOne({
where: { id },
select: ["id", "name"],
});
if (!bloodGroup) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
try {
return new HttpSuccess(bloodGroup);
} catch (error) {
return error;
}
}
/**
* API
*
* @summary ORG_062 - (ADMIN) #66
*
*/
@Get()
async listBloodGroup() {
const bloodGroup = await this.bloodGroupRepository.find({
select: ["id", "name" , "createdAt" , "lastUpdatedAt" , "createdFullName" , "lastUpdateFullName"],
order:{ createdAt:"ASC" }
});
if (!bloodGroup) {
return new HttpSuccess([]);
}
try {
return new HttpSuccess(bloodGroup);
} catch (error) {
return error;
}
}
}

View file

@ -156,7 +156,8 @@ export class EducationLevelController extends Controller {
@Get()
async listEducationLevel() {
const educationLevel = await this.educationLevelRepository.find({
select: ["id", "name" ],
select: ["id", "name" , "createdAt" , "lastUpdatedAt" , "createdFullName" , "lastUpdateFullName"],
order:{ createdAt:"ASC" }
});
if (!educationLevel) {

View file

@ -38,9 +38,11 @@ export class GenderController extends Controller {
*
*/
@Get()
async Get() {
async GetResult() {
console.log("asds")
const _gender = await this.genderRepository.find({
select: ["id", "name"],
select: ["id", "name" , "createdAt" , "lastUpdatedAt" , "createdFullName" , "lastUpdateFullName"],
order:{ createdAt:"ASC" }
});
if (!_gender) {
return new HttpSuccess([]);
@ -48,6 +50,7 @@ export class GenderController extends Controller {
try {
return new HttpSuccess(_gender);
} catch (error) {
console.log(error)
return error;
}
}

View file

@ -691,29 +691,31 @@ export class PositionController extends Controller {
keywordAsInt = "";
}
masterId = [...new Set(masterId)];
const posMaster = await this.posMasterRepository.find({
where: [
{
...checkChildConditions,
...typeCondition,
},
{
...checkChildConditions,
...typeCondition,
id: In(masterId),
},
{
...checkChildConditions,
...typeCondition,
posMasterNo: Like(`%${keywordAsInt}%`),
},
],
const keywordConditions = [
{
...checkChildConditions,
...typeCondition,
},
{
...checkChildConditions,
...typeCondition,
id: In(masterId),
},
{
...checkChildConditions,
...typeCondition,
posMasterNo: Like(`%${keywordAsInt}%`),
},
];
const [posMaster, total] = await this.posMasterRepository.findAndCount({
where: keywordConditions,
order: { posMasterOrder: "ASC" },
relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3", "orgChild4"],
skip: (body.page - 1) * body.pageSize,
take: body.pageSize,
});
const total = posMaster.length;
const formattedData = await Promise.all(
posMaster.map(async (posMaster) => {

View file

@ -40,7 +40,8 @@ export class PrefixController extends Controller {
@Get()
async Get() {
const _prefix = await this.prefixRepository.find({
select: ["id", "name"],
select: ["id", "name" , "createdAt" , "lastUpdatedAt" , "createdFullName" , "lastUpdateFullName"] ,
order:{ createdAt:"ASC" }
});
if (!_prefix) {
return new HttpSuccess([]);

View file

@ -156,7 +156,8 @@ import {
@Get()
async listRank() {
const rank = await this.rankRepository.find({
select: ["id", "name" ],
select: ["id", "name" , "createdAt" , "lastUpdatedAt" , "createdFullName" , "lastUpdateFullName"],
order:{ createdAt:"ASC" }
});
if (!rank) {

View file

@ -156,7 +156,8 @@ export class RelationshipController extends Controller {
@Get()
async listRelationship() {
const relationship = await this.relationshipRepository.find({
select: ["id", "name"],
select: ["id", "name" , "createdAt" , "lastUpdatedAt" , "createdFullName" , "lastUpdateFullName"],
order:{ createdAt:"ASC" }
});
if (!relationship) {
return new HttpSuccess([]);

View file

@ -156,7 +156,8 @@ export class ReligionController extends Controller {
@Get()
async listReligion() {
const religion = await this.religionRepository.find({
select: ["id", "name" ],
select: ["id", "name" , "createdAt" , "lastUpdatedAt" , "createdFullName" , "lastUpdateFullName"],
order:{ createdAt:"ASC" }
});
if (!religion) {