Check for organisation and transaction actually being defined on upload
This commit is contained in:
parent
3197352ff2
commit
d07610e72d
1 changed files with 17 additions and 2 deletions
|
@ -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 $transaction_value = $validation->param('transaction_value');
|
||||||
my $upload = $validation->param('file');
|
my $upload = $validation->param('file');
|
||||||
my $purchase_time = $c->parse_iso_datetime($validation->param('purchase_time') || '');
|
my $purchase_time = $c->parse_iso_datetime($validation->param('purchase_time') || '');
|
||||||
$purchase_time ||= DateTime->now();
|
$purchase_time ||= DateTime->now();
|
||||||
my $file = $c->store_file_from_upload( $upload );
|
my $file = $c->store_file_from_upload( $upload );
|
||||||
|
|
||||||
$organisation->create_related(
|
my $new_transaction = $organisation->create_related(
|
||||||
'transactions',
|
'transactions',
|
||||||
{
|
{
|
||||||
buyer => $user,
|
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 => {
|
return $c->render( json => {
|
||||||
success => Mojo::JSON->true,
|
success => Mojo::JSON->true,
|
||||||
message => 'Upload Successful',
|
message => 'Upload Successful',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# TODO Limit search results, possibly paginate them?
|
# TODO Limit search results, possibly paginate them?
|
||||||
# TODO Search by location as well
|
# TODO Search by location as well
|
||||||
sub post_search {
|
sub post_search {
|
||||||
|
|
Reference in a new issue