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 {