Fixed upload code

This commit is contained in:
Finn 2018-01-15 17:01:59 +00:00
parent 175026e37e
commit c4f68332b9

View file

@ -75,6 +75,9 @@ has error_messages => sub {
organisation_name => { organisation_name => {
required => { message => 'organisation name is missing', status => 400 }, required => { message => 'organisation name is missing', status => 400 },
}, },
category => {
in_resultset => { message => 'Category is invalid', status => 400 },
},
town => { town => {
required => { message => 'town/city is missing', status => 400 }, required => { message => 'town/city is missing', status => 400 },
}, },
@ -104,7 +107,7 @@ sub post_upload {
#Check a proper purchase time was submitted #Check a proper purchase time was submitted
$validation->optional('purchase_time')->is_full_iso_datetime; $validation->optional('purchase_time')->is_full_iso_datetime;
$validation->optional('category'); $validation->optional('category')->in_resultset( 'id', $c->schema->resultset('Category'));
# First pass of required items # First pass of required items
return $c->api_validation_error if $validation->has_error; return $c->api_validation_error if $validation->has_error;
@ -180,7 +183,7 @@ sub post_upload {
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 = defined $upload ? $c->store_file_from_upload( $upload ) : undef; my $file = defined $upload ? $c->store_file_from_upload( $upload ) : undef;
my $category = defined $validation->param('category') ? $validation->param('category') : undef; my $category = $validation->param('category');
my $distance = $c->get_distance_from_coords( $user->entity->type_object, $organisation ); my $distance = $c->get_distance_from_coords( $user->entity->type_object, $organisation );
my $new_transaction = $organisation->entity->create_related( my $new_transaction = $organisation->entity->create_related(