Added code for date submission in receipt upload

This commit is contained in:
Finn 2017-08-14 11:15:33 +01:00
parent e222b635a8
commit 85c80980c3
2 changed files with 19 additions and 2 deletions

View file

@ -19,6 +19,10 @@ The value of the transaction
Is a value of 1, 2, or 3 - depending on the type of transaction.
=item * purchase_time
Is a DateTime value submitted for when the receipt is from.
=item * organisation_id
An ID of a valid organisation. used when transaction_type is 1 or 2.
@ -54,6 +58,9 @@ has error_messages => sub {
number => { message => 'transaction_value does not look like a number', status => 400 },
gt_num => { message => 'transaction_value cannot be equal to or less than zero', status => 400 },
},
purchase_time => {
required => { message => 'purchase_time is missing', status => 400 },
},
file => {
required => { message => 'No file uploaded', status => 400 },
upload => { message => 'file key does not contain a file', status => 400 },
@ -92,6 +99,9 @@ sub post_upload {
$validation->required('transaction_value')->number->gt_num(0);
$validation->required('transaction_type')->in( 1, 2, 3 );
#Check a purchase time was submitted
$validation->required('purchase_time');
# First pass of required items
return $c->api_validation_error if $validation->has_error;
@ -112,7 +122,7 @@ sub post_upload {
# Unvalidated Organisation
my $valid_org_rs = $c->schema->resultset('PendingOrganisation')->search({ submitted_by_id => $user->id });
$validation->required('organisation_id')->number->in_resultset( 'id', $valid_org_rs );
return $c->api_validation_error if $validation->has_error;
$organisation = $valid_org_rs->find( $validation->param('organisation_id') );
@ -123,7 +133,7 @@ sub post_upload {
$validation->optional('street_name');
$validation->optional('town');
$validation->optional('postcode')->postcode;
return $c->api_validation_error if $validation->has_error;
$organisation = $c->schema->resultset('PendingOrganisation')->create({
@ -138,6 +148,7 @@ sub post_upload {
my $transaction_value = $validation->param('transaction_value');
my $upload = $validation->param('file');
my $purchase_time = $validation->param('purchase_time');
my $file = $c->store_file_from_upload( $upload );
$organisation->create_related(
@ -146,6 +157,7 @@ sub post_upload {
buyer => $user,
value => $transaction_value,
proof_image => $file,
purchase_time => $purchase_time,
}
);

View file

@ -42,6 +42,11 @@ __PACKAGE__->add_columns(
is_nullable => 0,
set_on_create => 1,
},
"purchase_time" => {
data_type => "datetime",
is_nullable => 0,
set_on_create => 1,
},
);
__PACKAGE__->set_primary_key("id");