fix: delete kpi row

This commit is contained in:
Warunee Tamkoo 2026-02-25 21:11:52 +07:00
parent 1ccde3f38d
commit fe37dc82be

View file

@ -41,10 +41,11 @@ import { resolveNodeId, resolveNodeLevel, setLogDataDiff } from "../interfaces/u
import { KpiUserRejectAgreement } from "../entities/kpiUserRejectAgreement";
import { KpiUserRejectResult } from "../entities/kpiUserRejectResult";
import { KpiUserCapacity } from "../entities/kpiUserCapacity";
import { KpiUserPlanned } from "../entities/kpiUserPlanned"
import { KpiUserPlanned } from "../entities/kpiUserPlanned";
import { KpiUserRole } from "../entities/kpiUserRole";
import { KpiUserSpecial } from "../entities/kpiUserSpecial";
import { KpiUserDevelopment } from "../entities/kpiUserDevelopment";
import { KpiUserEvaluationReasonPlan } from "../entities/kpiUserEvaluationReasonPlan";
@Route("api/v1/kpi/user/evaluation")
@Tags("kpiUserEvaluation")
@ -119,7 +120,7 @@ export class KpiUserEvaluationController extends Controller {
? requestBody.status.trim().toUpperCase() == "NEW"
? `kpiUserEvaluation.evaluationStatus LIKE CASE WHEN kpiUserEvaluation.evaluatorId = "${profileId}" THEN "NEW_EVALUATOR" WHEN kpiUserEvaluation.commanderId = "${profileId}" THEN "NEW_COMMANDER" WHEN kpiUserEvaluation.commanderHighId = "${profileId}" THEN "NEW_COMMANDER_HIGH" ELSE "${requestBody.status.trim().toUpperCase()}" END`
: requestBody.status.trim().toUpperCase() == "EVALUATING_EVALUATOR" ||
requestBody.status.trim().toUpperCase() == "EVALUATING"
requestBody.status.trim().toUpperCase() == "EVALUATING"
? "kpiUserEvaluation.evaluationStatus LIKE :status"
: requestBody.status.trim().toUpperCase() == "SUMMARY"
? "kpiUserEvaluation.evaluationStatus LIKE :status"
@ -130,8 +131,8 @@ export class KpiUserEvaluationController extends Controller {
requestBody.status == null || requestBody.status == undefined
? null
: requestBody.status.trim().toUpperCase() == "EVALUATING" ||
requestBody.status.trim().toUpperCase() == "EVALUATING_EVALUATOR" ||
requestBody.status.trim().toUpperCase() == "SUMMARY"
requestBody.status.trim().toUpperCase() == "EVALUATING_EVALUATOR" ||
requestBody.status.trim().toUpperCase() == "SUMMARY"
? requestBody.status.trim().toUpperCase() == "SUMMARY"
? `%${requestBody.status.trim().toUpperCase()}%`
: `%EVALUATING%`
@ -255,7 +256,7 @@ export class KpiUserEvaluationController extends Controller {
"CONCAT(kpiUserEvaluation.prefix, kpiUserEvaluation.firstName, ' ', kpiUserEvaluation.lastName) LIKE :keyword";
let _data = await new permission().PermissionOrgList(request, "SYS_RESULT");
const orgDna = await new permission().checkDna(request, request.user.sub)
const orgDna = await new permission().checkDna(request, request.user.sub);
let typeCondition: {
query?: string;
@ -266,9 +267,11 @@ export class KpiUserEvaluationController extends Controller {
let conditions: string[] = [];
let params: any = {};
if (_data.privilege === "CHILD" || /*_data.privilege === "PARENT" ||*/ _data.privilege === "BROTHER") {
if (
_data.privilege === "CHILD" ||
/*_data.privilege === "PARENT" ||*/ _data.privilege === "BROTHER"
) {
if (_data.privilege === "CHILD") {
if (level === 0 && orgDna.rootDnaId) {
conditions.push("kpiUserEvaluation.orgDnaId = :root");
params.root = orgDna.rootDnaId;
@ -300,8 +303,7 @@ export class KpiUserEvaluationController extends Controller {
params,
};
}
}
else if (_data.privilege === "BROTHER") {
} else if (_data.privilege === "BROTHER") {
const parentLevel = level !== null ? level - 1 : null;
if (parentLevel != null && parentLevel === 0 && orgDna.rootDnaId) {
conditions.push("kpiUserEvaluation.orgDnaId = :root");
@ -359,7 +361,11 @@ export class KpiUserEvaluationController extends Controller {
// };
// }
// }
} else if (_data.privilege === "OWNER" || _data.privilege === "ROOT" || _data.privilege === "PARENT") {
} else if (
_data.privilege === "OWNER" ||
_data.privilege === "ROOT" ||
_data.privilege === "PARENT"
) {
if (orgDna.rootDnaId) {
conditions.push("kpiUserEvaluation.orgDnaId = :root");
params.root = orgDna.rootDnaId;
@ -593,7 +599,7 @@ export class KpiUserEvaluationController extends Controller {
},
) {
let _data = await new permission().PermissionOrgList(request, "SYS_KPI_LIST");
const orgDna = await new permission().checkDna(request, request.user.sub)
const orgDna = await new permission().checkDna(request, request.user.sub);
let conditionFullName =
"CONCAT(kpiUserEvaluation.prefix, kpiUserEvaluation.firstName, ' ', kpiUserEvaluation.lastName) LIKE :keyword";
@ -606,9 +612,11 @@ export class KpiUserEvaluationController extends Controller {
let nodeId = resolveNodeId(orgDna);
let conditions: string[] = [];
let params: any = {};
if (_data.privilege === "CHILD" || /*_data.privilege === "PARENT" ||*/ _data.privilege === "BROTHER") {
if (
_data.privilege === "CHILD" ||
/*_data.privilege === "PARENT" ||*/ _data.privilege === "BROTHER"
) {
if (_data.privilege === "CHILD") {
if (level === 0 && orgDna.rootDnaId) {
conditions.push("kpiUserEvaluation.orgDnaId = :root");
params.root = orgDna.rootDnaId;
@ -640,8 +648,7 @@ export class KpiUserEvaluationController extends Controller {
params,
};
}
}
else if (_data.privilege === "BROTHER") {
} else if (_data.privilege === "BROTHER") {
const parentLevel = level !== null ? level - 1 : null;
if (parentLevel != null && parentLevel === 0 && orgDna.rootDnaId) {
conditions.push("kpiUserEvaluation.orgDnaId = :root");
@ -827,7 +834,7 @@ export class KpiUserEvaluationController extends Controller {
keyword: `%${requestBody.keyword}%`,
});
}),
)
);
if (typeCondition.query) {
query.andWhere(typeCondition.query, typeCondition.params);
@ -906,9 +913,9 @@ export class KpiUserEvaluationController extends Controller {
@Request() request: RequestWithUser,
) {
if (
requestBody.evaluatorId != null && requestBody.evaluatorId == requestBody.commanderId ||
requestBody.evaluatorId != null && requestBody.evaluatorId == requestBody.commanderHighId ||
requestBody.commanderId != null && requestBody.commanderId == requestBody.commanderHighId
(requestBody.evaluatorId != null && requestBody.evaluatorId == requestBody.commanderId) ||
(requestBody.evaluatorId != null && requestBody.evaluatorId == requestBody.commanderHighId) ||
(requestBody.commanderId != null && requestBody.commanderId == requestBody.commanderHighId)
) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
@ -1381,8 +1388,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(() => { })
.catch(() => { });
.then(() => {})
.catch(() => {});
}
const before = structuredClone(kpiUserEvaluation);
kpiUserEvaluation.evaluationReqEdit = requestBody.status.trim().toUpperCase();
@ -1464,8 +1471,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(() => { })
.catch(() => { });
.then(() => {})
.catch(() => {});
let _null: any = null;
kpiUserEvaluation.reasonReject = _null;
kpiUserEvaluation.actorReject = _null;
@ -1486,8 +1493,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(() => { })
.catch(() => { });
.then(() => {})
.catch(() => {});
}
const before = structuredClone(kpiUserEvaluation);
let _null: any = null;
@ -1540,7 +1547,7 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(async () => { })
.then(async () => {})
.catch((error) => {
console.error("Error details:", error.response.data);
});
@ -1610,8 +1617,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(() => { })
.catch(() => { });
.then(() => {})
.catch(() => {});
const before = structuredClone(kpiUserEvaluation);
let _null: any = null;
kpiUserEvaluation.evaluationStatus = "EVALUATING_EVALUATOR";
@ -1880,8 +1887,7 @@ export class KpiUserEvaluationController extends Controller {
* @param {string} id Guid, *Id (USER)
*/
@Delete("{id}")
async deleteKpiUserEvaluation(@Path() id: string, @Request() request: RequestWithUser
) {
async deleteKpiUserEvaluation(@Path() id: string, @Request() request: RequestWithUser) {
const queryRunner = AppDataSource.createQueryRunner();
await queryRunner.connect();
await queryRunner.startTransaction();
@ -1894,10 +1900,11 @@ export class KpiUserEvaluationController extends Controller {
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลการประเมินผลการปฏิบัติราชการระดับบุคคลนี้"
"ไม่พบข้อมูลการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
);
}
await queryRunner.manager.delete(KpiUserCapacity, { kpiUserEvaluationId: id });
await queryRunner.manager.delete(KpiUserEvaluationReasonPlan, { kpiUserEvaluationId: id });
await queryRunner.manager.delete(KpiUserPlanned, { kpiUserEvaluationId: id });
await queryRunner.manager.delete(KpiUserRole, { kpiUserEvaluationId: id });
await queryRunner.manager.delete(KpiUserSpecial, { kpiUserEvaluationId: id });
@ -1982,8 +1989,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(() => { })
.catch(() => { });
.then(() => {})
.catch(() => {});
item.evaluationStatus = "NEW_COMMANDER";
}
}
@ -2007,8 +2014,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(() => { })
.catch(() => { });
.then(() => {})
.catch(() => {});
item.evaluationStatus = "NEW_COMMANDER_HIGH";
}
}
@ -2032,8 +2039,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(() => { })
.catch(() => { });
.then(() => {})
.catch(() => {});
item.evaluationStatus = "APPROVE";
}
}
@ -2127,8 +2134,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(() => { })
.catch(() => { });
.then(() => {})
.catch(() => {});
}
}
} else if (role == "COMMANDER") {
@ -2153,8 +2160,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(() => { })
.catch(() => { });
.then(() => {})
.catch(() => {});
}
}
} else {
@ -2175,8 +2182,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(() => { })
.catch(() => { });
.then(() => {})
.catch(() => {});
}
} else {
item.evaluationReqEdit = requestBody.status.trim().toUpperCase();
@ -2411,8 +2418,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(() => { })
.catch(() => { });
.then(() => {})
.catch(() => {});
kpiUserEvaluation.evaluationStatus = "COMPLETE";
} else {
await new CallAPI()
@ -2430,8 +2437,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(() => { })
.catch(() => { });
.then(() => {})
.catch(() => {});
kpiUserEvaluation.evaluationStatus = "SUMMARY_COMMANDER";
}
const before = structuredClone(kpiUserEvaluation);
@ -2493,8 +2500,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(() => { })
.catch(() => { });
.then(() => {})
.catch(() => {});
kpiUserEvaluation.evaluationStatus = "COMPLETE";
} else {
await new CallAPI()
@ -2512,8 +2519,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(() => { })
.catch(() => { });
.then(() => {})
.catch(() => {});
kpiUserEvaluation.evaluationStatus = "SUMMARY_COMMANDER_HIGH";
}
const before = structuredClone(kpiUserEvaluation);
@ -2572,8 +2579,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(() => { })
.catch(() => { });
.then(() => {})
.catch(() => {});
kpiUserEvaluation.evaluationStatus = "COMPLETE";
} else {
await new CallAPI()
@ -2591,8 +2598,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(() => { })
.catch(() => { });
.then(() => {})
.catch(() => {});
kpiUserEvaluation.evaluationStatus = "COMPLETE";
}
const before = structuredClone(kpiUserEvaluation);
@ -2648,7 +2655,7 @@ export class KpiUserEvaluationController extends Controller {
pointSum: kpiUserEvaluation.summaryPoint,
profileId: kpiUserEvaluation.profileId,
})
.then(async () => { })
.then(async () => {})
.catch((error) => {
console.error("Error details:", error.response.data);
});
@ -2675,7 +2682,7 @@ export class KpiUserEvaluationController extends Controller {
kpiUserDevelopment.point != null ? kpiUserDevelopment.point.toString() : null,
developmentProjects: kpiUserDevelopment.developmentProjects.map((x) => x.name),
})
.then(async () => { })
.then(async () => {})
.catch((error) => {
console.error("Error details:", error.response.data);
});
@ -2691,7 +2698,7 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then(async () => { })
.then(async () => {})
.catch((error) => {
console.error("Error details:", error.response.data);
});