feat(public-api): next_trip in /api/v1/stats counts down to the next trip

The counterpart of last_trip for a homepage widget: the nearest trip that has not started yet, with its countries and the whole days until it starts, or null when nothing is planned. A trip under way stays last_trip, so the two never name the same trip. (#2542)
This commit is contained in:
Maurice
2026-10-01 09:22:37 +02:00
parent e24da67218
commit ba3dc65926
7 changed files with 164 additions and 11 deletions
@@ -308,6 +308,19 @@ export const publicApiLastTripSchema = z.object({
});
export type PublicApiLastTrip = z.infer<typeof publicApiLastTripSchema>;
/**
* The trip the traveller goes on next, for a widget that counts down to it (#2542).
*
* "Next" means not started yet, so a trip under way is still `last_trip` and the
* two never name the same trip. A user with nothing ahead gets `null`.
*/
export const publicApiNextTripSchema = publicApiLastTripSchema.extend({
start_date: z.string(),
/** Whole days from today until the start date; 1 means it starts tomorrow. */
days_until: z.number().int().positive(),
});
export type PublicApiNextTrip = z.infer<typeof publicApiNextTripSchema>;
/**
* Aggregate counts for a dashboard widget (#1367) — Homepage's `customapi` and
* anything else that renders a handful of numbers and cannot aggregate a list
@@ -337,5 +350,6 @@ export const publicApiStatsSchema = z.object({
/** Flown distance, summed over non-cancelled flight bookings. Kilometres. */
total_distance_km: z.number(),
last_trip: publicApiLastTripSchema.nullable(),
next_trip: publicApiNextTripSchema.nullable(),
});
export type PublicApiStats = z.infer<typeof publicApiStatsSchema>;