Skip to main content

Overview

The TripApiService provides HTTP methods for all trip-related operations throughout the driver’s journey, from accepting assignments to completing trips. Location: src/app/core/services/http/trip-api.service.ts

Public Methods

getById()

Retrieves detailed information about a specific trip.
tripId
string
required
The unique identifier of the trip
Returns: Observable<TripDto>
this.tripApiService.getById('trip_123456').subscribe({
  next: (trip) => {
    console.log('Trip details:', trip);
    this.displayOrigin = trip.origin.label;
    this.displayDestination = trip.destination.label;
  }
});

acceptAssignment()

Accepts a trip assignment offer before it expires.
assignmentId
string
required
The unique identifier of the trip assignment
Returns: Observable<TripDto>
this.tripApiService.acceptAssignment(assignmentId).subscribe({
  next: (trip) => {
    console.log('Assignment accepted:', trip);
    // Navigate to active trip view
    this.router.navigate(['/trips/active']);
  },
  error: (error) => {
    if (error.code === 'ASSIGNMENT_EXPIRED') {
      this.showMessage('This trip offer has expired');
    }
  }
});

declineAssignment()

Declines a trip assignment offer.
assignmentId
string
required
The unique identifier of the trip assignment
Returns: Observable<void>
this.tripApiService.declineAssignment(assignmentId).subscribe({
  next: () => {
    console.log('Assignment declined');
    // Return to home screen
  }
});

markArrivedPickup()

Marks that the driver has arrived at the pickup location.
tripId
string
required
The unique identifier of the trip
driverId
string
required
The unique identifier of the driver
Returns: Observable<TripDto> Response Fields:
arrivedPickupAt
string
ISO 8601 timestamp when driver arrived at pickup
status
string
Updated trip status (should be ‘ARRIVING’ or ‘PICKUP_ARRIVED’)
this.tripApiService.markArrivedPickup(tripId, driverId).subscribe({
  next: (trip) => {
    console.log('Marked as arrived at:', trip.arrivedPickupAt);
    // Start waiting timer
    this.startWaitingTimer(trip.arrivedPickupAt);
  }
});

startTrip()

Starts the trip after picking up the passenger.
tripId
string
required
The unique identifier of the trip
driverId
string
required
The unique identifier of the driver
Returns: Observable<TripDto> Response Fields:
startedAt
string
ISO 8601 timestamp when trip started
status
string
Updated trip status (should be ‘IN_PROGRESS’)
this.tripApiService.startTrip(tripId, driverId).subscribe({
  next: (trip) => {
    console.log('Trip started at:', trip.startedAt);
    // Navigate to in-progress trip view
  }
});

completeTrip()

Completes the trip and finalizes the fare calculation.
tripId
string
required
The unique identifier of the trip
payload
CompleteTripPayload
required
Trip completion details
Returns: Observable<TripDto> Example:
const payload: CompleteTripPayload = {
  driverId: 'driver_123',
  extraFees: 5.0,
  waitingTimeMinutes: 8,
  waitingReason: 'Passenger delayed at pickup',
  actualDistanceKm: 12.5,
  actualDurationMin: 25
};

this.tripApiService.completeTrip(tripId, payload).subscribe({
  next: (trip) => {
    console.log('Trip completed:', trip);
    console.log('Final fare:', trip.fareFinalTotal, trip.fareFinalCurrency);
    // Show completion summary
  }
});

Response Types

TripDto

Complete trip object returned by most endpoints:
interface TripDto {
  id: string;
  status: string;
  origin: TripStopDto;
  destination: TripStopDto;
  intermediateStops?: TripStopDto[];
  passenger?: {
    id: string;
    name: string;
    phoneMasked: string;
    photoUrl?: string;
  };
  driver?: {
    id: string;
    name: string;
    phoneMasked: string;
    photoUrl?: string;
  };
  driverId?: string;
  fareEstimatedTotal?: number;
  fareEstimatedCurrency?: string;
  fareFinalTotal?: number;
  fareFinalCurrency?: string;
  paymentMode: string;
  requestedAt: string;
  assignedAt?: string;
  arrivedPickupAt?: string;
  startedAt?: string;
  completedAt?: string;
  cancelledAt?: string;
}
See Trip Models for complete type definitions.

Error Handling

All trip operations may fail with specific error codes. Always handle these appropriately:
this.tripApiService.acceptAssignment(assignmentId).subscribe({
  error: (error: ApiError) => {
    switch (error.code) {
      case 'ASSIGNMENT_EXPIRED':
        this.showError('This trip offer has expired');
        break;
      case 'ASSIGNMENT_ALREADY_TAKEN':
        this.showError('Another driver accepted this trip');
        break;
      case 'DRIVER_NOT_AVAILABLE':
        this.showError('You must be online to accept trips');
        break;
      default:
        this.showError(error.message || 'Failed to accept trip');
    }
  }
});

Best Practices

Always refresh trip data after status changes to ensure UI reflects the latest state.
Waiting fees: Track waiting time from arrivedPickupAt to startedAt and apply charges according to your business rules.
Offline support: Consider queuing trip updates when offline and syncing when connection is restored.

Build docs developers (and LLMs) love