Files
TREK/server/src/nest/tours/tours.controller.ts
T
Maurice 782e613506 Tours: day GPX import, wanderer trails and planning over an import
- GPX files drop onto the map or a day; the import lands on that day
- wanderer connection per user in Integrations; the workspace offers the
  user's own trails only, behind an admin switch under the Tours addon
- wanderer difficulty is stored on the SAC scale (T1 to T3), backfilled
- a GPX or wanderer import can be planned as an editable tour, either in
  place (the recorded track is kept and can be restored) or as a new tour
  that remembers the import it came from
- rails, rows and detail dialog follow the plan sidebar's cards and badges
- admin addon shelves with more than one row fold, collapsed by default
- reverse-geocoded waypoint names are cached on the device
2026-10-15 17:44:15 +02:00

69 lines
2.4 KiB
TypeScript

import { ADDON_IDS } from '../../addons';
import { AddonGuard } from '../addons/addon.guard';
import { RequireAddon } from '../addons/require-addon.decorator';
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
import { ResponseContract } from '../common/response-contract';
import { RequirePermission, TripAccessGuard } from '../permissions/trip-access.guard';
import { TourCreateDto } from './dto/tour-create.dto';
import { ToursService } from './tours.service';
import { Body, Controller, Get, Headers, HttpCode, Param, Post, Put, UseGuards } from '@nestjs/common';
import { tourDetailResponseSchema } from '@trek/shared';
/**
* /api/trips/:tripId/tours: the Tours facet, read and route edits.
* TripAccessGuard resolves
* :tripId (404 for no access); writes require 'place_edit'. Assignments stay
* on the existing day_edit endpoints. The multipart GPX import lives in
* ToursImportController, which checks the same rules in its handler.
*/
@Controller('api/trips/:tripId/tours')
@UseGuards(AddonGuard, JwtAuthGuard, TripAccessGuard)
@RequireAddon(ADDON_IDS.TOURS, 'Tours')
export class ToursController {
constructor(private readonly tours: ToursService) {}
@Get()
async list(@Param('tripId') tripId: string) {
return { tours: await this.tours.listTours(tripId) };
}
@Get(':placeId')
async detail(@Param('tripId') tripId: string, @Param('placeId') placeId: string) {
return await this.tours.getTour(tripId, placeId);
}
@RequirePermission('place_edit')
@Post()
async create(
@Param('tripId') tripId: string,
@Body() body: TourCreateDto,
@Headers('x-socket-id') socketId?: string,
) {
return await this.tours.createTour(tripId, body, socketId);
}
@RequirePermission('place_edit')
@Put(':placeId')
async update(
@Param('tripId') tripId: string,
@Param('placeId') placeId: string,
@Body() body: TourCreateDto,
@Headers('x-socket-id') socketId?: string,
) {
return await this.tours.updateTour(tripId, placeId, body, socketId);
}
/** Takes an import planned over in place back to its recorded track; the planning is dropped. */
@RequirePermission('place_edit')
@Post(':placeId/restore-recorded')
@HttpCode(200)
@ResponseContract(tourDetailResponseSchema)
async restoreRecorded(
@Param('tripId') tripId: string,
@Param('placeId') placeId: string,
@Headers('x-socket-id') socketId?: string,
) {
return await this.tours.restoreRecordedTrack(tripId, placeId, socketId);
}
}