From d07610e72df61ea9756a15ecbe8140097b2712d0 Mon Sep 17 00:00:00 2001 From: Tom Bloor Date: Thu, 17 Aug 2017 15:38:08 +0100 Subject: [PATCH] Check for organisation and transaction actually being defined on upload --- lib/Pear/LocalLoop/Controller/Api/Upload.pm | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Api/Upload.pm b/lib/Pear/LocalLoop/Controller/Api/Upload.pm index 58d9bd8..45f0d52 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Upload.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Upload.pm @@ -146,13 +146,21 @@ sub post_upload { }); } + unless ( defined $organisation ) { + return $c->render( json => { + success => Mojo::JSON->false, + message => 'Error Finding Organisation', + error => 'organisation_error', + }); + } + my $transaction_value = $validation->param('transaction_value'); my $upload = $validation->param('file'); my $purchase_time = $c->parse_iso_datetime($validation->param('purchase_time') || ''); $purchase_time ||= DateTime->now(); my $file = $c->store_file_from_upload( $upload ); - $organisation->create_related( + my $new_transaction = $organisation->create_related( 'transactions', { buyer => $user, @@ -162,13 +170,20 @@ sub post_upload { } ); + unless ( defined $new_transaction ) { + return $c->render( json => { + success => Mojo::JSON->false, + message => 'Error Adding Transaction', + error => 'transaction_error', + }); + } + return $c->render( json => { success => Mojo::JSON->true, message => 'Upload Successful', }); } - # TODO Limit search results, possibly paginate them? # TODO Search by location as well sub post_search {