Updated to allow for user updates to change location by postcode
This commit is contained in:
parent
202deb9178
commit
37e8f0b46a
6 changed files with 105 additions and 26 deletions
|
@ -82,34 +82,11 @@ sub post_register {
|
|||
|
||||
return $c->api_validation_error if $validation->has_error;
|
||||
|
||||
my $postcode_obj = Geo::UK::Postcode::Regex->parse(
|
||||
$validation->param('postcode')
|
||||
my $location = $c->get_location_from_postcode(
|
||||
$validation->param('postcode'),
|
||||
$usertype,
|
||||
);
|
||||
|
||||
my $location;
|
||||
|
||||
unless ( defined $postcode_obj && $postcode_obj->{non_geographical} ) {
|
||||
my $pc_result = $c->schema->resultset('GbPostcode')->find({
|
||||
incode => $postcode_obj->{incode},
|
||||
outcode => $postcode_obj->{outcode},
|
||||
});
|
||||
if ( defined $pc_result ) {
|
||||
# Force truncation here as SQLite is stupid
|
||||
$location = {
|
||||
latitude => (
|
||||
$usertype eq 'customer'
|
||||
? int($pc_result->latitude * 100 ) / 100
|
||||
: $pc_result->latitude
|
||||
),
|
||||
longitude => (
|
||||
$usertype eq 'customer'
|
||||
? int($pc_result->longitude * 100 ) / 100
|
||||
: $pc_result->longitude
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if ($usertype eq 'customer'){
|
||||
|
||||
$c->schema->txn_do( sub {
|
||||
|
|
|
@ -145,6 +145,11 @@ sub post_account_update {
|
|||
|
||||
return $c->api_validation_error if $validation->has_error;
|
||||
|
||||
my $location = $c->get_location_from_postcode(
|
||||
$validation->param('postcode'),
|
||||
$user->type,
|
||||
);
|
||||
|
||||
if ( $user->type eq 'customer' ){
|
||||
|
||||
$c->schema->txn_do( sub {
|
||||
|
@ -152,6 +157,7 @@ sub post_account_update {
|
|||
full_name => $validation->param('full_name'),
|
||||
display_name => $validation->param('display_name'),
|
||||
postcode => $validation->param('postcode'),
|
||||
( defined $location ? ( %$location ) : ( latitude => undef, longitude => undef ) ),
|
||||
});
|
||||
$user->update({
|
||||
email => $validation->param('email'),
|
||||
|
@ -169,6 +175,7 @@ sub post_account_update {
|
|||
town => $validation->param('town'),
|
||||
sector => $validation->param('sector'),
|
||||
postcode => $validation->param('postcode'),
|
||||
( defined $location ? ( %$location ) : ( latitude => undef, longitude => undef ) ),
|
||||
});
|
||||
$user->update({
|
||||
email => $validation->param('email'),
|
||||
|
|
Reference in a new issue