From 93c0d6fe785a832136553277728b173e43af9523 Mon Sep 17 00:00:00 2001 From: jubnl Date: Fri, 3 Apr 2026 23:58:15 +0200 Subject: [PATCH] fix(trips): default to 7-day window when dates are omitted on creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - No dates → tomorrow to tomorrow+7d - Start only → end = start+7d - End only → start = end-7d - Both provided → unchanged fix(ci): include client/package-lock.json in version bump commit --- .github/workflows/docker.yml | 2 +- server/src/routes/trips.ts | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 27bab6f..326db6c 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 b35fb1a..c0f8267 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 });