fix(api): parse path ids with a rowId pipe that answers like an unknown id

RowIdPipe (src/nest/common/row-id.pipe.ts) parses a path param with toRowId. It answers a refused spelling with the route's own not-found answer, so '0x5', '5e0' and 'abc' get what an id that names no row gets. ParseRowIdPipe replaces Nest's ParseIntPipe with the same 400 and message: ParseIntPipe let '-1' and numbers past 2^53 through, and Postgres refuses the latter as out of range. Journey, journey recordings, day import, book design, map, public photo, collections, doc-sync, vacay, atlas and the plugin user-data export declare their ids through it. The upload routes parse in the handler with withRowId, so a refused id takes the existing cleanup path, or carry SpoolCleanupInterceptor (collections).
This commit is contained in:
Maurice
2026-11-18 13:20:05 +01:00
parent 7f6f2eb97c
commit 3eac508baf
28 changed files with 545 additions and 398 deletions
+3 -2
View File
@@ -1,6 +1,7 @@
import type { User } from '../../types';
import { CurrentUser } from '../auth-core/current-user.decorator';
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
import { rowId } from '../common/row-id.pipe';
import { ZodValidationPipe } from '../common/zod-validation.pipe';
import { getRegionGeoGz, getRegionGeoJson } from './atlas-geo';
import { AtlasWritesService } from './atlas-writes.service';
@@ -227,7 +228,7 @@ export class AtlasController {
@Put('bucket-list/:id')
async updateBucketItem(
@CurrentUser() user: User,
@Param('id') id: string,
@Param('id', rowId('Item not found')) id: number,
@Body() body: AtlasUpdateBucketItemDto,
@Headers('x-socket-id') socketId?: string,
): Promise<{ item: unknown }> {
@@ -253,7 +254,7 @@ export class AtlasController {
@Delete('bucket-list/:id')
async deleteBucketItem(
@CurrentUser() user: User,
@Param('id') id: string,
@Param('id', rowId('Item not found')) id: number,
@Headers('x-socket-id') socketId?: string,
): Promise<{ success: boolean }> {
if (!(await this.writes.deleteBucketItem(user.id, id, socketId))) {
@@ -8,6 +8,8 @@ import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
import { isDemoWriteBlocked, DEMO_WRITE_ERROR } from '../common/demo-write';
import { PLACE_IMAGE_FILE_FILTER } from '../common/place-image-upload';
import { ResponseContract } from '../common/response-contract';
import { rowId } from '../common/row-id.pipe';
import { SpoolCleanupInterceptor } from '../common/spool-cleanup.interceptor';
import { CollectionGpxError } from '../place-import/place-import.types';
import { placeImageUrl } from '../places/place-image';
import { PlaceRatingDto } from '../places/places.dto';
@@ -193,45 +195,49 @@ export class CollectionsController {
@Patch('places/:pid')
updatePlace(
@CurrentUser() user: User,
@Param('pid') pid: string,
@Param('pid', rowId('Place not found')) pid: number,
@Body() body: CollectionPlaceUpdateDto,
@Headers('x-socket-id') socketId?: string,
) {
return this.collections.updatePlace(user.id, Number(pid), body, socketId);
return this.collections.updatePlace(user.id, pid, body, socketId);
}
@Post('places/:pid/status')
@HttpCode(200)
setStatus(
@CurrentUser() user: User,
@Param('pid') pid: string,
@Param('pid', rowId('Place not found')) pid: number,
@Body() body: CollectionSetStatusDto,
@Headers('x-socket-id') socketId?: string,
) {
return this.collections.setStatus(user.id, Number(pid), body.status, socketId);
return this.collections.setStatus(user.id, pid, body.status, socketId);
}
@Put('places/:pid/rating')
setRating(
@CurrentUser() user: User,
@Param('pid') pid: string,
@Param('pid', rowId('Place not found')) pid: number,
@Body() body: PlaceRatingDto,
@Headers('x-socket-id') socketId?: string,
) {
return this.collections.setRating(user.id, Number(pid), body.rating, socketId);
return this.collections.setRating(user.id, pid, body.rating, socketId);
}
@Delete('places/:pid/rating')
clearRating(@CurrentUser() user: User, @Param('pid') pid: string, @Headers('x-socket-id') socketId?: string) {
return this.collections.setRating(user.id, Number(pid), null, socketId);
clearRating(
@CurrentUser() user: User,
@Param('pid', rowId('Place not found')) pid: number,
@Headers('x-socket-id') socketId?: string,
) {
return this.collections.setRating(user.id, pid, null, socketId);
}
@Post('places/:pid/image')
@HttpCode(200)
@UseInterceptors(FileInterceptor('image', { fileFilter: PLACE_IMAGE_FILE_FILTER }))
@UseInterceptors(FileInterceptor('image', { fileFilter: PLACE_IMAGE_FILE_FILTER }), SpoolCleanupInterceptor)
async uploadPlaceImage(
@CurrentUser() user: User,
@Param('pid') pid: string,
@Param('pid', rowId('Place not found')) pid: number,
@UploadedFile() file: Express.Multer.File | undefined,
@Headers('x-socket-id') socketId?: string,
) {
@@ -242,12 +248,16 @@ export class CollectionsController {
// Commit the spooled upload to its final storage location (atomic
// same-volume rename) before the DB row references the final path.
await this.storage.put('places', file.filename, { tmpPath: file.path });
return this.collections.setPlaceImage(user.id, Number(pid), placeImageUrl(file.filename), socketId);
return this.collections.setPlaceImage(user.id, pid, placeImageUrl(file.filename), socketId);
}
@Delete('places/:pid')
async deletePlace(@CurrentUser() user: User, @Param('pid') pid: string, @Headers('x-socket-id') socketId?: string) {
await this.collections.deletePlace(user.id, Number(pid), socketId);
async deletePlace(
@CurrentUser() user: User,
@Param('pid', rowId('Place not found')) pid: number,
@Headers('x-socket-id') socketId?: string,
) {
await this.collections.deletePlace(user.id, pid, socketId);
return { success: true };
}
@@ -309,16 +319,20 @@ export class CollectionsController {
@Patch('labels/:lid')
updateLabel(
@CurrentUser() user: User,
@Param('lid') lid: string,
@Param('lid', rowId('Label not found')) lid: number,
@Body() body: CollectionLabelUpdateDto,
@Headers('x-socket-id') socketId?: string,
) {
return this.collections.updateLabel(user.id, Number(lid), body, socketId);
return this.collections.updateLabel(user.id, lid, body, socketId);
}
@Delete('labels/:lid')
async deleteLabel(@CurrentUser() user: User, @Param('lid') lid: string, @Headers('x-socket-id') socketId?: string) {
await this.collections.deleteLabel(user.id, Number(lid), socketId);
async deleteLabel(
@CurrentUser() user: User,
@Param('lid', rowId('Label not found')) lid: number,
@Headers('x-socket-id') socketId?: string,
) {
await this.collections.deleteLabel(user.id, lid, socketId);
return { success: true };
}
@@ -450,19 +464,19 @@ export class CollectionsController {
// ── /:id (declared last so static prefixes win) ─────────────────────────────
@Get(':id/available-users')
async availableUsers(@CurrentUser() user: User, @Param('id') id: string) {
await this.collections.assertAccess(user.id, Number(id)); // 404 if not visible (no enumeration)
if (!(await this.collections.isOwner(user.id, Number(id)))) {
async availableUsers(@CurrentUser() user: User, @Param('id', rowId('Collection not found')) id: number) {
await this.collections.assertAccess(user.id, id); // 404 if not visible (no enumeration)
if (!(await this.collections.isOwner(user.id, id))) {
throw new HttpException({ error: 'Only the owner can manage members' }, 403);
}
return { users: await this.collections.availableUsers(user.id, Number(id)) };
return { users: await this.collections.availableUsers(user.id, id) };
}
@Post(':id/cover')
@UseInterceptors(FileInterceptor('cover', { fileFilter: COVER_FILE_FILTER }))
@UseInterceptors(FileInterceptor('cover', { fileFilter: COVER_FILE_FILTER }), SpoolCleanupInterceptor)
async uploadCover(
@CurrentUser() user: User,
@Param('id') id: string,
@Param('id', rowId('Collection not found')) id: number,
@UploadedFile() file: Express.Multer.File | undefined,
@Headers('x-socket-id') socketId?: string,
) {
@@ -474,7 +488,7 @@ export class CollectionsController {
// same-volume rename) before the DB row references the final path.
await this.storage.put('covers', file.filename, { tmpPath: file.path });
const coverUrl = `/uploads/covers/${file.filename}`;
return this.collections.setCollectionCover(user.id, Number(id), coverUrl, socketId);
return this.collections.setCollectionCover(user.id, id, coverUrl, socketId);
}
/** Preview for the bulk trip import: the trip's places plus, per place, the same
@@ -486,8 +500,8 @@ export class CollectionsController {
* filename decided by the server.
*/
@Get(':id/export')
exportCollection(@CurrentUser() user: User, @Param('id') id: string) {
return this.collections.exportCollection(user.id, Number(id));
exportCollection(@CurrentUser() user: User, @Param('id', rowId('Collection not found')) id: number) {
return this.collections.exportCollection(user.id, id);
}
/**
@@ -497,15 +511,15 @@ export class CollectionsController {
* no coordinates and were left out.
*/
@Get(':id/export/gpx')
exportCollectionGpx(@CurrentUser() user: User, @Param('id') id: string) {
return this.collections.exportCollectionGpx(user.id, Number(id));
exportCollectionGpx(@CurrentUser() user: User, @Param('id', rowId('Collection not found')) id: number) {
return this.collections.exportCollectionGpx(user.id, id);
}
/** The list as KML for Google My Maps (#1866), wrapped in JSON like the GPX above, for the same reasons. */
@Get(':id/export/kml')
@ResponseContract(collectionKmlExportSchema)
exportCollectionKml(@CurrentUser() user: User, @Param('id') id: string) {
return this.collections.exportCollectionKml(user.id, Number(id));
exportCollectionKml(@CurrentUser() user: User, @Param('id', rowId('Collection not found')) id: number) {
return this.collections.exportCollectionKml(user.id, id);
}
/**
@@ -519,36 +533,44 @@ export class CollectionsController {
@HttpCode(200)
importIntoCollection(
@CurrentUser() user: User,
@Param('id') id: string,
@Param('id', rowId('Collection not found')) id: number,
@Body() body: CollectionImportIntoDto,
@Headers('x-socket-id') socketId?: string,
) {
return this.collections.importIntoCollection(user.id, Number(id), body, socketId);
return this.collections.importIntoCollection(user.id, id, body, socketId);
}
@Get(':id/importable/:tripId')
importable(@CurrentUser() user: User, @Param('id') id: string, @Param('tripId') tripId: string) {
return this.collections.importablePlaces(user.id, Number(id), Number(tripId));
importable(
@CurrentUser() user: User,
@Param('id', rowId('Collection not found')) id: number,
@Param('tripId', rowId('Trip not found')) tripId: number,
) {
return this.collections.importablePlaces(user.id, id, tripId);
}
@Get(':id')
get(@CurrentUser() user: User, @Param('id') id: string) {
return this.collections.getCollection(user.id, Number(id));
get(@CurrentUser() user: User, @Param('id', rowId('Collection not found')) id: number) {
return this.collections.getCollection(user.id, id);
}
@Patch(':id')
update(
@CurrentUser() user: User,
@Param('id') id: string,
@Param('id', rowId('Collection not found')) id: number,
@Body() body: CollectionUpdateDto,
@Headers('x-socket-id') socketId?: string,
) {
return this.collections.updateCollection(user.id, Number(id), body, socketId);
return this.collections.updateCollection(user.id, id, body, socketId);
}
@Delete(':id')
async remove(@CurrentUser() user: User, @Param('id') id: string, @Headers('x-socket-id') socketId?: string) {
await this.collections.deleteCollection(user.id, Number(id), socketId);
async remove(
@CurrentUser() user: User,
@Param('id', rowId('Collection not found')) id: number,
@Headers('x-socket-id') socketId?: string,
) {
await this.collections.deleteCollection(user.id, id, socketId);
return { success: true };
}
}
+57
View File
@@ -0,0 +1,57 @@
import { toRowId } from './row-id';
import { HttpException, Injectable, type PipeTransform } from '@nestjs/common';
/** What a route answers for a path id that names no row: its own status and error text. */
interface RowIdRefusal {
status: number;
error: string;
}
/**
* Parses a route's row id param with `toRowId` before the handler sees it, and
* answers a spelling it refuses the way the route answers an id that names no
* row. `Number(id)` read '0x1', '1e0', '1.0' and '+1' as row 1 and 'abc' as
* NaN, which Postgres refuses with an error while SQLite matches nothing; a
* string handed on unparsed reached SQL, where Postgres 14 and 15 refuse the
* cast and 16 and later read hex and underscores as a number. Through this pipe
* every such spelling gets the same answer on every engine, and the handler
* receives a number.
*
* `tests/e2e/route-row-ids.e2e.test.ts` sends those spellings to every route.
*/
@Injectable()
class RowIdPipe implements PipeTransform<unknown, number> {
constructor(private readonly refusal: RowIdRefusal) {}
transform(value: unknown): number {
const id = toRowId(value);
if (id === null) throw new HttpException({ error: this.refusal.error }, this.refusal.status);
return id;
}
}
/** `@Param('id', rowId('Journey not found')) id: number`: the route's not-found answer for a malformed id. */
export function rowId(error: string, status = 404): RowIdPipe {
return new RowIdPipe({ status, error });
}
/**
* In place of Nest's `ParseIntPipe`, which reads '-1', '-0' and a number past
* 2^53 as integers, and Postgres refuses the last as out of range: its 400 and
* message, with `toRowId`'s parse. `@Param('id', ParseRowIdPipe) id: number`.
*/
@Injectable()
export class ParseRowIdPipe extends RowIdPipe {
constructor() {
super({ status: 400, error: 'Validation failed (numeric string is expected)' });
}
}
/**
* The same parse for a whole number in the path that is not a row id but is
* compared with an integer column all the same (a year, a day number):
* `@Param('year', intParam('Invalid year', 400)) year: number`.
*/
export function intParam(error: string, status = 400): RowIdPipe {
return new RowIdPipe({ status, error });
}
+23 -14
View File
@@ -4,6 +4,7 @@ import { AddonGuard } from '../addons/addon.guard';
import { RequireAddon } from '../addons/require-addon.decorator';
import { CurrentUser } from '../auth-core/current-user.decorator';
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
import { rowId } from '../common/row-id.pipe';
import { withRequestContext } from '../database/request-context';
import { TripAccessGuard } from '../permissions/trip-access.guard';
import { RealtimeService } from '../realtime/realtime.service';
@@ -208,11 +209,11 @@ export class DocSyncController {
@HttpCode(200)
async deleteConnection(
@Param('tripId') tripId: string,
@Param('connectionId') connectionId: string,
@Param('connectionId', rowId('Connection not found')) connectionId: number,
@CurrentUser() user: User,
) {
await this.assertCanManage(tripId, user);
const conn = await this.config.getConnection(Number(connectionId));
const conn = await this.config.getConnection(connectionId);
if (!conn || conn.trip_id !== Number(tripId)) throw new HttpException('Connection not found', 404);
// Its bindings go with it (ON DELETE CASCADE), so read them first. Every
// subscription TREK registered for one of them is taken down while the
@@ -238,12 +239,12 @@ export class DocSyncController {
@Get('connections/:connectionId/scopes')
async listScopes(
@Param('tripId') tripId: string,
@Param('connectionId') connectionId: string,
@Param('connectionId', rowId('Connection not found')) connectionId: number,
@CurrentUser() user: User,
@Query('q') q?: string,
) {
await this.assertCanManage(tripId, user);
const conn = await this.config.getConnection(Number(connectionId));
const conn = await this.config.getConnection(connectionId);
if (!conn || conn.trip_id !== Number(tripId)) throw new HttpException('Connection not found', 404);
const provider = this.registry.get(conn.provider_id);
if (!provider) throw new HttpException('Provider not available', 400);
@@ -255,12 +256,12 @@ export class DocSyncController {
@Post('connections/:connectionId/scopes')
async createScope(
@Param('tripId') tripId: string,
@Param('connectionId') connectionId: string,
@Param('connectionId', rowId('Connection not found')) connectionId: number,
@CurrentUser() user: User,
@Body() body: DocsyncScopeCreateDto,
) {
await this.assertCanManage(tripId, user);
const conn = await this.config.getConnection(Number(connectionId));
const conn = await this.config.getConnection(connectionId);
if (!conn || conn.trip_id !== Number(tripId)) throw new HttpException('Connection not found', 404);
const provider = this.registry.get(conn.provider_id);
if (!provider) throw new HttpException('Provider not available', 400);
@@ -343,13 +344,13 @@ export class DocSyncController {
@HttpCode(200)
async updateLink(
@Param('tripId') tripId: string,
@Param('linkId') linkId: string,
@Param('linkId', rowId('Link not found')) linkId: number,
@CurrentUser() user: User,
@Body() body: DocsyncLinkUpdateDto,
@Req() req: Request,
) {
await this.assertCanManage(tripId, user);
const link = await this.config.getLink(Number(linkId));
const link = await this.config.getLink(linkId);
if (!link || link.trip_id !== Number(tripId)) throw new HttpException('Link not found', 404);
const updated = await this.config.updateLink(link.id, body);
return await this.config.publicLink(updated ?? link, publicOrigin(req));
@@ -357,9 +358,13 @@ export class DocSyncController {
@Delete('links/:linkId')
@HttpCode(200)
async deleteLink(@Param('tripId') tripId: string, @Param('linkId') linkId: string, @CurrentUser() user: User) {
async deleteLink(
@Param('tripId') tripId: string,
@Param('linkId', rowId('Link not found')) linkId: number,
@CurrentUser() user: User,
) {
await this.assertCanManage(tripId, user);
const link = await this.config.getLink(Number(linkId));
const link = await this.config.getLink(linkId);
if (!link || link.trip_id !== Number(tripId)) throw new HttpException('Link not found', 404);
const conn = await this.config.getConnection(link.connection_id);
@@ -375,8 +380,12 @@ export class DocSyncController {
@Post('links/:linkId/sync')
@HttpCode(200)
async syncNow(@Param('tripId') tripId: string, @Param('linkId') linkId: string, @Body() body: DocsyncSyncNowDto) {
const link = await this.config.getLink(Number(linkId));
async syncNow(
@Param('tripId') tripId: string,
@Param('linkId', rowId('Link not found')) linkId: number,
@Body() body: DocsyncSyncNowDto,
) {
const link = await this.config.getLink(linkId);
if (!link || link.trip_id !== Number(tripId)) throw new HttpException('Link not found', 404);
// An orphaned binding stays orphaned: its credential belongs to somebody who
// is no longer on this trip. The run itself would stand down as well; this
@@ -413,12 +422,12 @@ export class DocSyncController {
@HttpCode(200)
async resolve(
@Param('tripId') tripId: string,
@Param('itemId') itemId: string,
@Param('itemId', rowId('Item is not in conflict', 400)) itemId: number,
@CurrentUser() user: User,
@Body() body: DocsyncResolveConflictDto,
) {
await this.assertCanManage(tripId, user);
const ok = await this.sync.resolveConflict(Number(itemId), body.keep, Number(tripId));
const ok = await this.sync.resolveConflict(itemId, body.keep, Number(tripId));
if (!ok) throw new HttpException('Item is not in conflict', 400);
return { success: true };
}
@@ -5,6 +5,7 @@ import { RequireAddon } from '../addons/require-addon.decorator';
import { CurrentUser } from '../auth-core/current-user.decorator';
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
import { ResponseContract } from '../common/response-contract';
import { rowId } from '../common/row-id.pipe';
import { JourneyDayImportService } from './journey-day-import.service';
import { dateParam } from './journey-recordings.controller';
import { JourneyDayImportDto } from './journey-recordings.dto';
@@ -27,8 +28,12 @@ export class JourneyDayImportController {
@Post(':date/stays/review')
@HttpCode(200)
@ResponseContract(journeyDayStaysSchema)
async review(@CurrentUser() user: User, @Param('id') id: string, @Param('date') date: string) {
return await this.dayImport.review(user.id, Number(id), dateParam(date));
async review(
@CurrentUser() user: User,
@Param('id', rowId('Journey not found')) id: number,
@Param('date') date: string,
) {
return await this.dayImport.review(user.id, id, dateParam(date));
}
@Post(':date/stays/import')
@@ -36,11 +41,11 @@ export class JourneyDayImportController {
@ResponseContract(journeyDayImportResultSchema)
async takeOver(
@CurrentUser() user: User,
@Param('id') id: string,
@Param('id', rowId('Journey not found')) id: number,
@Param('date') date: string,
@Body() body: JourneyDayImportDto,
@Headers('x-socket-id') socketId?: string,
) {
return await this.dayImport.takeOver(user.id, Number(id), dateParam(date), body, socketId);
return await this.dayImport.takeOver(user.id, id, dateParam(date), body, socketId);
}
}
@@ -5,6 +5,7 @@ import { RequireAddon } from '../addons/require-addon.decorator';
import { CurrentUser } from '../auth-core/current-user.decorator';
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
import { ResponseContract } from '../common/response-contract';
import { rowId } from '../common/row-id.pipe';
import { JourneyRecordingPreviewDto, JourneyRecordingSaveDto } from './journey-recordings.dto';
import { JourneyRecordingsService } from './journey-recordings.service';
import {
@@ -43,34 +44,38 @@ export class JourneyRecordingsController {
@Get()
@ResponseContract(journeyRecordedDaysResponseSchema)
async list(@CurrentUser() user: User, @Param('id') id: string) {
return { days: await this.recordings.list(user.id, Number(id)) };
async list(@CurrentUser() user: User, @Param('id', rowId('Journey not found')) id: number) {
return { days: await this.recordings.list(user.id, id) };
}
/** JRN-03: whether the journey prepares its recorded days, and how the caller's last runs went. */
@Get('prep')
@ResponseContract(journeyRecordingPrepSchema)
async prep(@CurrentUser() user: User, @Param('id') id: string) {
return await this.recordings.prepStatus(user.id, Number(id));
async prep(@CurrentUser() user: User, @Param('id', rowId('Journey not found')) id: number) {
return await this.recordings.prepStatus(user.id, id);
}
@Post('preview')
@HttpCode(200)
@ResponseContract(journeyRecordingPreviewSchema)
async preview(@CurrentUser() user: User, @Param('id') id: string, @Body() body: JourneyRecordingPreviewDto) {
return await this.recordings.preview(user.id, Number(id), body);
async preview(
@CurrentUser() user: User,
@Param('id', rowId('Journey not found')) id: number,
@Body() body: JourneyRecordingPreviewDto,
) {
return await this.recordings.preview(user.id, id, body);
}
@Put(':date')
@ResponseContract(journeyRecordingSaveResultSchema)
async save(
@CurrentUser() user: User,
@Param('id') id: string,
@Param('id', rowId('Journey not found')) id: number,
@Param('date') date: string,
@Body() body: JourneyRecordingSaveDto,
@Headers('x-socket-id') socketId?: string,
) {
return await this.recordings.save(user.id, Number(id), dateParam(date), body, socketId);
return await this.recordings.save(user.id, id, dateParam(date), body, socketId);
}
@Delete(':date')
@@ -78,11 +83,11 @@ export class JourneyRecordingsController {
@ResponseContract(successResponseSchema)
async remove(
@CurrentUser() user: User,
@Param('id') id: string,
@Param('id', rowId('Journey not found')) id: number,
@Param('date') date: string,
@Headers('x-socket-id') socketId?: string,
) {
await this.recordings.remove(user.id, Number(id), dateParam(date), socketId);
await this.recordings.remove(user.id, id, dateParam(date), socketId);
return { success: true as const };
}
}
@@ -5,6 +5,7 @@ import { RequireAddon } from '../addons/require-addon.decorator';
import { CurrentUser } from '../auth-core/current-user.decorator';
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
import { ResponseContract } from '../common/response-contract';
import { rowId } from '../common/row-id.pipe';
import { BookDesignSelectionDto } from './journey-book-design.dto';
import { JourneyBookDesignService } from './journey-book-design.service';
import { Body, Controller, Get, HttpCode, Param, Put, UseGuards } from '@nestjs/common';
@@ -27,8 +28,12 @@ export class JourneyBookDesignController {
@Get(':designId')
@ResponseContract(bookDesignDraftResponseSchema)
async draft(@CurrentUser() user: User, @Param('journeyId') journeyId: string, @Param('designId') designId: string) {
return this.designs.draftView(Number(journeyId), user.id, designId);
async draft(
@CurrentUser() user: User,
@Param('journeyId', rowId('Journey not found')) journeyId: number,
@Param('designId') designId: string,
) {
return this.designs.draftView(journeyId, user.id, designId);
}
@Put(':designId/selection')
@@ -36,10 +41,10 @@ export class JourneyBookDesignController {
@ResponseContract(bookDesignSelectionResponseSchema)
async select(
@CurrentUser() user: User,
@Param('journeyId') journeyId: string,
@Param('journeyId', rowId('Journey not found')) journeyId: number,
@Param('designId') designId: string,
@Body() body: BookDesignSelectionDto,
) {
return this.designs.select(Number(journeyId), user.id, designId, body.spreadIds);
return this.designs.select(journeyId, user.id, designId, body.spreadIds);
}
}
@@ -5,6 +5,7 @@ import { RequireAddon } from '../addons/require-addon.decorator';
import { CurrentUser } from '../auth-core/current-user.decorator';
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
import { ResponseContract } from '../common/response-contract';
import { rowId } from '../common/row-id.pipe';
import { JourneyMapService } from './journey-map.service';
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
import { journeyMapLayersResponseSchema } from '@trek/shared';
@@ -23,7 +24,7 @@ export class JourneyMapController {
@Get(':id/map-layers')
@ResponseContract(journeyMapLayersResponseSchema)
async layers(@CurrentUser() user: User, @Param('id') id: string) {
return this.map.mapLayers(Number(id), user.id);
async layers(@CurrentUser() user: User, @Param('id', rowId('Journey not found')) id: number) {
return this.map.mapLayers(id, user.id);
}
}
@@ -3,6 +3,7 @@ import { AddonGuard } from '../addons/addon.guard';
import { RequireAddon } from '../addons/require-addon.decorator';
import { Public } from '../auth-core/public.decorator';
import { ResponseContract } from '../common/response-contract';
import { rowId } from '../common/row-id.pipe';
import { StorageService } from '../storage/storage.service';
import { JourneyService } from './journey.service';
import { Controller, Get, HttpException, Param, Res, UseGuards } from '@nestjs/common';
@@ -61,20 +62,15 @@ export class JourneyPublicController {
@Get(':token/photos/:photoId/:kind')
async photo(
@Param('token') token: string,
@Param('photoId') photoId: string,
@Param('photoId', rowId('Not found')) photoId: number,
@Param('kind') kind: string,
@Res() res: Response,
): Promise<void> {
const valid = await this.journey.validateShareTokenForPhoto(token, Number(photoId));
const valid = await this.journey.validateShareTokenForPhoto(token, photoId);
if (!valid) {
throw new HttpException({ error: 'Not found' }, 404);
}
await this.journey.streamPhoto(
res,
valid.ownerId,
Number(photoId),
kind === 'thumbnail' ? 'thumbnail' : 'original',
);
await this.journey.streamPhoto(res, valid.ownerId, photoId, kind === 'thumbnail' ? 'thumbnail' : 'original');
}
@Get(':token/photo/:provider/:assetId/:ownerId/:kind')
+87 -80
View File
@@ -47,6 +47,8 @@ import { isVideoMime, isVideoExtension, MAX_VIDEO_SIZE } from '../files/files.co
import { AllowedFileTypesService } from '../files/allowed-file-types.service';
import { logError } from '../audit/audit-log.logger';
import { ResponseContract } from '../common/response-contract';
import { rowId } from '../common/row-id.pipe';
import { toRowId, withRowId } from '../common/row-id';
import {
emptyResponseSchema,
journeyListResponseSchema,
@@ -248,7 +250,8 @@ export class JourneyController {
// permissive so that guard keeps answering, not the pipe.
title: (body.title as string).trim(),
subtitle: body.subtitle as string | undefined,
trip_ids: Array.isArray(body.trip_ids) ? body.trip_ids.map(Number) : [],
// A trip id toRowId refuses names no trip, so it links none, like an id the user cannot open.
trip_ids: Array.isArray(body.trip_ids) ? body.trip_ids.map(toRowId).filter((id): id is number => id !== null) : [],
}, socketId);
}
@@ -264,8 +267,8 @@ export class JourneyController {
// ── Entries (prefix /entries — before /:id) ─────────────────────────────
@Patch('entries/:entryId')
async updateEntry(@CurrentUser() user: User, @Param('entryId') entryId: string, @Body() body: JourneyEntryUpdateDto, @Headers('x-socket-id') socketId?: string) {
const result = await this.journey.updateEntry(Number(entryId), user.id, body, socketId);
async updateEntry(@CurrentUser() user: User, @Param('entryId', rowId('Entry not found')) entryId: number, @Body() body: JourneyEntryUpdateDto, @Headers('x-socket-id') socketId?: string) {
const result = await this.journey.updateEntry(entryId, user.id, body, socketId);
if (!result) {
throw new HttpException({ error: 'Entry not found' }, 404);
}
@@ -274,8 +277,8 @@ export class JourneyController {
@Put('entries/:entryId/photos/reorder')
@ResponseContract(successResponseSchema)
async reorderEntryPhotos(@CurrentUser() user: User, @Param('entryId') entryId: string, @Body() body: JourneyReorderEntryPhotosDto, @Headers('x-socket-id') socketId?: string) {
if (!(await this.journey.reorderEntryPhotos(Number(entryId), user.id, body.orderedIds, socketId))) {
async reorderEntryPhotos(@CurrentUser() user: User, @Param('entryId', rowId('Entry not found')) entryId: number, @Body() body: JourneyReorderEntryPhotosDto, @Headers('x-socket-id') socketId?: string) {
if (!(await this.journey.reorderEntryPhotos(entryId, user.id, body.orderedIds, socketId))) {
throw new HttpException({ error: 'Entry not found' }, 404);
}
return { success: true };
@@ -283,8 +286,8 @@ export class JourneyController {
@Delete('entries/:entryId')
@ResponseContract(successResponseSchema)
async deleteEntry(@CurrentUser() user: User, @Param('entryId') entryId: string, @Headers('x-socket-id') socketId?: string) {
if (!(await this.journey.deleteEntry(Number(entryId), user.id, socketId))) {
async deleteEntry(@CurrentUser() user: User, @Param('entryId', rowId('Entry not found')) entryId: number, @Headers('x-socket-id') socketId?: string) {
if (!(await this.journey.deleteEntry(entryId, user.id, socketId))) {
throw new HttpException({ error: 'Entry not found' }, 404);
}
return { success: true };
@@ -304,7 +307,7 @@ export class JourneyController {
const refused: Express.Multer.File[] = [];
for (const file of files) {
const relativePath = `journey/${file.filename}`;
const photo = await this.journey.addPhoto(Number(entryId), user.id, relativePath, undefined, body?.caption as string | undefined);
const photo = await withRowId(entryId, (id) => this.journey.addPhoto(id, user.id, relativePath, undefined, body?.caption as string | undefined));
if (!photo) {
// No row points at this file, so nothing would ever clean it up.
refused.push(file);
@@ -372,14 +375,14 @@ export class JourneyController {
}
await this.commitJourneyUploads(poster ? [video, poster] : [video]);
const durationMs = body?.duration_ms != null ? Number(body.duration_ms) : null;
const photo = await this.journey.addPhoto(
Number(entryId),
const photo = await withRowId(entryId, (id) => this.journey.addPhoto(
id,
user.id,
`journey/${video.filename}`,
poster ? `journey/${poster.filename}` : undefined,
undefined,
{ mediaType: 'video', durationMs: durationMs != null && Number.isFinite(durationMs) ? durationMs : null },
);
));
if (!photo) {
// Committed already, so the pre-commit unlink would orphan the bytes.
await this.storage.delete('journey', video.filename).catch(() => {});
@@ -390,8 +393,8 @@ export class JourneyController {
}
@Post('entries/:entryId/provider-photos')
async providerPhotos(@CurrentUser() user: User, @Param('entryId') entryId: string, @Body() body: JourneyProviderPhotosDto, @Headers('x-socket-id') socketId?: string) {
return this.addProviderPhotos({ entryId: Number(entryId) }, user, body, socketId);
async providerPhotos(@CurrentUser() user: User, @Param('entryId', rowId('Not allowed or duplicate', 403)) entryId: number, @Body() body: JourneyProviderPhotosDto, @Headers('x-socket-id') socketId?: string) {
return this.addProviderPhotos({ entryId: entryId }, user, body, socketId);
}
/**
@@ -421,12 +424,12 @@ export class JourneyController {
}
@Post('entries/:entryId/link-photo')
async linkPhoto(@CurrentUser() user: User, @Param('entryId') entryId: string, @Body() body: JourneyLinkPhotoDto, @Headers('x-socket-id') socketId?: string) {
const journeyPhotoId = body.journey_photo_id ?? body.photo_id;
async linkPhoto(@CurrentUser() user: User, @Param('entryId', rowId('Not allowed', 403)) entryId: number, @Body() body: JourneyLinkPhotoDto, @Headers('x-socket-id') socketId?: string) {
const journeyPhotoId = toRowId(body.journey_photo_id ?? body.photo_id);
if (!journeyPhotoId) {
throw new HttpException({ error: 'journey_photo_id required' }, 400);
}
const result = await this.photoLinks.link(Number(entryId), Number(journeyPhotoId), user.id, socketId);
const result = await this.photoLinks.link(entryId, journeyPhotoId, user.id, socketId);
if (!result) {
throw new HttpException({ error: 'Not allowed' }, 403);
}
@@ -437,22 +440,22 @@ export class JourneyController {
@Post('entries/:entryId/photos/move')
@HttpCode(200)
@ResponseContract(journeyPhotosMoveResponseSchema)
async movePhotos(@CurrentUser() user: User, @Param('entryId') entryId: string, @Body() body: JourneyPhotosMoveDto, @Headers('x-socket-id') socketId?: string) {
return this.photoLinks.move(Number(entryId), body, user.id, socketId);
async movePhotos(@CurrentUser() user: User, @Param('entryId', rowId('Entry not found')) entryId: number, @Body() body: JourneyPhotosMoveDto, @Headers('x-socket-id') socketId?: string) {
return this.photoLinks.move(entryId, body, user.id, socketId);
}
@Delete('entries/:entryId/photos/:journeyPhotoId')
@HttpCode(204)
@ResponseContract(emptyResponseSchema)
async unlinkPhoto(@CurrentUser() user: User, @Param('entryId') entryId: string, @Param('journeyPhotoId') journeyPhotoId: string, @Headers('x-socket-id') socketId?: string): Promise<void> {
if (!(await this.photoLinks.unlink(Number(entryId), Number(journeyPhotoId), user.id, socketId))) {
async unlinkPhoto(@CurrentUser() user: User, @Param('entryId', rowId('Not found or not allowed')) entryId: number, @Param('journeyPhotoId', rowId('Not found or not allowed')) journeyPhotoId: number, @Headers('x-socket-id') socketId?: string): Promise<void> {
if (!(await this.photoLinks.unlink(entryId, journeyPhotoId, user.id, socketId))) {
throw new HttpException({ error: 'Not found or not allowed' }, 404);
}
}
@Patch('photos/:photoId')
async updatePhoto(@CurrentUser() user: User, @Param('photoId') photoId: string, @Body() body: JourneyPhotoUpdateDto, @Headers('x-socket-id') socketId?: string) {
const result = await this.photoLinks.updatePhoto(Number(photoId), user.id, body, socketId);
async updatePhoto(@CurrentUser() user: User, @Param('photoId', rowId('Photo not found')) photoId: number, @Body() body: JourneyPhotoUpdateDto, @Headers('x-socket-id') socketId?: string) {
const result = await this.photoLinks.updatePhoto(photoId, user.id, body, socketId);
if (!result) {
throw new HttpException({ error: 'Photo not found' }, 404);
}
@@ -461,8 +464,8 @@ export class JourneyController {
@Delete('photos/:photoId')
@ResponseContract(successResponseSchema)
async deletePhoto(@CurrentUser() user: User, @Param('photoId') photoId: string) {
const photo = await this.journey.deletePhoto(Number(photoId), user.id);
async deletePhoto(@CurrentUser() user: User, @Param('photoId', rowId('Photo not found')) photoId: number) {
const photo = await this.journey.deletePhoto(photoId, user.id);
if (!photo) {
throw new HttpException({ error: 'Photo not found' }, 404);
}
@@ -490,7 +493,7 @@ export class JourneyController {
}
await this.commitJourneyUploads(files);
const filePaths = files.map((f) => ({ path: `journey/${f.filename}` }));
const photos = await this.journey.uploadGalleryPhotos(Number(id), user.id, filePaths);
const photos = (await withRowId(id, (journeyId) => this.journey.uploadGalleryPhotos(journeyId, user.id, filePaths))) ?? [];
if (!photos.length) {
await this.discardJourneyUploads(files);
throw new HttpException({ error: 'Not allowed' }, 403);
@@ -531,12 +534,12 @@ export class JourneyController {
}
await this.commitJourneyUploads(poster ? [video, poster] : [video]);
const durationMs = body?.duration_ms != null ? Number(body.duration_ms) : null;
const photos = await this.journey.uploadGalleryPhotos(Number(id), user.id, [{
const photos = (await withRowId(id, (journeyId) => this.journey.uploadGalleryPhotos(journeyId, user.id, [{
path: `journey/${video.filename}`,
thumbnail: poster ? `journey/${poster.filename}` : undefined,
mediaType: 'video',
durationMs: durationMs != null && Number.isFinite(durationMs) ? durationMs : null,
}]);
}]))) ?? [];
if (!photos.length) {
// The parts are already committed (file.path is consumed), so the
// pre-commit unlink cleanup would silently orphan them — delete the
@@ -549,15 +552,15 @@ export class JourneyController {
}
@Post(':id/gallery/provider-photos')
async galleryProviderPhotos(@CurrentUser() user: User, @Param('id') id: string, @Body() body: JourneyProviderPhotosDto, @Headers('x-socket-id') socketId?: string) {
return this.addProviderPhotos({ journeyId: Number(id) }, user, body, socketId);
async galleryProviderPhotos(@CurrentUser() user: User, @Param('id', rowId('Not allowed or duplicate', 403)) id: number, @Body() body: JourneyProviderPhotosDto, @Headers('x-socket-id') socketId?: string) {
return this.addProviderPhotos({ journeyId: id }, user, body, socketId);
}
@Delete(':id/gallery/:journeyPhotoId')
@HttpCode(204)
@ResponseContract(emptyResponseSchema)
async deleteGalleryPhoto(@CurrentUser() user: User, @Param('journeyPhotoId') journeyPhotoId: string): Promise<void> {
const photo = await this.journey.deleteGalleryPhoto(Number(journeyPhotoId), user.id);
async deleteGalleryPhoto(@CurrentUser() user: User, @Param('journeyPhotoId', rowId('Photo not found or not allowed')) journeyPhotoId: number): Promise<void> {
const photo = await this.journey.deleteGalleryPhoto(journeyPhotoId, user.id);
if (!photo) {
throw new HttpException({ error: 'Photo not found or not allowed' }, 404);
}
@@ -566,8 +569,8 @@ export class JourneyController {
// ── Journeys /:id ───────────────────────────────────────────────────────
@Get(':id')
async get(@CurrentUser() user: User, @Param('id') id: string) {
const data = await this.journey.getJourneyFull(Number(id), user.id);
async get(@CurrentUser() user: User, @Param('id', rowId('Journey not found')) id: number) {
const data = await this.journey.getJourneyFull(id, user.id);
if (!data) {
throw new HttpException({ error: 'Journey not found' }, 404);
}
@@ -575,8 +578,8 @@ export class JourneyController {
}
@Patch(':id')
async update(@CurrentUser() user: User, @Param('id') id: string, @Body() body: JourneyUpdateDto, @Headers('x-socket-id') socketId?: string) {
const result = await this.journey.updateJourney(Number(id), user.id, body, socketId);
async update(@CurrentUser() user: User, @Param('id', rowId('Journey not found')) id: number, @Body() body: JourneyUpdateDto, @Headers('x-socket-id') socketId?: string) {
const result = await this.journey.updateJourney(id, user.id, body, socketId);
if (!result) {
throw new HttpException({ error: 'Journey not found' }, 404);
}
@@ -592,7 +595,7 @@ export class JourneyController {
throw new HttpException({ error: 'No file uploaded' }, 400);
}
await this.commitJourneyUploads([file]);
const result = await this.journey.updateJourney(Number(id), user.id, { cover_image: `journey/${file.filename}` }, socketId);
const result = await withRowId(id, (journeyId) => this.journey.updateJourney(journeyId, user.id, { cover_image: `journey/${file.filename}` }, socketId));
if (!result) {
await this.discardJourneyUploads([file]);
throw new HttpException({ error: 'Journey not found' }, 404);
@@ -602,8 +605,8 @@ export class JourneyController {
@Delete(':id')
@ResponseContract(successResponseSchema)
async remove(@CurrentUser() user: User, @Param('id') id: string, @Headers('x-socket-id') socketId?: string) {
if (!(await this.journey.deleteJourney(Number(id), user.id, socketId))) {
async remove(@CurrentUser() user: User, @Param('id', rowId('Journey not found')) id: number, @Headers('x-socket-id') socketId?: string) {
if (!(await this.journey.deleteJourney(id, user.id, socketId))) {
throw new HttpException({ error: 'Journey not found' }, 404);
}
return { success: true };
@@ -613,11 +616,13 @@ export class JourneyController {
@Post(':id/trips')
@HttpCode(200) // Express answers with res.json (200).
@ResponseContract(successResponseSchema)
async addTrip(@CurrentUser() user: User, @Param('id') id: string, @Body() body: JourneyAddTripDto) {
if (!body.trip_id) {
async addTrip(@CurrentUser() user: User, @Param('id', rowId('Not allowed', 403)) id: number, @Body() body: JourneyAddTripDto) {
// A body id toRowId refuses ('5e0', '0x5') is no id, as on every route.
const tripId = toRowId(body.trip_id);
if (!tripId) {
throw new HttpException({ error: 'trip_id required' }, 400);
}
if (!(await this.journey.addTripToJourney(Number(id), Number(body.trip_id), user.id))) {
if (!(await this.journey.addTripToJourney(id, tripId, user.id))) {
throw new HttpException({ error: 'Not allowed' }, 403);
}
return { success: true };
@@ -625,8 +630,8 @@ export class JourneyController {
@Delete(':id/trips/:tripId')
@ResponseContract(successResponseSchema)
async removeTrip(@CurrentUser() user: User, @Param('id') id: string, @Param('tripId') tripId: string, @Headers('x-socket-id') socketId?: string) {
if (!(await this.journey.removeTripFromJourney(Number(id), Number(tripId), user.id, socketId))) {
async removeTrip(@CurrentUser() user: User, @Param('id', rowId('Not allowed', 403)) id: number, @Param('tripId', rowId('Not allowed', 403)) tripId: number, @Headers('x-socket-id') socketId?: string) {
if (!(await this.journey.removeTripFromJourney(id, tripId, user.id, socketId))) {
throw new HttpException({ error: 'Not allowed' }, 403);
}
return { success: true };
@@ -634,8 +639,8 @@ export class JourneyController {
// ── Entries under journey ───────────────────────────────────────────────
@Get(':id/entries')
async listEntries(@CurrentUser() user: User, @Param('id') id: string) {
const entries = await this.journey.listEntries(Number(id), user.id);
async listEntries(@CurrentUser() user: User, @Param('id', rowId('Journey not found')) id: number) {
const entries = await this.journey.listEntries(id, user.id);
if (!entries) {
throw new HttpException({ error: 'Journey not found' }, 404);
}
@@ -649,8 +654,8 @@ export class JourneyController {
*/
@Get(':id/tracks')
@ResponseContract(journeyTracksResponseSchema)
async listTracks(@CurrentUser() user: User, @Param('id') id: string) {
const tracks = await this.journey.journeyTracks(Number(id), user.id);
async listTracks(@CurrentUser() user: User, @Param('id', rowId('Journey not found')) id: number) {
const tracks = await this.journey.journeyTracks(id, user.id);
if (!tracks) {
throw new HttpException({ error: 'Journey not found' }, 404);
}
@@ -668,8 +673,8 @@ export class JourneyController {
*/
@Get(':id/stats')
@ResponseContract(journeyStatsSchema)
async stats(@CurrentUser() user: User, @Param('id') id: string) {
const stats = await this.journey.journeyStats(Number(id), user.id);
async stats(@CurrentUser() user: User, @Param('id', rowId('Journey not found')) id: number) {
const stats = await this.journey.journeyStats(id, user.id);
if (!stats) {
throw new HttpException({ error: 'Journey not found' }, 404);
}
@@ -685,9 +690,9 @@ export class JourneyController {
*/
@Get(':id/book')
async getBook(@CurrentUser() user: User, @Param('id') id: string) {
const book = await this.books.getBook(Number(id), user.id);
if (book === null && !(await this.books.canOpen(Number(id), user.id))) {
async getBook(@CurrentUser() user: User, @Param('id', rowId('Journey not found')) id: number) {
const book = await this.books.getBook(id, user.id);
if (book === null && !(await this.books.canOpen(id, user.id))) {
throw new HttpException({ error: 'Journey not found' }, 404);
}
// A journey with no book yet is not an error: Studio opens, lays one out
@@ -700,19 +705,19 @@ export class JourneyController {
@HttpCode(200)
async saveBook(
@CurrentUser() user: User,
@Param('id') id: string,
@Param('id', rowId('Journey not found')) id: number,
@Body() body: BookSaveDto,
@Headers('x-socket-id') socketId?: string,
) {
// The service announces the save after its commit, leaving out this tab.
const result = await this.books.saveBook(
Number(id),
id,
user.id,
{ title: body.title ?? '', document: body.document, baseVersion: body.baseVersion },
{ socketId },
);
if (result === null) {
throw await this.bookRefusal(Number(id), user.id);
throw await this.bookRefusal(id, user.id);
}
if ('conflict' in result) {
/*
@@ -734,10 +739,10 @@ export class JourneyController {
@Delete(':id/book')
@HttpCode(204)
@ResponseContract(emptyResponseSchema)
async deleteBook(@CurrentUser() user: User, @Param('id') id: string) {
const removed = await this.books.deleteBook(Number(id), user.id);
async deleteBook(@CurrentUser() user: User, @Param('id', rowId('Journey not found')) id: number) {
const removed = await this.books.deleteBook(id, user.id);
if (removed === null) {
throw await this.bookRefusal(Number(id), user.id);
throw await this.bookRefusal(id, user.id);
}
}
@@ -756,11 +761,11 @@ export class JourneyController {
}
@Post(':id/entries')
async createEntry(@CurrentUser() user: User, @Param('id') id: string, @Body() body: JourneyEntryCreateDto, @Headers('x-socket-id') socketId?: string) {
async createEntry(@CurrentUser() user: User, @Param('id', rowId('Journey not found')) id: number, @Body() body: JourneyEntryCreateDto, @Headers('x-socket-id') socketId?: string) {
if (!body.entry_date) {
throw new HttpException({ error: 'entry_date is required' }, 400);
}
const entry = await this.journey.createEntry(Number(id), user.id, body, socketId);
const entry = await this.journey.createEntry(id, user.id, body, socketId);
if (!entry) {
throw new HttpException({ error: 'Journey not found' }, 404);
}
@@ -769,12 +774,13 @@ export class JourneyController {
@Put(':id/entries/reorder')
@ResponseContract(successResponseSchema)
async reorderEntries(@CurrentUser() user: User, @Param('id') id: string, @Body() body: JourneyReorderEntriesDto, @Headers('x-socket-id') socketId?: string) {
async reorderEntries(@CurrentUser() user: User, @Param('id', rowId('Not allowed', 403)) id: number, @Body() body: JourneyReorderEntriesDto, @Headers('x-socket-id') socketId?: string) {
const orderedIds = body.orderedIds;
if (!Array.isArray(orderedIds) || !orderedIds.every((v) => Number.isFinite(Number(v)))) {
const entryIds = Array.isArray(orderedIds) ? orderedIds.map(toRowId) : null;
if (!entryIds?.every((v) => v !== null)) {
throw new HttpException({ error: 'orderedIds must be an array of numbers' }, 400);
}
if (!(await this.journey.reorderEntries(Number(id), user.id, orderedIds.map(Number), socketId))) {
if (!(await this.journey.reorderEntries(id, user.id, entryIds as number[], socketId))) {
throw new HttpException({ error: 'Not allowed' }, 403);
}
return { success: true };
@@ -783,11 +789,12 @@ export class JourneyController {
// ── Contributors ────────────────────────────────────────────────────────
@Post(':id/contributors')
@ResponseContract(successResponseSchema)
async addContributor(@CurrentUser() user: User, @Param('id') id: string, @Body() body: JourneyContributorAddDto) {
if (!body.user_id) {
async addContributor(@CurrentUser() user: User, @Param('id', rowId('Not allowed', 403)) id: number, @Body() body: JourneyContributorAddDto) {
const contributorId = toRowId(body.user_id);
if (!contributorId) {
throw new HttpException({ error: 'user_id required' }, 400);
}
if (!(await this.journey.addContributor(Number(id), user.id, Number(body.user_id), (body.role as 'editor' | 'viewer') || 'viewer'))) {
if (!(await this.journey.addContributor(id, user.id, contributorId, (body.role as 'editor' | 'viewer') || 'viewer'))) {
throw new HttpException({ error: 'Not allowed' }, 403);
}
return { success: true };
@@ -795,8 +802,8 @@ export class JourneyController {
@Patch(':id/contributors/:userId')
@ResponseContract(successResponseSchema)
async updateContributor(@CurrentUser() user: User, @Param('id') id: string, @Param('userId') userId: string, @Body() body: JourneyContributorUpdateDto) {
if (!(await this.journey.updateContributorRole(Number(id), user.id, Number(userId), body.role as 'editor' | 'viewer'))) {
async updateContributor(@CurrentUser() user: User, @Param('id', rowId('Not allowed', 403)) id: number, @Param('userId', rowId('Not allowed', 403)) userId: number, @Body() body: JourneyContributorUpdateDto) {
if (!(await this.journey.updateContributorRole(id, user.id, userId, body.role as 'editor' | 'viewer'))) {
throw new HttpException({ error: 'Not allowed' }, 403);
}
return { success: true };
@@ -804,8 +811,8 @@ export class JourneyController {
@Delete(':id/contributors/:userId')
@ResponseContract(successResponseSchema)
async removeContributor(@CurrentUser() user: User, @Param('id') id: string, @Param('userId') userId: string) {
if (!(await this.journey.removeContributor(Number(id), user.id, Number(userId)))) {
async removeContributor(@CurrentUser() user: User, @Param('id', rowId('Not allowed', 403)) id: number, @Param('userId', rowId('Not allowed', 403)) userId: number) {
if (!(await this.journey.removeContributor(id, user.id, userId))) {
throw new HttpException({ error: 'Not allowed' }, 403);
}
return { success: true };
@@ -814,8 +821,8 @@ export class JourneyController {
// ── Suggestions ─────────────────────────────────────────────────────────
@Post(':id/suggestions/restore')
@HttpCode(200)
async restoreSuggestions(@CurrentUser() user: User, @Param('id') id: string, @Headers('x-socket-id') socketId?: string) {
const result = await this.journey.restoreDismissedSuggestions(Number(id), user.id, socketId);
async restoreSuggestions(@CurrentUser() user: User, @Param('id', rowId('Not allowed', 403)) id: number, @Headers('x-socket-id') socketId?: string) {
const result = await this.journey.restoreDismissedSuggestions(id, user.id, socketId);
if (!result) {
throw new HttpException({ error: 'Not allowed' }, 403);
}
@@ -824,8 +831,8 @@ export class JourneyController {
// ── User Preferences ────────────────────────────────────────────────────
@Patch(':id/preferences')
async preferences(@CurrentUser() user: User, @Param('id') id: string, @Body() body: JourneyPreferencesDto, @Headers('x-socket-id') socketId?: string) {
const result = await this.journey.updateJourneyPreferences(Number(id), user.id, body, socketId);
async preferences(@CurrentUser() user: User, @Param('id', rowId('Not allowed', 403)) id: number, @Body() body: JourneyPreferencesDto, @Headers('x-socket-id') socketId?: string) {
const result = await this.journey.updateJourneyPreferences(id, user.id, body, socketId);
if (!result) {
throw new HttpException({ error: 'Not allowed' }, 403);
}
@@ -835,12 +842,12 @@ export class JourneyController {
// ── Share Link ──────────────────────────────────────────────────────────
@Get(':id/share-link')
@ResponseContract(journeyShareLinkResponseSchema)
async getShareLink(@CurrentUser() user: User, @Param('id') id: string) {
async getShareLink(@CurrentUser() user: User, @Param('id', rowId('Not allowed', 403)) id: number) {
// Reading the token is owner-only. It refuses like its siblings rather than
// answering with a null link: "not published" and "not yours to see" are
// different answers, and a client told the first one offers a create button
// that the POST below then refuses.
const result = await this.journey.getJourneyShareLink(Number(id), user.id);
const result = await this.journey.getJourneyShareLink(id, user.id);
if (!result.allowed) {
throw new HttpException({ error: 'Not allowed' }, 403);
}
@@ -850,8 +857,8 @@ export class JourneyController {
@Post(':id/share-link')
@HttpCode(200) // Express answers with res.json (200).
@ResponseContract(journeyShareLinkSetResponseSchema)
async setShareLink(@CurrentUser() user: User, @Param('id') id: string, @Body() body: JourneyShareLinkDto) {
const result = await this.journey.createOrUpdateJourneyShareLink(Number(id), user.id, {
async setShareLink(@CurrentUser() user: User, @Param('id', rowId('Not allowed', 403)) id: number, @Body() body: JourneyShareLinkDto) {
const result = await this.journey.createOrUpdateJourneyShareLink(id, user.id, {
share_timeline: body.share_timeline as boolean | undefined,
share_gallery: body.share_gallery as boolean | undefined,
share_map: body.share_map as boolean | undefined,
@@ -867,8 +874,8 @@ export class JourneyController {
@Delete(':id/share-link')
@ResponseContract(successResponseSchema)
async deleteShareLink(@CurrentUser() user: User, @Param('id') id: string) {
if (!(await this.journey.deleteJourneyShareLink(Number(id), user.id))) {
async deleteShareLink(@CurrentUser() user: User, @Param('id', rowId('Not allowed', 403)) id: number) {
if (!(await this.journey.deleteJourneyShareLink(id, user.id))) {
throw new HttpException({ error: 'Not allowed' }, 403);
}
return { success: true };
@@ -8,6 +8,7 @@ import { AdminGuard } from '../auth-core/admin.guard';
import { CurrentUser } from '../auth-core/current-user.decorator';
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
import { ManagedForbidden, isManagedBlocked, MANAGED_FORBIDDEN_ERROR } from '../common/managed';
import { rowId } from '../common/row-id.pipe';
import { DependencyCycleError } from './dependencies';
import { devLinkEnabled } from './dev-link';
import { pluginsEnabled } from './kill-switch';
@@ -430,9 +431,8 @@ export class PluginsController {
* user, for an admin fulfilling a data-access request. Literal-prefixed path, so it
* never collides with the :id routes. */
@Get('user-data/:userId/export')
async exportUserData(@Param('userId') userId: string) {
const id = Number(userId);
if (!Number.isInteger(id) || id <= 0) throw new HttpException({ error: 'invalid user id' }, 400);
async exportUserData(@Param('userId', rowId('invalid user id', 400)) id: number) {
if (id <= 0) throw new HttpException({ error: 'invalid user id' }, 400);
return { userId: id, plugins: await this.runtime.exportUserData(id) };
}
@@ -2,9 +2,10 @@ 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 { ParseRowIdPipe } from '../common/row-id.pipe';
import { TripAccessGuard } from '../permissions/trip-access.guard';
import { ChargingService } from './charging.service';
import { Controller, Get, Param, ParseIntPipe, UseGuards } from '@nestjs/common';
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
@Controller('api/trips/:tripId/roadtrip/charging')
@UseGuards(AddonGuard, JwtAuthGuard, TripAccessGuard)
@@ -12,7 +13,7 @@ import { Controller, Get, Param, ParseIntPipe, UseGuards } from '@nestjs/common'
export class ChargingController {
constructor(private readonly charging: ChargingService) {}
@Get(':placeId')
read(@Param('tripId', ParseIntPipe) tripId: number, @Param('placeId', ParseIntPipe) placeId: number) {
read(@Param('tripId', ParseRowIdPipe) tripId: number, @Param('placeId', ParseRowIdPipe) placeId: number) {
return this.charging.read(tripId, placeId);
}
}
@@ -2,10 +2,11 @@ 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 { ParseRowIdPipe } from '../common/row-id.pipe';
import { RequirePermission, TripAccessGuard } from '../permissions/trip-access.guard';
import { RealtimeService } from '../realtime/realtime.service';
import { DayBoundariesService } from './day-boundaries.service';
import { Body, Controller, Delete, Get, Headers, Param, ParseIntPipe, Put, UseGuards } from '@nestjs/common';
import { Body, Controller, Delete, Get, Headers, Param, Put, UseGuards } from '@nestjs/common';
import { roadtripDayBoundarySchema } from '@trek/shared';
import { createZodDto } from 'nestjs-zod';
@@ -38,7 +39,7 @@ export class DayBoundariesController {
@RequirePermission('day_edit')
async remove(
@Param('tripId') tripId: string,
@Param('dayNumber', ParseIntPipe) dayNumber: number,
@Param('dayNumber', ParseRowIdPipe) dayNumber: number,
@Headers('x-socket-id') socketId?: string,
) {
const boundaries = await this.boundaries.remove(tripId, dayNumber);
@@ -1,19 +1,8 @@
import { AdminGuard } from '../auth-core/admin.guard';
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
import { ParseRowIdPipe } from '../common/row-id.pipe';
import { SchoolHolidaysService } from './school-holidays.service';
import {
Body,
Controller,
Delete,
Get,
Param,
ParseIntPipe,
Post,
Put,
Query,
UseGuards,
BadRequestException,
} from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Post, Put, Query, UseGuards, BadRequestException } from '@nestjs/common';
import { schoolHolidayCountryRequestSchema, schoolHolidayRegionRequestSchema } from '@trek/shared';
import { createZodDto } from 'nestjs-zod';
@@ -32,12 +21,12 @@ export class SchoolHolidaysController {
}
@Get('regions/:id')
async region(@Param('id', ParseIntPipe) id: number) {
async region(@Param('id', ParseRowIdPipe) id: number) {
return this.holidays.region(id);
}
@Get('regions/:id/holidays/:year')
async forYear(@Param('id', ParseIntPipe) id: number, @Param('year') year: string) {
async forYear(@Param('id', ParseRowIdPipe) id: number, @Param('year') year: string) {
if (!/^\d{4}$/.test(year)) throw new BadRequestException('Invalid year');
return this.holidays.holidays(id, year);
}
@@ -62,13 +51,13 @@ export class SchoolHolidaysController {
@Put('regions/:id')
@UseGuards(AdminGuard)
async updateRegion(@Param('id', ParseIntPipe) id: number, @Body() body: SchoolHolidayRegionDto) {
async updateRegion(@Param('id', ParseRowIdPipe) id: number, @Body() body: SchoolHolidayRegionDto) {
return this.holidays.updateRegion(id, body);
}
@Delete('regions/:id')
@UseGuards(AdminGuard)
async deleteRegion(@Param('id', ParseIntPipe) id: number, @Query('revision', ParseIntPipe) revision: number) {
async deleteRegion(@Param('id', ParseRowIdPipe) id: number, @Query('revision', ParseRowIdPipe) revision: number) {
return this.holidays.deleteRegion(id, revision);
}
}
@@ -5,10 +5,11 @@ import { RequireAddon } from '../addons/require-addon.decorator';
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 { TourActivityAssignDto } from './dto/tour-activity.dto';
import { TourActivitiesService } from './tour-activities.service';
import { Body, Controller, Delete, Headers, Param, ParseIntPipe, Put, UseGuards } from '@nestjs/common';
import { Body, Controller, Delete, Headers, Param, Put, UseGuards } from '@nestjs/common';
import { tourDetailResponseSchema } from '@trek/shared';
/**
@@ -44,7 +45,7 @@ export class TourActivitiesController {
async unassign(
@Param('tripId') tripId: string,
@Param('placeId') placeId: string,
@Param('activityId', ParseIntPipe) activityId: number,
@Param('activityId', ParseRowIdPipe) activityId: number,
@Headers('x-socket-id') socketId?: string,
) {
return await this.activities.unassign(tripId, placeId, activityId, socketId);
@@ -5,10 +5,11 @@ import { RequireAddon } from '../addons/require-addon.decorator';
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, ParseIntPipe, Put, UseGuards } from '@nestjs/common';
import { Body, Controller, Delete, Get, Param, Put, UseGuards } from '@nestjs/common';
import { successResponseSchema, tourDraftResponseSchema } from '@trek/shared';
/**
@@ -25,20 +26,24 @@ export class TourDraftsController {
@Get()
@ResponseContract(tourDraftResponseSchema)
async read(@CurrentUser() user: User, @Param('tripId', ParseIntPipe) tripId: number) {
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', ParseIntPipe) tripId: number, @Body() body: TourDraftPutDto) {
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', ParseIntPipe) tripId: number) {
async forget(@CurrentUser() user: User, @Param('tripId', ParseRowIdPipe) tripId: number) {
return await this.drafts.forget(tripId, user.id);
}
}
@@ -3,20 +3,11 @@ 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 { ParseRowIdPipe } from '../common/row-id.pipe';
import { RequirePermission, TripAccessGuard } from '../permissions/trip-access.guard';
import { TourVisitUpdateDto } from './dto/tour-visit.dto';
import { TourVisitsService } from './tour-visits.service';
import {
BadRequestException,
Body,
Controller,
Get,
Headers,
Param,
ParseIntPipe,
Put,
UseGuards,
} from '@nestjs/common';
import { BadRequestException, Body, Controller, Get, Headers, Param, Put, UseGuards } from '@nestjs/common';
import { stationKeySchema, tourVisitListResponseSchema } from '@trek/shared';
/**
@@ -42,7 +33,7 @@ export class TourVisitsController {
@ResponseContract(tourVisitListResponseSchema)
async update(
@Param('tripId') tripId: string,
@Param('assignmentId', ParseIntPipe) assignmentId: number,
@Param('assignmentId', ParseRowIdPipe) assignmentId: number,
@Param('stationKey') stationKey: string,
@Body() body: TourVisitUpdateDto,
@Headers('x-socket-id') socketId?: string,
+33 -29
View File
@@ -2,6 +2,8 @@ import type { User } from '../../types';
import { CurrentUser } from '../auth-core/current-user.decorator';
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
import { ResponseContract } from '../common/response-contract';
import { toRowId } from '../common/row-id';
import { intParam, rowId } from '../common/row-id.pipe';
import {
VacayAddHolidayCalendarDto,
VacayAddYearDto,
@@ -112,11 +114,10 @@ export class VacayController {
@ResponseContract(vacayHolidayCalendarResponseSchema)
async updateHolidayCalendar(
@CurrentUser() user: User,
@Param('id') idParam: string,
@Param('id', rowId('Calendar not found')) id: number,
@Body() body: VacayUpdateHolidayCalendarDto,
@Headers('x-socket-id') socketId?: string,
) {
const id = Number.parseInt(idParam);
const planId = await this.vacay.getActivePlanId(user.id);
const calendar = await this.vacay.updateHolidayCalendar(id, planId, body, socketId);
if (!calendar) {
@@ -129,10 +130,9 @@ export class VacayController {
@ResponseContract(successResponseSchema)
async deleteHolidayCalendar(
@CurrentUser() user: User,
@Param('id') idParam: string,
@Param('id', rowId('Calendar not found')) id: number,
@Headers('x-socket-id') socketId?: string,
) {
const id = Number.parseInt(idParam);
const planId = await this.vacay.getActivePlanId(user.id);
if (!(await this.vacay.deleteHolidayCalendar(id, planId, socketId))) {
throw new HttpException({ error: 'Calendar not found' }, 404);
@@ -144,8 +144,9 @@ export class VacayController {
@ResponseContract(successResponseSchema)
async setColor(@CurrentUser() user: User, @Body() body: VacaySetColorDto, @Headers('x-socket-id') socketId?: string) {
const planId = await this.vacay.getActivePlanId(user.id);
const userId = body.target_user_id ? Number.parseInt(String(body.target_user_id)) : user.id;
if (!(await this.vacay.getPlanUsers(planId)).find((u) => u.id === userId)) {
// toRowId: a spelling it refuses names nobody, so it is no user of the plan.
const userId = body.target_user_id ? toRowId(body.target_user_id) : user.id;
if (userId === null || !(await this.vacay.getPlanUsers(planId)).find((u) => u.id === userId)) {
throw new HttpException({ error: 'User not in plan' }, 403);
}
await this.vacay.setUserColor(userId, planId, body.color, socketId);
@@ -156,11 +157,12 @@ export class VacayController {
@HttpCode(200)
@ResponseContract(successResponseSchema)
async invite(@CurrentUser() user: User, @Body() body: VacayInviteDto, @Headers('x-socket-id') socketId?: string) {
if (!body.user_id) {
const invitee = toRowId(body.user_id);
if (!invitee) {
throw new HttpException({ error: 'user_id required' }, 400);
}
const plan = await this.vacay.getActivePlan(user.id);
await this.vacay.sendInvite(plan.id, user.id, user.username, body.user_id as number, socketId);
await this.vacay.sendInvite(plan.id, user.id, user.username, invitee, socketId);
return { success: true };
}
@@ -197,7 +199,9 @@ export class VacayController {
@Headers('x-socket-id') socketId?: string,
) {
const plan = await this.vacay.getActivePlan(user.id);
await this.vacay.cancelInvite(plan.id, body.user_id as number, socketId);
// A user id toRowId refuses names nobody, so there is no invite to cancel.
const invitee = toRowId(body.user_id);
if (invitee !== null) await this.vacay.cancelInvite(plan.id, invitee, socketId);
return { success: true };
}
@@ -227,21 +231,21 @@ export class VacayController {
@HttpCode(200)
@ResponseContract(vacayYearsResponseSchema)
async addYear(@CurrentUser() user: User, @Body() body: VacayAddYearDto, @Headers('x-socket-id') socketId?: string) {
if (!body.year) {
const year = toRowId(body.year);
if (!year) {
throw new HttpException({ error: 'Year required' }, 400);
}
const planId = await this.vacay.getActivePlanId(user.id);
return { years: await this.vacay.addYear(planId, body.year as number, socketId) };
return { years: await this.vacay.addYear(planId, year, socketId) };
}
@Delete('years/:year')
@ResponseContract(vacayYearsResponseSchema)
async deleteYear(
@CurrentUser() user: User,
@Param('year') yearParam: string,
@Param('year', intParam('Invalid year')) year: number,
@Headers('x-socket-id') socketId?: string,
) {
const year = Number.parseInt(yearParam);
const planId = await this.vacay.getActivePlanId(user.id);
return { years: await this.vacay.deleteYear(planId, year, socketId) };
}
@@ -277,12 +281,13 @@ export class VacayController {
) {
const planId = await this.vacay.getActivePlanId(user.id);
let userId = user.id;
if (body.target_user_id && Number.parseInt(String(body.target_user_id)) !== user.id) {
const tid = Number.parseInt(String(body.target_user_id));
if (!(await this.vacay.getPlanUsers(planId)).find((u) => u.id === tid)) {
const tid = toRowId(body.target_user_id);
if (body.target_user_id && tid !== user.id) {
const member = (await this.vacay.getPlanUsers(planId)).find((u) => u.id === tid);
if (!member) {
throw new HttpException({ error: 'User not in plan' }, 403);
}
userId = tid;
userId = member.id;
}
const result = await this.vacay.toggleEntry(userId, planId, body.date, body.fraction, body.kind, socketId);
if (result.error === 'weekend_blocked') {
@@ -305,8 +310,7 @@ export class VacayController {
@Get('stats/:year')
@ResponseContract(vacayStatsResponseSchema)
async stats(@CurrentUser() user: User, @Param('year') yearParam: string) {
const year = Number.parseInt(yearParam);
async stats(@CurrentUser() user: User, @Param('year', intParam('Invalid year')) year: number) {
const planId = await this.vacay.getActivePlanId(user.id);
return { stats: await this.vacay.getStats(planId, year) };
}
@@ -315,14 +319,13 @@ export class VacayController {
@ResponseContract(successResponseSchema)
async updateStats(
@CurrentUser() user: User,
@Param('year') yearParam: string,
@Param('year', intParam('Invalid year')) year: number,
@Body() body: VacayUpdateStatsDto,
@Headers('x-socket-id') socketId?: string,
) {
const year = Number.parseInt(yearParam);
const planId = await this.vacay.getActivePlanId(user.id);
const userId = body.target_user_id ? Number.parseInt(String(body.target_user_id)) : user.id;
if (!(await this.vacay.getPlanUsers(planId)).find((u) => u.id === userId)) {
const userId = body.target_user_id ? toRowId(body.target_user_id) : user.id;
if (userId === null || !(await this.vacay.getPlanUsers(planId)).find((u) => u.id === userId)) {
throw new HttpException({ error: 'User not in plan' }, 403);
}
await this.vacay.updateStats(userId, planId, year, body.vacation_days as number, socketId);
@@ -339,10 +342,11 @@ export class VacayController {
@HttpCode(200)
@ResponseContract(successResponseSchema)
async share(@CurrentUser() user: User, @Body() body: VacayShareDto, @Headers('x-socket-id') socketId?: string) {
if (!body.user_id) {
const shareWith = toRowId(body.user_id);
if (!shareWith) {
throw new HttpException({ error: 'user_id required' }, 400);
}
await this.vacay.shareCalendar(user.id, user.username, Number.parseInt(String(body.user_id)), socketId);
await this.vacay.shareCalendar(user.id, user.username, shareWith, socketId);
return { success: true };
}
@@ -362,11 +366,11 @@ export class VacayController {
@ResponseContract(successResponseSchema)
async updateShare(
@CurrentUser() user: User,
@Param('id') idParam: string,
@Param('id', rowId('Share not found')) id: number,
@Body() body: VacayShareUpdateDto,
@Headers('x-socket-id') socketId?: string,
) {
if (!(await this.vacay.setShareHidden(Number.parseInt(idParam), user.id, body.hidden, socketId))) {
if (!(await this.vacay.setShareHidden(id, user.id, body.hidden, socketId))) {
throw new HttpException({ error: 'Share not found' }, 404);
}
return { success: true };
@@ -376,10 +380,10 @@ export class VacayController {
@ResponseContract(successResponseSchema)
async deleteShare(
@CurrentUser() user: User,
@Param('id') idParam: string,
@Param('id', rowId('Share not found')) id: number,
@Headers('x-socket-id') socketId?: string,
) {
if (!(await this.vacay.removeShare(Number.parseInt(idParam), user.id, socketId))) {
if (!(await this.vacay.removeShare(id, user.id, socketId))) {
throw new HttpException({ error: 'Share not found' }, 404);
}
return { success: true };
@@ -2,10 +2,11 @@ import type { User } from '../../types';
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 { TripAccessGuard } from '../permissions/trip-access.guard';
import { WalletPassService } from './wallet-pass.service';
import { walletLanguage } from './wallet-pass.words';
import { Controller, Get, Param, ParseIntPipe, Query, Res, UseGuards } from '@nestjs/common';
import { Controller, Get, Param, Query, Res, UseGuards } from '@nestjs/common';
import {
googleWalletAvailabilityResponseSchema,
googleWalletSaveResponseSchema,
@@ -32,8 +33,8 @@ export class WalletPassController {
@Get(':id/wallet-pass')
async pass(
@CurrentUser() user: User,
@Param('tripId', ParseIntPipe) tripId: number,
@Param('id', ParseIntPipe) id: number,
@Param('tripId', ParseRowIdPipe) tripId: number,
@Param('id', ParseRowIdPipe) id: number,
@Query('lang') lang: string | undefined,
@Res() res: Response,
): Promise<void> {
@@ -53,8 +54,8 @@ export class WalletPassController {
@ResponseContract(googleWalletSaveResponseSchema)
async google(
@CurrentUser() user: User,
@Param('tripId', ParseIntPipe) tripId: number,
@Param('id', ParseIntPipe) id: number,
@Param('tripId', ParseRowIdPipe) tripId: number,
@Param('id', ParseRowIdPipe) id: number,
@Query('lang') lang: string | undefined,
): Promise<GoogleWalletSaveResponse> {
return { saveUrl: await this.passes.googleSaveUrlFor(user.id, tripId, id, walletLanguage(lang)) };