feat(transactions): add transactions.controller
This commit is contained in:
parent
a80bd5080b
commit
78d60c69ab
1 changed files with 48 additions and 0 deletions
48
src/transactions/transactions.controller.ts
Normal file
48
src/transactions/transactions.controller.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue