เพิ่มฟิวผู้บังคับ

This commit is contained in:
Kittapath 2024-04-26 13:08:23 +07:00
parent ba00645cb8
commit ecbb9c0d9f
7 changed files with 171 additions and 64 deletions

View file

@ -37,32 +37,31 @@ export class kpiEvaluationController extends Controller {
* @param id
*/
@Put()
async updateKpiEvaluations(
@Body() requestBody: updateKpiEvaluation[],
@Request() request: { user: Record<string, any> },
) {
const updatedIds: string[] = [];
async updateKpiEvaluations(
@Body() requestBody: updateKpiEvaluation[],
@Request() request: { user: Record<string, any> },
) {
const updatedIds: string[] = [];
for (const item of requestBody) {
const kpiEvaluation = await this.kpiEvaluationRepository.findOne({
where: { id: item.id },
});
if (!kpiEvaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, `ไม่พบข้อมูลเกณฑ์การประเมินนี้: ${item.id}`);
for (const item of requestBody) {
const kpiEvaluation = await this.kpiEvaluationRepository.findOne({
where: { id: item.id },
});
if (!kpiEvaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, `ไม่พบข้อมูลเกณฑ์การประเมินนี้: ${item.id}`);
}
this.kpiEvaluationRepository.merge(kpiEvaluation, item);
kpiEvaluation.lastUpdateUserId = request.user.sub;
kpiEvaluation.lastUpdateFullName = request.user.name;
await this.kpiEvaluationRepository.save(kpiEvaluation);
updatedIds.push(item.id);
}
this.kpiEvaluationRepository.merge(kpiEvaluation, item);
kpiEvaluation.lastUpdateUserId = request.user.sub;
kpiEvaluation.lastUpdateFullName = request.user.name;
await this.kpiEvaluationRepository.save(kpiEvaluation);
updatedIds.push(item.id);
return new HttpSuccess();
}
return new HttpSuccess();
}
/**
* API list
* @param page
@ -81,20 +80,20 @@ async updateKpiEvaluations(
where: [{ description: Like(`%${keyword}%`) }],
};
whereClause.where.push({ level: Like(`%${keyword}%`) });
}
const [kpiEvaluation, total] = await this.kpiEvaluationRepository.findAndCount({
...whereClause,
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
order:{
level: "DESC"}
order: {
level: "DESC",
},
});
const formatted = kpiEvaluation.map((item) => ({
id: item.id,
level: item.level,
description: item.description
description: item.description,
}));
return new HttpSuccess({ data: formatted, total });
}

View file

@ -24,6 +24,7 @@ import { KpiPeriod } from "../entities/kpiPeriod";
import {
KpiUserEvaluation,
createKpiUserEvaluation,
updateKpiUserCheckEvaluation,
updateKpiUserEvaluation,
} from "../entities/kpiUserEvaluation";
import { Like, In } from "typeorm";
@ -120,6 +121,35 @@ export class KpiUserEvaluationController extends Controller {
return new HttpSuccess(kpiUserEvaluation.id);
}
/**
* API (USER)
*
* @summary (USER)
*
* @param {string} id Guid, *Id (USER)
*/
@Put("check/{id}")
async updateKpiUserCheckEvaluation(
@Path() id: string,
@Body() requestBody: updateKpiUserCheckEvaluation,
@Request() request: { user: Record<string, any> },
) {
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
where: { id: id },
});
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
Object.assign(kpiUserEvaluation, requestBody);
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation);
return new HttpSuccess(kpiUserEvaluation.id);
}
/**
* API (USER)
*
@ -136,7 +166,7 @@ export class KpiUserEvaluationController extends Controller {
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
where: { id: id },
});
if (!KpiUserEvaluation) {
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
@ -153,15 +183,13 @@ export class KpiUserEvaluationController extends Controller {
);
}
if (kpiUserEvaluation) {
// kpiUserEvaluation.evaluationStatus = requestBody.evaluationStatus
// kpiUserEvaluation.evaluationResults = requestBody.evaluationResults
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
this.kpiUserEvalutionRepository.merge(kpiUserEvaluation, requestBody);
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation);
return new HttpSuccess(kpiUserEvaluation.id);
}
// kpiUserEvaluation.evaluationStatus = requestBody.evaluationStatus
// kpiUserEvaluation.evaluationResults = requestBody.evaluationResults
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
this.kpiUserEvalutionRepository.merge(kpiUserEvaluation, requestBody);
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation);
return new HttpSuccess(kpiUserEvaluation.id);
}
/**
@ -173,7 +201,7 @@ export class KpiUserEvaluationController extends Controller {
*/
@Get("{id}")
async GetKpiUserEvaluationById(@Path() id: string) {
const KpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
where: { id: id },
select: [
"id",
@ -187,13 +215,13 @@ export class KpiUserEvaluationController extends Controller {
"createdAt",
],
});
if (!KpiUserEvaluation) {
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
return new HttpSuccess(KpiUserEvaluation);
return new HttpSuccess(kpiUserEvaluation);
}
/**
@ -242,16 +270,16 @@ export class KpiUserEvaluationController extends Controller {
*/
@Delete("{id}")
async deleteKpiUserEvaluation(@Path() id: string) {
const KpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
where: { id: id },
});
if (!KpiUserEvaluation) {
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
await this.kpiUserEvalutionRepository.remove(KpiUserEvaluation);
await this.kpiUserEvalutionRepository.remove(kpiUserEvaluation);
return new HttpSuccess();
}
}

View file

@ -74,9 +74,12 @@ export class KpiUserPlannedController extends Controller {
kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
kpiPlanId: requestBody.kpiPlanId,
},
})
});
if (chk_indicator) {
throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ");
throw new HttpError(
HttpStatusCode.CONFLICT,
"ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ",
);
}
const kpiUserPlanned = Object.assign(new KpiUserPlanned(), requestBody);
@ -105,21 +108,23 @@ export class KpiUserPlannedController extends Controller {
@Body() requestBody: UpdateKpiUserPlanned,
@Request() request: { user: Record<string, any> },
) {
const kpiUserPlanned = await this.kpiUserPlannedRepository.findOne({ where: { id } });
if (!kpiUserPlanned) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามแผนปฏิบัติราชการประจำปีนี้");
}
const chk_indicator = await this.kpiUserPlannedRepository.findOne({
where: {
id: Not(id),
kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
kpiPlanId: requestBody.kpiPlanId,
},
})
});
if (chk_indicator) {
throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ");
throw new HttpError(
HttpStatusCode.CONFLICT,
"ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ",
);
}
kpiUserPlanned.lastUpdateUserId = request.user.sub;

View file

@ -76,15 +76,18 @@ export class KpiUserRoleController extends Controller {
if (!kpiUserRole) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const chk_indicator = await this.kpiUserRoleRepository.findOne({
where: {
kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
kpiRoleId: requestBody.kpiRoleId,
},
})
});
if (chk_indicator) {
throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ");
throw new HttpError(
HttpStatusCode.CONFLICT,
"ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ",
);
}
kpiUserRole.createdUserId = request.user.sub;
@ -128,16 +131,19 @@ export class KpiUserRoleController extends Controller {
"ไม่พบข้อมูลแบบประเมินตามหน้าที่ความรับผิดชอบหลัก",
);
}
const chk_indicator = await this.kpiUserRoleRepository.findOne({
where: {
id: Not(id),
kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
kpiRoleId: requestBody.kpiRoleId,
},
})
});
if (chk_indicator) {
throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ");
throw new HttpError(
HttpStatusCode.CONFLICT,
"ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ",
);
}
kpiUserRole.lastUpdateUserId = request.user.sub;

View file

@ -63,17 +63,21 @@ export class KpiUserSpecialController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const chk_indicator = await this.kpiUserSpecialRepository.findOne({
where: {
kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
},
})
if (chk_indicator && chk_indicator.including == requestBody.including || chk_indicator && chk_indicator.includingName == requestBody.includingName) {
throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ");
});
if (
(chk_indicator && chk_indicator.including == requestBody.including) ||
(chk_indicator && chk_indicator.includingName == requestBody.includingName)
) {
throw new HttpError(
HttpStatusCode.CONFLICT,
"ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ",
);
}
kpiUserSpecial.createdUserId = request.user.sub;
kpiUserSpecial.createdFullName = request.user.name;
kpiUserSpecial.lastUpdateUserId = request.user.sub;
@ -111,9 +115,15 @@ export class KpiUserSpecialController extends Controller {
id: Not(id),
kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
},
})
if (chk_indicator && chk_indicator.including == requestBody.including || chk_indicator && chk_indicator.includingName == requestBody.includingName) {
throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ");
});
if (
(chk_indicator && chk_indicator.including == requestBody.including) ||
(chk_indicator && chk_indicator.includingName == requestBody.includingName)
) {
throw new HttpError(
HttpStatusCode.CONFLICT,
"ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ",
);
}
kpiUserSpecial.lastUpdateUserId = request.user.sub;