Skip to content

Commit ab9b82b

Browse files
committed
Blocking delete of funding request if it has disbursements
1 parent 6a601d7 commit ab9b82b

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/api/routes/admin/application-router.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -905,13 +905,20 @@ applicationRouter.delete(
905905
return res.status(404).send({ messages: [{ variant: "error", text: "The record does not exits" }] });
906906
}
907907

908-
await db("sfa.disbursement").where({ funding_request_id: id }).del();
909-
await db("sfa.assessment").where({ funding_request_id: id }).del();
910-
const deleteRecord: any = await db("sfa.funding_request").where({ id: id }).del();
908+
const disbursements = await db("sfa.disbursement").where({ funding_request_id: id })
911909

912-
return deleteRecord > 0
913-
? res.status(202).send({ messages: [{ variant: "success", text: "Removed" }] })
914-
: res.status(404).send({ messages: [{ variant: "error", text: "Record does not exits" }] });
910+
if (disbursements.length > 0) {
911+
return res.status(400).json({
912+
messages: [{ variant: "error", text: "This funding request has disbursements and cannot be deleted" }],
913+
});
914+
}
915+
916+
await db.transaction(async (trx) => {
917+
//await trx("sfa.disbursement").where({ funding_request_id: id }).delete();
918+
await trx("sfa.assessment").where({ funding_request_id: id }).delete();
919+
await trx("sfa.funding_request").where({ id }).delete();
920+
return res.status(202).send({ messages: [{ variant: "success", text: "Removed" }] });
921+
});
915922
} catch (error: any) {
916923
console.log(error);
917924

src/web/src/components/application/sfa-funding-requests/student-training-allowance/StudentTrainingAllowance.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ export default {
303303
this.$emit("showError", message.text);
304304
}
305305
} catch (error) {
306-
this.$emit("showError", "Error to delete");
306+
this.$emit("showError", error.response?.data?.messages[0]?.text || "Error deleting funding request");
307307
} finally {
308308
store.dispatch("loadApplication", this.application.id);
309309
}

0 commit comments

Comments
 (0)