Unverified Commit 85022709 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

API: fix checkin with toStation and checkout endpoints

Broken by 38ad42b4
parent 8745513f
Loading
Loading
Loading
Loading
+39 −24
Original line number Diff line number Diff line
@@ -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,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,
		);
		)->then(
			sub {
				my ( $train, $error ) = @_;
				if ($error) {
					return Mojo::Promise->reject($error);
				}
				$self->render(
					json => {
					success    => \0,
						success    => \1,
						deprecated => \0,
					error      => 'Checkout error: ' . $error,
						status => $self->get_user_status_json_v1( uid => $uid )
					}
				);
				return;
			}
		else {
		)->catch(
			sub {
				my ($err) = @_;
				$self->render(
					json => {
					success    => \1,
						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 );