@vulog/aima-trip
v1.2.30
Published
A set of utilities for managing trips, trip-related products, and bookings in the Vulog AIMA ecosystem.
Readme
@vulog/aima-trip
A set of utilities for managing trips, trip-related products, and bookings in the Vulog AIMA ecosystem.
Installation
npm install @vulog/aima-tripRequirements
- You must have an instance of
Clientfrom@vulog/aima-client.
API
1. getTripById
Fetch a trip by its ID.
import { getTripById } from '@vulog/aima-trip';
import { Client } from '@vulog/aima-client';
const trip = await getTripById(client, tripId);
// If the trip is not found (404), returns an empty object: {}Arguments:
client: Client– The authenticated API client.tripId: string– The trip's unique identifier.
Returns:Promise<TripResponse | Record<string, never>>
A trip object, or an empty object if not found.
2. getVehiclesBooked
Get all vehicles currently booked in the fleet.
import { getVehiclesBooked } from '@vulog/aima-trip';
const vehicles = await getVehiclesBooked(client);Returns:Promise<FleetManagerBook[]>
3. getVehiclesBookedByUserId
Get all vehicles currently booked by a specific user.
import { getVehiclesBookedByUserId } from '@vulog/aima-trip';
const vehicles = await getVehiclesBookedByUserId(client, userId);Returns:Promise<FleetManagerBook[]>
Returns an empty array if the user has no bookings or is not found.
4. addTripRelatedProduct / removeTripRelatedProduct
Add or remove a product to/from a vehicle's trip.
import { addTripRelatedProduct, removeTripRelatedProduct } from '@vulog/aima-trip';
await addTripRelatedProduct(client, vehicleId, productId);
await removeTripRelatedProduct(client, vehicleId, productId);Arguments:
client: ClientvehicleId: stringproductId: string
5. endTrip
End a trip for a vehicle.
import { endTrip } from '@vulog/aima-trip';
await endTrip(client, {
vehicleId,
userId,
orderId,
});Arguments:
client: Clientinfo: EndTripInfo(object withvehicleId,userId,orderId)
Types
FleetManagerBook
Describes a booked vehicle.
See src/types.ts for the full structure.
EndTripInfo
type EndTripInfo = {
vehicleId: string;
userId: string;
orderId: string;
};TripResponse
Describes a trip as returned by getTripById.
See src/getTripById.ts for the full structure.
Error Handling
- All functions throw on validation or network errors, except:
getTripByIdreturns{}if the trip is not found (404).getVehiclesBookedByUserIdreturns[]if the user is not found (404).
