BREAKING: Reservations have been completely rebuilt. Existing place-level reservations are no longer used. All reservations must be re-created via the Bookings tab. Your trips, places, and other data are unaffected. Reservation System (rebuilt from scratch): - Reservations now link to specific day assignments instead of places - Same place on different days can have independent reservations - New assignment picker in booking modal (grouped by day, searchable) - Removed day/place dropdowns from booking form - Reservation badges in day plan sidebar with type-specific icons - Reservation details in place inspector (only for selected assignment) - Reservation summary in day detail panel Day Detail Panel (new): - Opens on day click in the sidebar - Detailed weather: hourly forecast, precipitation, wind, sunrise/sunset - Historical climate averages for dates beyond 16 days - Accommodation management with check-in/check-out, confirmation number - Hotel assignment across multiple days with day range picker - Reservation overview for the day Places: - Places can now be assigned to the same day multiple times - Start time + end time fields (replaces single time field) - Map badges show multiple position numbers (e.g. "1 · 4") - Route optimization fixed for duplicate places - File attachments during place editing (not just creation) - Cover image upload during trip creation (not just editing) - Paste support (Ctrl+V) for images in trip, place, and file forms Internationalization: - 200+ hardcoded German strings translated to i18n (EN + DE) - Server error messages in English - Category seeds in English for new installations - All planner, register, photo, packing components translated UI/UX: - Auto dark mode (follows system preference, configurable in settings) - Navbar toggle switches light/dark (overrides auto) - Sidebar minimize buttons z-index fixed - Transport mode selector removed from day plan - CustomSelect supports grouped headers (isHeader option) - Optimistic updates for day notes (instant feedback) - Booking cards redesigned with type-colored headers and structured details Weather: - Wind speed in mph when using Fahrenheit setting - Weather description language matches app language Admin: - Weather info panel replaces OpenWeatherMap key input - "Recommended" badge styling updated
113 lines
3.9 KiB
JavaScript
113 lines
3.9 KiB
JavaScript
const express = require('express');
|
|
const { db, canAccessTrip } = require('../db/database');
|
|
const { authenticate } = require('../middleware/auth');
|
|
const { broadcast } = require('../websocket');
|
|
|
|
const router = express.Router({ mergeParams: true });
|
|
|
|
function verifyTripOwnership(tripId, userId) {
|
|
return canAccessTrip(tripId, userId);
|
|
}
|
|
|
|
// GET /api/trips/:tripId/packing
|
|
router.get('/', authenticate, (req, res) => {
|
|
const { tripId } = req.params;
|
|
|
|
const trip = verifyTripOwnership(tripId, req.user.id);
|
|
if (!trip) return res.status(404).json({ error: 'Trip not found' });
|
|
|
|
const items = db.prepare(
|
|
'SELECT * FROM packing_items WHERE trip_id = ? ORDER BY sort_order ASC, created_at ASC'
|
|
).all(tripId);
|
|
|
|
res.json({ items });
|
|
});
|
|
|
|
// POST /api/trips/:tripId/packing
|
|
router.post('/', authenticate, (req, res) => {
|
|
const { tripId } = req.params;
|
|
const { name, category, checked } = req.body;
|
|
|
|
const trip = verifyTripOwnership(tripId, req.user.id);
|
|
if (!trip) return res.status(404).json({ error: 'Trip not found' });
|
|
|
|
if (!name) return res.status(400).json({ error: 'Item name is required' });
|
|
|
|
const maxOrder = db.prepare('SELECT MAX(sort_order) as max FROM packing_items WHERE trip_id = ?').get(tripId);
|
|
const sortOrder = (maxOrder.max !== null ? maxOrder.max : -1) + 1;
|
|
|
|
const result = db.prepare(
|
|
'INSERT INTO packing_items (trip_id, name, checked, category, sort_order) VALUES (?, ?, ?, ?, ?)'
|
|
).run(tripId, name, checked ? 1 : 0, category || 'Allgemein', sortOrder);
|
|
|
|
const item = db.prepare('SELECT * FROM packing_items WHERE id = ?').get(result.lastInsertRowid);
|
|
res.status(201).json({ item });
|
|
broadcast(tripId, 'packing:created', { item }, req.headers['x-socket-id']);
|
|
});
|
|
|
|
// PUT /api/trips/:tripId/packing/:id
|
|
router.put('/:id', authenticate, (req, res) => {
|
|
const { tripId, id } = req.params;
|
|
const { name, checked, category } = req.body;
|
|
|
|
const trip = verifyTripOwnership(tripId, req.user.id);
|
|
if (!trip) return res.status(404).json({ error: 'Trip not found' });
|
|
|
|
const item = db.prepare('SELECT * FROM packing_items WHERE id = ? AND trip_id = ?').get(id, tripId);
|
|
if (!item) return res.status(404).json({ error: 'Item not found' });
|
|
|
|
db.prepare(`
|
|
UPDATE packing_items SET
|
|
name = COALESCE(?, name),
|
|
checked = CASE WHEN ? IS NOT NULL THEN ? ELSE checked END,
|
|
category = COALESCE(?, category)
|
|
WHERE id = ?
|
|
`).run(
|
|
name || null,
|
|
checked !== undefined ? 1 : null,
|
|
checked ? 1 : 0,
|
|
category || null,
|
|
id
|
|
);
|
|
|
|
const updated = db.prepare('SELECT * FROM packing_items WHERE id = ?').get(id);
|
|
res.json({ item: updated });
|
|
broadcast(tripId, 'packing:updated', { item: updated }, req.headers['x-socket-id']);
|
|
});
|
|
|
|
// DELETE /api/trips/:tripId/packing/:id
|
|
router.delete('/:id', authenticate, (req, res) => {
|
|
const { tripId, id } = req.params;
|
|
|
|
const trip = verifyTripOwnership(tripId, req.user.id);
|
|
if (!trip) return res.status(404).json({ error: 'Trip not found' });
|
|
|
|
const item = db.prepare('SELECT id FROM packing_items WHERE id = ? AND trip_id = ?').get(id, tripId);
|
|
if (!item) return res.status(404).json({ error: 'Item not found' });
|
|
|
|
db.prepare('DELETE FROM packing_items WHERE id = ?').run(id);
|
|
res.json({ success: true });
|
|
broadcast(tripId, 'packing:deleted', { itemId: Number(id) }, req.headers['x-socket-id']);
|
|
});
|
|
|
|
// PUT /api/trips/:tripId/packing/reorder
|
|
router.put('/reorder', authenticate, (req, res) => {
|
|
const { tripId } = req.params;
|
|
const { orderedIds } = req.body;
|
|
|
|
const trip = verifyTripOwnership(tripId, req.user.id);
|
|
if (!trip) return res.status(404).json({ error: 'Trip not found' });
|
|
|
|
const update = db.prepare('UPDATE packing_items SET sort_order = ? WHERE id = ? AND trip_id = ?');
|
|
const updateMany = db.transaction((ids) => {
|
|
ids.forEach((id, index) => {
|
|
update.run(index, id, tripId);
|
|
});
|
|
});
|
|
|
|
updateMany(orderedIds);
|
|
res.json({ success: true });
|
|
});
|
|
|
|
module.exports = router;
|