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:
Maurice
2026-10-07 16:11:41 +02:00
parent bfa512589c
commit e0aedbb2c6
6 changed files with 65 additions and 29 deletions
+2 -7
View File
@@ -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);
}