summaryrefslogtreecommitdiff
path: root/lib/Travelynx/Controller
diff options
context:
space:
mode:
authorBirte Kristina Friesel <derf@finalrewind.org>2023-08-19 10:06:15 +0200
committerBirte Kristina Friesel <derf@finalrewind.org>2023-08-19 10:06:15 +0200
commit85022709d75940a3f84cdbe462f9b261b38fc69e (patch)
tree9ffaba60336977c75ef5a63d9ddd07132f76c58b /lib/Travelynx/Controller
parent8745513fe90f65e456f74aa66bbbbcb53078b79b (diff)
API: fix checkin with toStation and checkout endpoints
Broken by 38ad42b42cbf6da6254a2498a2fc553507cb3f18
Diffstat (limited to 'lib/Travelynx/Controller')
-rwxr-xr-xlib/Travelynx/Controller/Api.pm63
1 files changed, 39 insertions, 24 deletions
diff --git a/lib/Travelynx/Controller/Api.pm b/lib/Travelynx/Controller/Api.pm
index d0ebc1b..8ff98de 100755
--- a/lib/Travelynx/Controller/Api.pm
+++ b/lib/Travelynx/Controller/Api.pm
@@ -280,15 +280,20 @@ 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,
);
- if ($error) {
- return Mojo::Promise->reject($error);
- }
+ }
+ return Mojo::Promise->resolve;
+ }
+ )->then(
+ sub {
+ my ( undef, $error ) = @_;
+ if ($error) {
+ return Mojo::Promise->reject($error);
}
$self->render(
json => {
@@ -334,33 +339,43 @@ 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,
- );
- if ($error) {
- $self->render(
- json => {
- success => \0,
- deprecated => \0,
- error => 'Checkout error: ' . $error,
- status => $self->get_user_status_json_v1( uid => $uid )
- }
- );
- }
- else {
- $self->render(
- json => {
- success => \1,
- deprecated => \0,
- status => $self->get_user_status_json_v1( uid => $uid )
+ )->then(
+ sub {
+ my ( $train, $error ) = @_;
+ if ($error) {
+ return Mojo::Promise->reject($error);
}
- );
- }
+ $self->render(
+ json => {
+ success => \1,
+ deprecated => \0,
+ 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 );