Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

fix(trips): default to 7-day window when dates are omitted on creation

jubnl93c0d6fe785a
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
index 27bab6f50..326db6c11 100644
--- a/.github/workflows/docker.yml
+++ b/.github/workflows/docker.yml
@@ -58,7 +58,7 @@ jobs:
# Commit and tag
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- git add server/package.json server/package-lock.json client/package.json
+ git add server/package.json server/package-lock.json client/package.json client/package-lock.json
git commit -m "chore: bump version to $NEW_VERSION [skip ci]"
git tag "v$NEW_VERSION"
git push origin main --follow-tags
diff --git a/server/src/routes/trips.ts b/server/src/routes/trips.ts
index b35fb1a79..c0f82674a 100644
--- a/server/src/routes/trips.ts
+++ b/server/src/routes/trips.ts
@@ -74,9 +74,26 @@ router.post('/', authenticate, (req: Request, res: Response) => {
if (!checkPermission('trip_create', authReq.user.role, null, authReq.user.id, false))
return res.status(403).json({ error: 'No permission to create trips' });
- const { title, description, start_date, end_date, currency, reminder_days } = req.body;
+ const { title, description, currency, reminder_days } = req.body;
if (!title) return res.status(400).json({ error: 'Title is required' });
- if (start_date && end_date && new Date(end_date) < new Date(start_date))
+
+ 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; };
+
+ let start_date: string | null = req.body.start_date || null;
+ let end_date: string | null = req.body.end_date || null;
+
+ if (!start_date && !end_date) {
+ const tomorrow = addDays(new Date(), 1);
+ start_date = toDateStr(tomorrow);
+ end_date = toDateStr(addDays(tomorrow, 7));
+ } else if (start_date && !end_date) {
+ end_date = toDateStr(addDays(new Date(start_date), 7));
+ } else if (!start_date && end_date) {
+ start_date = toDateStr(addDays(new Date(end_date), -7));
+ }
+
+ if (new Date(end_date!) < new Date(start_date!))
return res.status(400).json({ error: 'End date must be after start date' });
const { trip, tripId, reminderDays } = createTrip(authReq.user.id, { title, description, start_date, end_date, currency, reminder_days });