From 4e9312148cd935eafe0c400c18efb2d4945cefa4 Mon Sep 17 00:00:00 2001 From: Finn Date: Mon, 15 Jan 2018 17:01:59 +0000 Subject: [PATCH] Fixed upload code --- lib/Pear/LocalLoop/Controller/Api/Upload.pm | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Pear/LocalLoop/Controller/Api/Upload.pm b/lib/Pear/LocalLoop/Controller/Api/Upload.pm index 72c9b3e..56f5ca6 100644 --- a/lib/Pear/LocalLoop/Controller/Api/Upload.pm +++ b/lib/Pear/LocalLoop/Controller/Api/Upload.pm @@ -75,6 +75,9 @@ has error_messages => sub { organisation_name => { required => { message => 'organisation name is missing', status => 400 }, }, + category => { + in_resultset => { message => 'Category is invalid', status => 400 }, + }, town => { required => { message => 'town/city is missing', status => 400 }, }, @@ -104,7 +107,7 @@ sub post_upload { #Check a proper purchase time was submitted $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 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') || ''); $purchase_time ||= DateTime->now(); 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 $new_transaction = $organisation->entity->create_related(