API: fix checkin with toStation and checkout endpoints

Broken by 38ad42b42c
This commit is contained in:
Birte Kristina Friesel 2023-08-19 10:06:15 +02:00
parent 8745513fe9
commit 85022709d7
No known key found for this signature in database
GPG key ID: 19E6E524EBB177BA

View file

@ -280,16 +280,21 @@ sub travel_v1 {
# the user may not have provided the correct to_station, so
# request related stations for checkout.
my ( $train2, $error ) = $self->checkout(
return $self->checkout_p(
station => $to_station,
force => 0,
uid => $uid,
with_related => 1,
);
}
return Mojo::Promise->resolve;
}
)->then(
sub {
my ( undef, $error ) = @_;
if ($error) {
return Mojo::Promise->reject($error);
}
}
$self->render(
json => {
success => \1,
@ -334,25 +339,21 @@ sub travel_v1 {
);
}
$self->render_later;
# the user may not have provided the correct to_station, so
# request related stations for checkout.
my ( $train, $error ) = $self->checkout(
$self->checkout_p(
station => $to_station,
force => $payload->{force} ? 1 : 0,
uid => $uid,
with_related => 1,
);
)->then(
sub {
my ( $train, $error ) = @_;
if ($error) {
$self->render(
json => {
success => \0,
deprecated => \0,
error => 'Checkout error: ' . $error,
status => $self->get_user_status_json_v1( uid => $uid )
return Mojo::Promise->reject($error);
}
);
}
else {
$self->render(
json => {
success => \1,
@ -360,7 +361,21 @@ sub travel_v1 {
status => $self->get_user_status_json_v1( uid => $uid )
}
);
return;
}
)->catch(
sub {
my ($err) = @_;
$self->render(
json => {
success => \0,
deprecated => \0,
error => 'Checkout error: ' . $err,
status => $self->get_user_status_json_v1( uid => $uid )
}
);
}
)->wait;
}
elsif ( $payload->{action} eq 'undo' ) {
my $error = $self->undo( 'in_transit', $uid );