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

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-01-21 15:01:32 +07:00
commit 86f04ed0f9
5 changed files with 128 additions and 15 deletions

View file

@ -20,13 +20,15 @@ import { Survey } from "../entities/Survey";
import { Assign } from "../entities/Assign";
import { AppDataSource } from "../database/data-source";
import CallAPI from "../interfaces/call-api";
import permission from "../interfaces/permission";
import { Brackets } from "typeorm";
@Route("api/v1/probation/survey")
@Tags("Survey")
@Security("bearerAuth")
// @Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
export class SurveyController extends Controller {
private surveyRepository = AppDataSource.getRepository(Survey);
@ -52,7 +54,10 @@ export class SurveyController extends Controller {
order: { date_start: "DESC" },
});
if (!dataAssign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบผลการประเมินการทดลองปฏิบัติหน้าที่ราชการนี้");
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบผลการประเมินการทดลองปฏิบัติหน้าที่ราชการนี้",
);
}
const assign_id = dataAssign.id;
@ -74,17 +79,94 @@ export class SurveyController extends Controller {
async PostSurvey(
@Query() assign_id: string,
@Body() requestBody: any,
@Request() request: RequestWithUser
@Request() request: RequestWithUser,
) {
const personalId = await new CallAPI()
.GetData(request, "/org/profile/keycloak")
.catch((error) => {
console.error("Error calling API:", error);
});
const before = null;
const data = await {
...requestBody,
personal_id: request.user.sub,
personal_id: personalId,
assign_id,
createdUserId: request.user.sub,
updateUserId: request.user.sub,
};
await this.surveyRepository.save(data, { data: request });
setLogDataDiff(request, { before, after: data });
return new HttpSuccess();
}
/**
* API Admin
*
* @summary Admin
*
*/
@Get("/admin")
async GetSurveyAdmin(
@Query() year: number = new Date().getFullYear(),
@Query() keyword: string = "",
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Request() request: RequestWithUser,
) {
// await new permission().PermissionUpdate(request, "SYS_PROBATION");
const start = new Date("01-01-" + year);
const end = new Date("12-31-" + year);
const searchKeyword = await (keyword ? keyword.trim() : null);
const [lists, total] = await AppDataSource.getRepository(Survey)
.createQueryBuilder("survey")
.leftJoinAndSelect("survey.personal", "personal")
.where(`survey.createdAt BETWEEN '${start.toISOString()}' AND '${end.toISOString()}'`)
.andWhere(
new Brackets((qb) => {
qb.orWhere(
searchKeyword
? `CONCAT(personal.prefixName, personal.firstName," ",personal.lastName) like '%${keyword}%'`
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
);
qb.orWhere(
searchKeyword
? `CONCAT(personal.positionName, personal.positionLevelName) like '%${keyword}%'`
: "1=1",
{
keyword: `%${searchKeyword}%`,
},
);
}),
)
.orderBy("survey.createdAt", "DESC")
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
const data = lists.map((item) => {
return {
createdAt: item.createdAt,
personal_id: item.personal_id,
assign_id: item.assign_id,
answer1: item.answer1,
answer2: item.answer2,
answer3: item.answer3,
fullname: item.personal
? `${item.personal.prefixName}${item.personal.firstName} ${item.personal.lastName}`
: "",
position: item.personal
? `${item.personal.positionName}${item.personal.positionLevelName}`
: "",
};
});
return new HttpSuccess({ data, total: total });
}
}