mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 18:34:09 +00:00
fix(trips): count trip dates in calendar days, the same on REST and MCP
Filling in a missing end date and keeping a trip's length when its start moved both shifted a local-time Date, so a trip crossing a DST change lost or gained a day. Both now use addIsoDays. The one-date-makes-a-week default moves from the REST controller into TripsService.create, so the MCP create_trip tool no longer stores a half-dated trip, and the trip and its days are written in one transaction.
This commit is contained in:
@@ -50,9 +50,6 @@ export const TRIP_COVER_FILE_FILTER: Options['fileFilter'] = (_req, file, cb) =>
|
||||
else cb(new Error('Only jpg, png, gif, webp images allowed'));
|
||||
};
|
||||
|
||||
const toDateStr = (d: Date) => d.toISOString().slice(0, 10);
|
||||
const addDays = (d: Date, n: number) => { const r = new Date(d); r.setDate(r.getDate() + n); return r; };
|
||||
|
||||
/**
|
||||
* /api/trips — the trip aggregate root.
|
||||
*
|
||||
@@ -115,10 +112,8 @@ export class TripsController {
|
||||
}
|
||||
// Presence/shape validation happens in the ZodValidationPipe (tripCreateRequestSchema).
|
||||
const { title, description, currency, reminder_days, day_count } = body;
|
||||
let start_date: string | null = body.start_date || null;
|
||||
let end_date: string | null = body.end_date || null;
|
||||
if (start_date && !end_date) end_date = toDateStr(addDays(new Date(start_date), 6));
|
||||
else if (!start_date && end_date) start_date = toDateStr(addDays(new Date(end_date), -6));
|
||||
const start_date: string | null = body.start_date || null;
|
||||
const end_date: string | null = body.end_date || null;
|
||||
if (start_date && end_date && new Date(end_date) < new Date(start_date)) {
|
||||
throw new HttpException({ error: 'End date must be after start date' }, 400);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user