Fix Delete Error FK #2332
This commit is contained in:
parent
2231ce6b7c
commit
1ccde3f38d
1 changed files with 37 additions and 11 deletions
|
|
@ -40,6 +40,11 @@ import permission from "../interfaces/permission";
|
||||||
import { resolveNodeId, resolveNodeLevel, setLogDataDiff } from "../interfaces/utils";
|
import { resolveNodeId, resolveNodeLevel, setLogDataDiff } from "../interfaces/utils";
|
||||||
import { KpiUserRejectAgreement } from "../entities/kpiUserRejectAgreement";
|
import { KpiUserRejectAgreement } from "../entities/kpiUserRejectAgreement";
|
||||||
import { KpiUserRejectResult } from "../entities/kpiUserRejectResult";
|
import { KpiUserRejectResult } from "../entities/kpiUserRejectResult";
|
||||||
|
import { KpiUserCapacity } from "../entities/kpiUserCapacity";
|
||||||
|
import { KpiUserPlanned } from "../entities/kpiUserPlanned"
|
||||||
|
import { KpiUserRole } from "../entities/kpiUserRole";
|
||||||
|
import { KpiUserSpecial } from "../entities/kpiUserSpecial";
|
||||||
|
import { KpiUserDevelopment } from "../entities/kpiUserDevelopment";
|
||||||
|
|
||||||
@Route("api/v1/kpi/user/evaluation")
|
@Route("api/v1/kpi/user/evaluation")
|
||||||
@Tags("kpiUserEvaluation")
|
@Tags("kpiUserEvaluation")
|
||||||
|
|
@ -1875,18 +1880,39 @@ export class KpiUserEvaluationController extends Controller {
|
||||||
* @param {string} id Guid, *Id รายการประเมินผลการปฏิบัติราชการระดับบุคคล (USER)
|
* @param {string} id Guid, *Id รายการประเมินผลการปฏิบัติราชการระดับบุคคล (USER)
|
||||||
*/
|
*/
|
||||||
@Delete("{id}")
|
@Delete("{id}")
|
||||||
async deleteKpiUserEvaluation(@Path() id: string, @Request() request: RequestWithUser) {
|
async deleteKpiUserEvaluation(@Path() id: string, @Request() request: RequestWithUser
|
||||||
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
|
) {
|
||||||
where: { id: id },
|
const queryRunner = AppDataSource.createQueryRunner();
|
||||||
});
|
await queryRunner.connect();
|
||||||
if (!kpiUserEvaluation) {
|
await queryRunner.startTransaction();
|
||||||
throw new HttpError(
|
|
||||||
HttpStatusCode.NOT_FOUND,
|
try {
|
||||||
"ไม่พบข้อมูลการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
const kpiUserEvaluation = await queryRunner.manager.findOne(KpiUserEvaluation, {
|
||||||
);
|
where: { id },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!kpiUserEvaluation) {
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.NOT_FOUND,
|
||||||
|
"ไม่พบข้อมูลการประเมินผลการปฏิบัติราชการระดับบุคคลนี้"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
await queryRunner.manager.delete(KpiUserCapacity, { 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(KpiUserRejectAgreement, { kpiUserEvaluationId: id });
|
||||||
|
await queryRunner.manager.delete(KpiUserRejectResult, { kpiUserEvaluationId: id });
|
||||||
|
await queryRunner.manager.delete(KpiUserEvaluation, { id });
|
||||||
|
await queryRunner.commitTransaction();
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error) {
|
||||||
|
await queryRunner.rollbackTransaction();
|
||||||
|
throw error;
|
||||||
|
} finally {
|
||||||
|
await queryRunner.release();
|
||||||
}
|
}
|
||||||
await this.kpiUserEvalutionRepository.remove(kpiUserEvaluation, { data: request });
|
|
||||||
return new HttpSuccess();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue