Files
TREK/server/src/nest/tours/tour-drafts.controller.ts
T
Maurice 3f38621024 feat(server): let a trip owner switch trip addons for one trip
A trip can now turn a trip addon (lists, costs, documents, collab, road
trip, tours) on or off for itself, whatever the instance switch says. No
row in the new trip_addon_overrides table means the trip follows the
instance; a row is the owner's choice. Going back to the instance setting
deletes the row, and no addon data is touched either way.

- GET/PUT /api/trips/:tripId/addons[/:addonId] (every member reads, the
  owner writes) and the MCP tools get_trip_addons and set_trip_addon, on
  the shared tripAddons contract; tripAddons:changed tells the members.
- Every trip-scoped addon surface asks the trip: REST through
  TripAddonGuard, MCP through a per-call gate on the named or pinned trip,
  plugin RPC and events, the share link, the offline bundle, reminders,
  doc sync, the assistant (tools, keep_attached_file), booking costs, the
  trip summary prompt, and the cross-trip tour reads (library, Atlas
  stats, collection save).
- Routes without a trip open while the addon is on in any of the user's
  trips. Switching an addon on that the instance has off ends the members'
  MCP sessions so they reconnect with its tools.
- A copied trip takes its owner's choices along.

Behaviour changes: an anonymous call to an addon route that is off now
gets 401 instead of 404, and with an instance switch off the packing,
todo and files plugin RPC methods, the files MCP tools, todo reminder
mails, core plugin events, plugin view contributions, the share link's
lists, costs and chat sections and the offline bundle's lists follow it.
2026-11-21 13:23:09 +01:00

50 lines
2.0 KiB
TypeScript

import { ADDON_IDS } from '../../addons';
import type { User } from '../../types';
import { RequireAddon } from '../addons/require-addon.decorator';
import { TripAddonGuard } from '../addons/trip-addon.guard';
import { CurrentUser } from '../auth-core/current-user.decorator';
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
import { ResponseContract } from '../common/response-contract';
import { ParseRowIdPipe } from '../common/row-id.pipe';
import { RequirePermission, TripAccessGuard } from '../permissions/trip-access.guard';
import { TourDraftPutDto } from './dto/tour-draft.dto';
import { TourDraftsService } from './tour-drafts.service';
import { Body, Controller, Delete, Get, Param, Put, UseGuards } from '@nestjs/common';
import { successResponseSchema, tourDraftResponseSchema } from '@trek/shared';
/**
* /api/trips/:tripId/tour-draft: the caller's own unsaved draft of the Tours
* planner in this trip. Reading it and letting it go need the trip; keeping
* one needs 'place_edit', as saving the tour it becomes does. Every route
* names the signed-in user, so a traveller only ever reaches their own draft.
*/
@Controller('api/trips/:tripId/tour-draft')
@UseGuards(JwtAuthGuard, TripAccessGuard, TripAddonGuard)
@RequireAddon(ADDON_IDS.TOURS, 'Tours')
export class TourDraftsController {
constructor(private readonly drafts: TourDraftsService) {}
@Get()
@ResponseContract(tourDraftResponseSchema)
async read(@CurrentUser() user: User, @Param('tripId', ParseRowIdPipe) tripId: number) {
return await this.drafts.read(tripId, user.id);
}
@RequirePermission('place_edit')
@Put()
@ResponseContract(tourDraftResponseSchema)
async keep(
@CurrentUser() user: User,
@Param('tripId', ParseRowIdPipe) tripId: number,
@Body() body: TourDraftPutDto,
) {
return await this.drafts.keep(tripId, user.id, body);
}
@Delete()
@ResponseContract(successResponseSchema)
async forget(@CurrentUser() user: User, @Param('tripId', ParseRowIdPipe) tripId: number) {
return await this.drafts.forget(tripId, user.id);
}
}