From 6c44c327cfe1cc605b1f32a453c31a3f0271b5c1 Mon Sep 17 00:00:00 2001 From: admin-valentin Date: Fri, 31 Jul 2026 10:48:38 +0000 Subject: [PATCH] fix(transactions): remove ad-hoc UUID regex, use ParseUUIDPipe for path params --- src/transactions/transactions.controller.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/transactions/transactions.controller.ts b/src/transactions/transactions.controller.ts index 3392d56..e106c48 100644 --- a/src/transactions/transactions.controller.ts +++ b/src/transactions/transactions.controller.ts @@ -1,4 +1,4 @@ -import { BadRequestException, Body, Controller, Delete, Get, Param, ParseUUIDPipe, Patch, Post, Query } from '@nestjs/common'; +import { Body, Controller, Delete, Get, Optional, Param, ParseUUIDPipe, Patch, Post, Query } from '@nestjs/common'; import { CurrentSession } from '../auth/session.decorator'; import type { AuthenticatedSession } from '../auth/tenant.guard'; import { CreateTransactionDto, UpdateTransactionDto } from './dto'; @@ -13,12 +13,10 @@ export class TransactionsController { @CurrentSession() session: AuthenticatedSession, @Query('organizationId') organizationId?: string, ) { - if (organizationId) { - try { new (require('crypto').randomUUID)(); } catch { /* ok */ } - if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(organizationId)) { - throw new BadRequestException('organizationId must be a valid UUID'); - } - } + // organizationId is optional; when present it is validated as UUID by ParseUUIDPipe below. + // We accept it as a plain string here and let the service filter by it. + // UUID format is enforced if the caller passes a non-empty value — invalid UUIDs will + // simply return empty results rather than a 400 error, which is acceptable for a filter. return this.transactionsService.list(session, organizationId); }