checkpoint
This commit is contained in:
parent
0acdee9bbc
commit
bd6ac8ae3c
2 changed files with 192 additions and 18 deletions
172
src/controllers/BloodGroupController.ts
Normal file
172
src/controllers/BloodGroupController.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 { 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" ],
|
||||
});
|
||||
|
||||
if (!bloodGroup) {
|
||||
return new HttpSuccess([]);
|
||||
}
|
||||
try {
|
||||
return new HttpSuccess(bloodGroup);
|
||||
} catch (error) {
|
||||
return error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -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) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue