File tree Expand file tree Collapse file tree 2 files changed +14
-7
lines changed
web/src/components/application/sfa-funding-requests/student-training-allowance Expand file tree Collapse file tree 2 files changed +14
-7
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments