Merge branch 'develop' into dev
All checks were successful
Build & Deploy on Dev / build (push) Successful in 57s
All checks were successful
Build & Deploy on Dev / build (push) Successful in 57s
* develop: fix: delete kpi
This commit is contained in:
commit
537d3f56da
1 changed files with 79 additions and 2 deletions
|
|
@ -46,6 +46,10 @@ import { KpiUserRole } from "../entities/kpiUserRole";
|
|||
import { KpiUserSpecial } from "../entities/kpiUserSpecial";
|
||||
import { KpiUserDevelopment } from "../entities/kpiUserDevelopment";
|
||||
import { KpiUserEvaluationReasonPlan } from "../entities/kpiUserEvaluationReasonPlan";
|
||||
import { KpiUserEvaluationReasonCapacity } from "../entities/kpiUserEvaluationReasonCapacity";
|
||||
import { KpiUserEvaluationReasonRole } from "../entities/kpiUserEvaluationReasonRole";
|
||||
import { KpiUserEvaluationReasonSpecial } from "../entities/kpiUserEvaluationReasonSpecial";
|
||||
import { KpiUserEvaluationReasonDevelopment } from "../entities/kpiUserEvaluationReasonDevelopment";
|
||||
|
||||
@Route("api/v1/kpi/user/evaluation")
|
||||
@Tags("kpiUserEvaluation")
|
||||
|
|
@ -1903,15 +1907,88 @@ export class KpiUserEvaluationController extends Controller {
|
|||
"ไม่พบข้อมูลการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
||||
);
|
||||
}
|
||||
|
||||
// Phase 1: Delete grandchild entities (reason entities)
|
||||
// These must be deleted before their parent records
|
||||
|
||||
// First, get all child entity IDs for this evaluation
|
||||
const [kpiUserCapacities, kpiUserRoles, kpiUserSpecials, kpiUserDevelopments, kpiUserPlanneds] =
|
||||
await Promise.all([
|
||||
queryRunner.manager.find(KpiUserCapacity, {
|
||||
where: { kpiUserEvaluationId: id },
|
||||
select: ["id"],
|
||||
}),
|
||||
queryRunner.manager.find(KpiUserRole, {
|
||||
where: { kpiUserEvaluationId: id },
|
||||
select: ["id"],
|
||||
}),
|
||||
queryRunner.manager.find(KpiUserSpecial, {
|
||||
where: { kpiUserEvaluationId: id },
|
||||
select: ["id"],
|
||||
}),
|
||||
queryRunner.manager.find(KpiUserDevelopment, {
|
||||
where: { kpiUserEvaluationId: id },
|
||||
select: ["id"],
|
||||
}),
|
||||
queryRunner.manager.find(KpiUserPlanned, {
|
||||
where: { kpiUserEvaluationId: id },
|
||||
select: ["id"],
|
||||
}),
|
||||
]);
|
||||
|
||||
const capacityIds = kpiUserCapacities.map((c) => c.id);
|
||||
const roleIds = kpiUserRoles.map((r) => r.id);
|
||||
const specialIds = kpiUserSpecials.map((s) => s.id);
|
||||
const developmentIds = kpiUserDevelopments.map((d) => d.id);
|
||||
const plannedIds = kpiUserPlanneds.map((p) => p.id);
|
||||
|
||||
// 1. KpiUserEvaluationReasonCapacity (via kpiUserCapacityId)
|
||||
if (capacityIds.length > 0) {
|
||||
await queryRunner.manager.delete(KpiUserEvaluationReasonCapacity, {
|
||||
kpiUserCapacityId: In(capacityIds),
|
||||
});
|
||||
}
|
||||
|
||||
// 2. KpiUserEvaluationReasonRole (via kpiUserRoleId)
|
||||
if (roleIds.length > 0) {
|
||||
await queryRunner.manager.delete(KpiUserEvaluationReasonRole, {
|
||||
kpiUserRoleId: In(roleIds),
|
||||
});
|
||||
}
|
||||
|
||||
// 3. KpiUserEvaluationReasonSpecial (via kpiUserSpecialId)
|
||||
if (specialIds.length > 0) {
|
||||
await queryRunner.manager.delete(KpiUserEvaluationReasonSpecial, {
|
||||
kpiUserSpecialId: In(specialIds),
|
||||
});
|
||||
}
|
||||
|
||||
// 4. KpiUserEvaluationReasonDevelopment (via kpiUserDevelopmentId)
|
||||
if (developmentIds.length > 0) {
|
||||
await queryRunner.manager.delete(KpiUserEvaluationReasonDevelopment, {
|
||||
kpiUserDevelopmentId: In(developmentIds),
|
||||
});
|
||||
}
|
||||
|
||||
// 5. KpiUserEvaluationReasonPlan (via kpiUserPlannedId)
|
||||
if (plannedIds.length > 0) {
|
||||
await queryRunner.manager.delete(KpiUserEvaluationReasonPlan, {
|
||||
kpiUserPlannedId: In(plannedIds),
|
||||
});
|
||||
}
|
||||
|
||||
// Phase 2: Delete child entities
|
||||
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 });
|
||||
await queryRunner.manager.delete(KpiUserDevelopment, { kpiUserEvaluationId: id });
|
||||
await queryRunner.manager.delete(KpiUserPlanned, { kpiUserEvaluationId: id });
|
||||
await queryRunner.manager.delete(KpiUserRejectAgreement, { kpiUserEvaluationId: id });
|
||||
await queryRunner.manager.delete(KpiUserRejectResult, { kpiUserEvaluationId: id });
|
||||
|
||||
// Phase 3: Delete parent entity
|
||||
await queryRunner.manager.delete(KpiUserEvaluation, { id });
|
||||
|
||||
await queryRunner.commitTransaction();
|
||||
return new HttpSuccess();
|
||||
} catch (error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue