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

This commit is contained in:
Kittapath 2024-05-09 11:11:49 +07:00
commit 5d9e731947
3 changed files with 258 additions and 231 deletions

View file

@ -25,9 +25,9 @@ import {
} from "../entities/kpiUserDevelopment"; } from "../entities/kpiUserDevelopment";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation"; import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
import { Not } from "typeorm"; import { Not, Like } from "typeorm";
@Route("api/v1/kpi/user/achievement/evelopment") @Route("api/v1/kpi/user/achievement/development")
@Tags("KpiUserDevelopment") @Tags("KpiUserDevelopment")
@Security("bearerAuth") @Security("bearerAuth")
@Response( @Response(
@ -58,6 +58,13 @@ import {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมินผู้ใช้งาน"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมินผู้ใช้งาน");
} }
const chkName = await this.kpiUserDevelopmentRepository.findOne({
where: { name: requestBody.name},
});
if (chkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "มีชื่อนี้ในระบบแล้ว");
}
const kpiUserDevelopment = Object.assign(new KpiUserDevelopment(), requestBody); const kpiUserDevelopment = Object.assign(new KpiUserDevelopment(), requestBody);
if (!kpiUserDevelopment) { if (!kpiUserDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
@ -110,6 +117,16 @@ import {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมินผู้ใช้งาน"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมินผู้ใช้งาน");
} }
const chkName = await this.kpiUserDevelopmentRepository.find({
where: {
id: Not(id),
name: requestBody.name
},
});
if (chkName && chkName.length > 0) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "มีชื่อนี้ในระบบแล้ว");
}
// const chk_indicator = await this.kpiUserDevelopmentRepository.findOne({ // const chk_indicator = await this.kpiUserDevelopmentRepository.findOne({
// where: { // where: {
// id: Not(id), // id: Not(id),
@ -141,7 +158,9 @@ import {
*/ */
@Delete("{id}") @Delete("{id}")
async deleteKpiUserDevelopment(@Path() id: string) { async deleteKpiUserDevelopment(@Path() id: string) {
const delKpiUserDevelopment = await this.kpiUserDevelopmentRepository.findOne({ where: { id } }); const delKpiUserDevelopment = await this.kpiUserDevelopmentRepository.findOne({
where: { id },
});
if (!delKpiUserDevelopment) { if (!delKpiUserDevelopment) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลพัฒนาตนเองนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลพัฒนาตนเองนี้");
} }
@ -175,6 +194,9 @@ import {
achievement10: getKpiUserDevelopment.achievement10, achievement10: getKpiUserDevelopment.achievement10,
achievement5: getKpiUserDevelopment.achievement5, achievement5: getKpiUserDevelopment.achievement5,
achievement0: getKpiUserDevelopment.achievement0, achievement0: getKpiUserDevelopment.achievement0,
isDevelopment70: getKpiUserDevelopment.isDevelopment70,
isDevelopment20: getKpiUserDevelopment.isDevelopment20,
isDevelopment10: getKpiUserDevelopment.isDevelopment10,
}; };
return new HttpSuccess(mapKpiUserDevelopment); return new HttpSuccess(mapKpiUserDevelopment);
@ -205,38 +227,37 @@ import {
achievement10: item.achievement10, achievement10: item.achievement10,
achievement5: item.achievement5, achievement5: item.achievement5,
achievement0: item.achievement0, achievement0: item.achievement0,
isDevelopment70: item.isDevelopment70,
isDevelopment20: item.isDevelopment20,
isDevelopment10: item.isDevelopment10,
})); }));
return new HttpSuccess(mapKpiUserDevelopment); return new HttpSuccess(mapKpiUserDevelopment);
} }
/** // /**
* API // * API กรอกระดับคะแนนงานตามแผนปฏิบัติราชการประจำปี
* // *
* @summary // * @summary กรอกระดับคะแนนงานตามแผนปฏิบัติราชการประจำปี
* // *
* // *
*/ // */
@Post("point") // @Post("point")
async CreateKpiUserDevelopmentPoint( // async CreateKpiUserDevelopmentPoint(
@Body() requestBody: KpiUserDevelopmentDataPoint[], // @Body() requestBody: KpiUserDevelopmentDataPoint[],
@Request() request: { user: Record<string, any> }, // @Request() request: { user: Record<string, any> },
) { // ) {
for (const item of requestBody) { // for (const item of requestBody) {
const kpiUserDevelopment = await this.kpiUserDevelopmentRepository.findOne({ // const kpiUserDevelopment = await this.kpiUserDevelopmentRepository.findOne({
where: { id: item.id }, // where: { id: item.id },
}); // });
if (!kpiUserDevelopment) { // if (!kpiUserDevelopment) {
throw new HttpError( // throw new HttpError(HttpStatusCode.NOT_FOUND, `ไม่พบข้อมูลพัฒนาตนเองนี้: ${item.id}`);
HttpStatusCode.NOT_FOUND, // }
`ไม่พบข้อมูลพัฒนาตนเองนี้: ${item.id}`, // this.kpiUserDevelopmentRepository.merge(kpiUserDevelopment, item);
); // kpiUserDevelopment.lastUpdateUserId = request.user.sub;
// kpiUserDevelopment.lastUpdateFullName = request.user.name;
// await this.kpiUserDevelopmentRepository.save(kpiUserDevelopment);
// }
// return new HttpSuccess();
// }
} }
this.kpiUserDevelopmentRepository.merge(kpiUserDevelopment, item);
kpiUserDevelopment.lastUpdateUserId = request.user.sub;
kpiUserDevelopment.lastUpdateFullName = request.user.name;
await this.kpiUserDevelopmentRepository.save(kpiUserDevelopment);
}
return new HttpSuccess();
}
}

View file

@ -240,25 +240,8 @@ export class KpiUserEvaluationController extends Controller {
@Get("{id}") @Get("{id}")
async GetKpiUserEvaluationById(@Path() id: string) { async GetKpiUserEvaluationById(@Path() id: string) {
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({ const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
relations:["kpiPeriod"],
where: { id: id }, where: { id: id },
select: [
"id",
"profileId",
"prefix",
"firstName",
"lastName",
"kpiPeriodId",
"evaluationStatus",
"evaluationResults",
"createdAt",
"evaluatorId",
"commanderId",
"commanderHighId",
"plannedPoint",
"rolePoint",
"specialPoint",
"capacityPoint",
],
}); });
if (!kpiUserEvaluation) { if (!kpiUserEvaluation) {
throw new HttpError( throw new HttpError(
@ -266,7 +249,27 @@ export class KpiUserEvaluationController extends Controller {
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
); );
} }
return new HttpSuccess(kpiUserEvaluation); const mapData = {
id: kpiUserEvaluation.id,
profileId: kpiUserEvaluation.profileId,
prefix: kpiUserEvaluation.prefix,
firstName: kpiUserEvaluation.firstName,
lastName: kpiUserEvaluation.lastName,
evaluationStatus: kpiUserEvaluation.evaluationStatus,
evaluationResults: kpiUserEvaluation.evaluationResults,
createdAt: kpiUserEvaluation.createdAt,
evaluatorId: kpiUserEvaluation.evaluatorId,
commanderId: kpiUserEvaluation.commanderId,
commanderHighId: kpiUserEvaluation.commanderHighId,
plannedPoint: kpiUserEvaluation.plannedPoint,
rolePoint: kpiUserEvaluation.rolePoint,
specialPoint: kpiUserEvaluation.specialPoint,
capacityPoint: kpiUserEvaluation.capacityPoint,
kpiPeriodId: kpiUserEvaluation.kpiPeriodId,
year: kpiUserEvaluation.kpiPeriod == null ? null : kpiUserEvaluation.kpiPeriod.year,
durationKPI: kpiUserEvaluation.kpiPeriod == null ? null : kpiUserEvaluation.kpiPeriod.durationKPI,
}
return new HttpSuccess(mapData);
} }
/** /**
@ -286,6 +289,7 @@ export class KpiUserEvaluationController extends Controller {
) { ) {
const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation) const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation)
.createQueryBuilder("kpiUserEvaluation") .createQueryBuilder("kpiUserEvaluation")
.leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod")
.andWhere(kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1", { .andWhere(kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1", {
kpiPeriodId: kpiPeriodId, kpiPeriodId: kpiPeriodId,
}) })
@ -318,6 +322,8 @@ export class KpiUserEvaluationController extends Controller {
rolePoint: item.rolePoint, rolePoint: item.rolePoint,
specialPoint: item.specialPoint, specialPoint: item.specialPoint,
capacityPoint: item.capacityPoint, capacityPoint: item.capacityPoint,
year: item.kpiPeriod ? item.kpiPeriod.year : null,
durationKPI: item.kpiPeriod ? item.kpiPeriod.durationKPI : null,
})); }));
return new HttpSuccess({ data: mapData, total }); return new HttpSuccess({ data: mapData, total });
} }

View file

@ -87,7 +87,7 @@ export class KpiUserDevelopment extends EntityBase {
export class CreateKpiUserDevelopment { export class CreateKpiUserDevelopment {
@Column() @Column()
name: string | null; name: string;
@Column() @Column()
target: string | null; target: string | null;
@Column() @Column()
@ -110,7 +110,7 @@ export class CreateKpiUserDevelopment {
export class UpdateKpiUserDevelopment { export class UpdateKpiUserDevelopment {
@Column() @Column()
name: string | null; name: string;
@Column() @Column()
target: string | null; target: string | null;
@Column() @Column()