Skip to main content
The favorites system allows authenticated users to save their commonly traveled routes for quick access, eliminating the need to repeatedly enter origin and destination details.

Overview

Favorites are saved routes with:
  • Custom labels (e.g., “Home to Campus”, “Morning Commute”)
  • Origin and destination nodes
  • Optional default departure time
  • Per-user storage with a limit of 10 favorites
Authentication is required to use the favorites feature. See the Authentication guide for details on obtaining an auth token.

Getting Your Favorites

Retrieve all saved favorites for the authenticated user:

Creating a Favorite

Save a new favorite route:
1

Authenticate your request

Include your auth token in the Authorization header:
2

Provide route details

Send a POST request with the route information:
The defaultTime field is optional. If omitted, it defaults to “08:00”.
3

Handle the response

On success, you’ll receive the created favorite:

Required Fields

Updating a Favorite

Modify the label or default time of an existing favorite:
You can update either the label, defaultTime, or both. The from and to fields cannot be changed - create a new favorite instead.

Deleting a Favorite

Remove a favorite route:
Successful deletion returns:

Using Favorites for Quick Route Planning

Once you have favorites saved, you can use them to quickly plan routes:
1

Fetch your favorites

2

Select a favorite

3

Plan the route

Error Handling

Duplicate Favorites

If you try to save a route that’s already in your favorites:
HTTP Status: 409 Conflict

Limit Reached

Each user can save a maximum of 10 favorites:
HTTP Status: 400 Bad Request
Before creating a new favorite, check if you’re at the limit and prompt the user to delete old favorites if needed.

Invalid Node IDs

If the from or to node doesn’t exist:
HTTP Status: 400 Bad Request

Unauthorized Access

Attempting to access favorites without authentication:
HTTP Status: 401 Unauthorized

Favorite Not Found

Trying to update or delete a favorite that doesn’t exist or doesn’t belong to you:
HTTP Status: 404 Not Found

Best Practices

Use descriptive labels that make sense at a glance:Good labels:
  • “Home to Campus (Morning)”
  • “Campus to Library”
  • “Weekend Market Trip”
Poor labels:
  • “Route 1”
  • “TILAGOR to CAMPUS”
  • “A”
Choose default times based on your regular schedule:
  • Morning commute: Set to your typical departure time (e.g., “08:00”)
  • Return trips: Use your usual class end time (e.g., “17:00”)
  • Flexible routes: Use “08:00” as a neutral default
Users can always override the default time when planning a route.
  • Delete seasonal favorites (e.g., routes used only during exam week)
  • Combine similar routes with generic labels
  • Keep only your most frequent trips
  • Regularly review and remove unused favorites

Favorites Data Storage

Favorites are stored in the favorites.json file on the server:
Each favorite is linked to a userId ensuring users can only see and modify their own favorites.

Implementation Reference

The favorites feature is implemented in src/api/favoritesController.ts:
  • GET /api/favorites - Returns all favorites for the authenticated user (line 58)
  • POST /api/favorites - Creates a new favorite with validation and deduplication (line 97)
  • PUT /api/favorites/:id - Updates label or defaultTime for a favorite (line 250)
  • DELETE /api/favorites/:id - Removes a favorite from the user’s list (line 189)