mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-01 00:43:15 +00:00
fix(api): read body, query and handler-parsed ids with toRowId instead of Number() and parseInt
The services and controllers that took an id from a request with Number(), parseInt() or not at all now use toRowId. That covers admin users, notifications (and their limit and offset), trip members and guests, day notes, assignments, memories (photo owner, album link, body photo_id), photos, mail-ingest, the assistant id parsers, dawarich, registration invites, the plugin contribution routes and the collab reply. The accommodation update body is open, so AccommodationsService reads the place and day refs of every stay write with toRowId and answers a refused one with the create schema's 400. AdminService.deleteUser checked the caller with parseInt and deleted with Number(), so an admin could delete their own account by spelling its id in hex; both now use one parse. The OAuth session revoke called Number(id) first and so revoked session 5 for '0x5'; the service now reads the id as sent.
This commit is contained in:
@@ -7,6 +7,7 @@ import { CurrentUser } from '../auth-core/current-user.decorator';
|
||||
import { JwtAuthGuard } from '../auth-core/jwt-auth.guard';
|
||||
import { ManagedForbidden } from '../common/managed';
|
||||
import { ResponseContract } from '../common/response-contract';
|
||||
import { toRowId } from '../common/row-id';
|
||||
import { onClientGone, openSseStream } from '../common/sse-stream';
|
||||
import { RequirePermission, TripAccessGuard } from '../permissions/trip-access.guard';
|
||||
import { AssistantFoundPlacesService } from './assistant-found-places.service';
|
||||
@@ -36,10 +37,10 @@ import {
|
||||
|
||||
import type { Response } from 'express';
|
||||
|
||||
/** A route id: a positive integer, or the 404 an unknown one gets. */
|
||||
/** A route id: a positive integer as toRowId reads it, or the 404 an unknown one gets. */
|
||||
export function idParam(value: string): number {
|
||||
const id = Number(value);
|
||||
if (!Number.isInteger(id) || id <= 0) throw aiRefusal('not_found', 'Conversation not found');
|
||||
const id = toRowId(value);
|
||||
if (id === null || id <= 0) throw aiRefusal('not_found', 'Conversation not found');
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user