add reject

This commit is contained in:
kittapath 2025-01-29 10:21:08 +07:00
parent 9646659f4c
commit 6f1b3f9216
5 changed files with 262 additions and 7 deletions

View file

@ -38,6 +38,8 @@ import { KpiLink } from "../entities/kpiLink";
import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
import { KpiUserRejectAgreement } from "../entities/kpiUserRejectAgreement";
import { KpiUserRejectResult } from "../entities/kpiUserRejectResult";
@Route("api/v1/kpi/user/evaluation")
@Tags("kpiUserEvaluation")
@ -53,6 +55,8 @@ export class KpiUserEvaluationController extends Controller {
private kpiCapacityRepository = AppDataSource.getRepository(KpiCapacity);
private kpiPositionRepository = AppDataSource.getRepository(Position);
private kpiLinkRepository = AppDataSource.getRepository(KpiLink);
private kpiUserRejectAgreementRepository = AppDataSource.getRepository(KpiUserRejectAgreement);
private kpiUserRejectResultRepository = AppDataSource.getRepository(KpiUserRejectResult);
/**
* API
@ -195,6 +199,8 @@ export class KpiUserEvaluationController extends Controller {
evaluatorId: item.evaluatorId,
commanderId: item.commanderId,
commanderHighId: item.commanderHighId,
reasonReject: item.reasonReject,
isReject: item.reasonReject ? true : false,
}));
return new HttpSuccess({ data: mapData, total });
}
@ -1004,6 +1010,8 @@ export class KpiUserEvaluationController extends Controller {
})
.then(() => {})
.catch(() => {});
let _null: any = null;
kpiUserEvaluation.reasonReject = _null;
} else if (requestBody.status.trim().toUpperCase() == "EVALUATING_EVALUATOR") {
await new CallAPI()
.PostData(request, "/placement/noti/profile", {
@ -1019,6 +1027,8 @@ export class KpiUserEvaluationController extends Controller {
.catch(() => {});
}
const before = structuredClone(kpiUserEvaluation);
let _null: any = null;
kpiUserEvaluation.reasonReject = _null;
kpiUserEvaluation.evaluationStatus = requestBody.status.trim().toUpperCase();
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
@ -1028,6 +1038,118 @@ export class KpiUserEvaluationController extends Controller {
return new HttpSuccess(kpiUserEvaluation.id);
}
/**
* API (USER)
*
* @summary (USER)
*
* @param {string} id Guid, *Id (USER)
*/
@Put("reject-agreement/{id}")
async updateKpiUserStatusRejectAgreementEvaluation(
@Path() id: string,
@Body() requestBody: { reason: string },
@Request() request: RequestWithUser,
) {
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
where: { id: id },
});
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
await new CallAPI()
.PostData(request, "/placement/noti/profile", {
subject: `${kpiUserEvaluation.prefix}${kpiUserEvaluation.firstName} ${kpiUserEvaluation.lastName} ไม่อนุมัติเนื่องจาก: ${requestBody.reason}`,
body: `${kpiUserEvaluation.prefix}${kpiUserEvaluation.firstName} ${kpiUserEvaluation.lastName} ไม่อนุมัติเนื่องจาก: ${requestBody.reason}`,
receiverUserId: kpiUserEvaluation.profileId,
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then(async () => {})
.catch((error) => {
console.error("Error details:", error.response.data);
});
const before = structuredClone(kpiUserEvaluation);
kpiUserEvaluation.evaluationStatus = "NEW";
kpiUserEvaluation.reasonReject = requestBody.reason;
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
kpiUserEvaluation.lastUpdatedAt = new Date();
let kpiReject = {
reason: requestBody.reason,
createdUserId: request.user.sub,
createdFullName: request.user.name,
lastUpdateUserId: request.user.sub,
lastUpdateFullName: request.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
await this.kpiUserRejectAgreementRepository.save(kpiReject);
setLogDataDiff(request, { before, after: kpiUserEvaluation });
return new HttpSuccess(kpiUserEvaluation.id);
}
/**
* API (USER)
*
* @summary (USER)
*
* @param {string} id Guid, *Id (USER)
*/
@Put("reject-result/{id}")
async updateKpiUserStatusRejectResultEvaluation(
@Path() id: string,
@Body() requestBody: { reason: string },
@Request() request: RequestWithUser,
) {
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
where: { id: id },
});
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
await new CallAPI()
.PostData(request, "/placement/noti/profile", {
subject: `${kpiUserEvaluation.prefixEvaluator}${kpiUserEvaluation.firstNameEvaluator} ${kpiUserEvaluation.lastNameEvaluator} ไม่อนุมัติเนื่องจาก: ${requestBody.reason}`,
body: `${kpiUserEvaluation.prefixEvaluator}${kpiUserEvaluation.firstNameEvaluator} ${kpiUserEvaluation.lastNameEvaluator} ไม่อนุมัติเนื่องจาก: ${requestBody.reason}`,
receiverUserId: kpiUserEvaluation.evaluatorId,
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then(() => {})
.catch(() => {});
const before = structuredClone(kpiUserEvaluation);
kpiUserEvaluation.evaluationStatus = "EVALUATING_EVALUATOR";
kpiUserEvaluation.reasonReject = requestBody.reason;
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
kpiUserEvaluation.lastUpdatedAt = new Date();
let kpiReject = {
reason: requestBody.reason,
createdUserId: request.user.sub,
createdFullName: request.user.name,
lastUpdateUserId: request.user.sub,
lastUpdateFullName: request.user.name,
createdAt: new Date(),
lastUpdatedAt: new Date(),
};
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
await this.kpiUserRejectResultRepository.save(kpiReject);
setLogDataDiff(request, { before, after: kpiUserEvaluation });
return new HttpSuccess(kpiUserEvaluation.id);
}
/**
* API (USER)
*
@ -1081,6 +1203,8 @@ export class KpiUserEvaluationController extends Controller {
child2: kpiUserEvaluation.child2,
child3: kpiUserEvaluation.child3,
child4: kpiUserEvaluation.child4,
reasonReject: kpiUserEvaluation.reasonReject,
isReject: kpiUserEvaluation.reasonReject ? true : false,
year: kpiUserEvaluation.kpiPeriod == null ? null : kpiUserEvaluation.kpiPeriod.year,
durationKPI:
kpiUserEvaluation.kpiPeriod == null ? null : kpiUserEvaluation.kpiPeriod.durationKPI,
@ -1159,6 +1283,8 @@ export class KpiUserEvaluationController extends Controller {
rolePoint: item.rolePoint,
specialPoint: item.specialPoint,
capacityPoint: item.capacityPoint,
reasonReject: item.reasonReject,
isReject: item.reasonReject ? true : false,
year: item.kpiPeriod ? item.kpiPeriod.year : null,
durationKPI: item.kpiPeriod ? item.kpiPeriod.durationKPI : null,
}));
@ -1281,6 +1407,8 @@ export class KpiUserEvaluationController extends Controller {
item.evaluationStatus = requestBody.status.trim().toUpperCase();
}
const before = null;
let _null: any = null;
item.reasonReject = _null;
item.lastUpdateUserId = request.user.sub;
item.lastUpdateFullName = request.user.name;
item.lastUpdatedAt = new Date();
@ -1446,6 +1574,8 @@ export class KpiUserEvaluationController extends Controller {
// // item.evaluationStatus = requestBody.status.trim().toUpperCase();
// }
const before = null;
let _null: any = null;
item.reasonReject = _null;
item.lastUpdateUserId = request.user.sub;
item.lastUpdateFullName = request.user.name;
item.lastUpdatedAt = new Date();
@ -1915,24 +2045,24 @@ export class KpiUserEvaluationController extends Controller {
}
/**
* API 5
* API 5
*
* @summary 5
* @summary 5
*
* @param {string} id Guid, *Id
* @param {string} id Guid, *Id
*/
@Get("summaryFiveYear/{id}")
async getsummaryFiveYear(@Path() id: string, @Request() request: RequestWithUser) {
const year = new Date().getFullYear();
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.find({
relations: ["kpiPeriod"],
where: {
profileId: id ,
where: {
profileId: id,
evaluationResults: Not("PENDING"),
evaluationStatus: "KP7",
kpiPeriod: {
year: MoreThanOrEqual(year - 5),
}
year: MoreThanOrEqual(year - 5),
},
},
select: ["id", "evaluationStatus", "evaluationResults", "kpiPeriod"],
});