feat(transactions): add transactions.controller

This commit is contained in:
admin-valentin 2026-07-31 10:44:58 +00:00
parent a80bd5080b
commit 78d60c69ab

View file

@ -0,0 +1,48 @@
import { BadRequestException, Body, Controller, Delete, Get, 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';
import { TransactionsService } from './transactions.service';
@Controller('transactions')
export class TransactionsController {
constructor(private readonly transactionsService: TransactionsService) {}
@Get()
list(
@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');
}
}
return this.transactionsService.list(session, organizationId);
}
@Get(':id')
getById(@CurrentSession() session: AuthenticatedSession, @Param('id', ParseUUIDPipe) id: string) {
return this.transactionsService.getById(session, id);
}
@Post()
create(@CurrentSession() session: AuthenticatedSession, @Body() dto: CreateTransactionDto) {
return this.transactionsService.create(session, dto);
}
@Patch(':id')
update(
@CurrentSession() session: AuthenticatedSession,
@Param('id', ParseUUIDPipe) id: string,
@Body() dto: UpdateTransactionDto,
) {
return this.transactionsService.update(session, id, dto);
}
@Delete(':id')
softDelete(@CurrentSession() session: AuthenticatedSession, @Param('id', ParseUUIDPipe) id: string) {
return this.transactionsService.softDelete(session, id);
}
}