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. 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 =item * organisation_id
An ID of a valid organisation. used when transaction_type is 1 or 2. 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 }, 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 }, 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 => { file => {
required => { message => 'No file uploaded', status => 400 }, required => { message => 'No file uploaded', status => 400 },
upload => { message => 'file key does not contain a file', 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_value')->number->gt_num(0);
$validation->required('transaction_type')->in( 1, 2, 3 ); $validation->required('transaction_type')->in( 1, 2, 3 );
#Check a purchase time was submitted
$validation->required('purchase_time');
# 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;
@ -138,6 +148,7 @@ sub post_upload {
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 = $validation->param('purchase_time');
my $file = $c->store_file_from_upload( $upload ); my $file = $c->store_file_from_upload( $upload );
$organisation->create_related( $organisation->create_related(
@ -146,6 +157,7 @@ sub post_upload {
buyer => $user, buyer => $user,
value => $transaction_value, value => $transaction_value,
proof_image => $file, proof_image => $file,
purchase_time => $purchase_time,
} }
); );

View file

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