Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 1x 1x 1x 1x 2x 2x 2x 2x 2x 1x | import { Controller, Get, Inject, Param, Post, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { Company, type Currency } from '@amalia/core/models';
import { UuidPipe } from '@amalia/kernel/api';
import {
AmaliaAuthGuard,
CheckPolicies,
CurrentUserCompany,
PoliciesGuard,
ZodBodyValidationPipe,
ZodQueryValidationPipe,
} from '@amalia/kernel/auth/core';
import { canModifyCompanyRates, canViewCompanyRates } from '@amalia/kernel/auth/shared';
import { type CreateCurrencyRequest, type SearchCurrencyRequest } from '@amalia/tenants/companies/currency-rates/types';
import { CurrenciesService } from './currencies.service';
import { createCurrencyRequestRequest } from './dto/create-currency.dto';
import { searchCurrencyRequestSchema } from './dto/search-currency.dto';
@UseGuards(AmaliaAuthGuard, PoliciesGuard)
@ApiBearerAuth()
@ApiTags('currencies')
@Controller('currencies')
export class CurrenciesController {
public constructor(
@Inject(CurrenciesService)
private readonly currencyService: CurrenciesService,
) {}
@Get(':id')
@CheckPolicies((ability) => canViewCompanyRates(ability))
public async findOne(
@Param('id', new UuidPipe()) id: string,
@CurrentUserCompany() company: Company,
): Promise<Currency> {
return this.currencyService.findOne(company, id);
}
@Get()
@CheckPolicies((ability) => canViewCompanyRates(ability))
public async findAll(
@CurrentUserCompany() company: Company,
@ZodQueryValidationPipe({ schema: searchCurrencyRequestSchema }) query: SearchCurrencyRequest,
): Promise<Currency[]> {
return this.currencyService.findAll(company, query.year, query.date);
}
@Post()
@CheckPolicies((ability) => canModifyCompanyRates(ability))
public async create(
@CurrentUserCompany() company: Company,
@ZodBodyValidationPipe({ schema: createCurrencyRequestRequest }) currency: CreateCurrencyRequest,
): Promise<void> {
return this.currencyService.createOrUpdate(company, currency);
}
}
|