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 | 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 1x 1x 2x 2x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 1x 1x | import { Body, Controller, Delete, Get, Param, Post, UseGuards } from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { Company } from '@amalia/core/models';
import { UuidPipe } from '@amalia/kernel/api';
import {
AmaliaAuthGuard,
CheckPolicies,
CurrentAuthenticatedContext,
CurrentUserCompany,
PoliciesGuard,
} from '@amalia/kernel/auth/core';
import { canCreateApiKeys, canDeleteApiKeys, canViewApiKeys } from '@amalia/kernel/auth/shared';
import { type AuthenticatedContext } from '@amalia/kernel/auth/types';
import { CompanyApiKeyDto } from './companyApiKey.dto';
import { CompanyApiKeyService } from './companyApiKey.service';
@UseGuards(AmaliaAuthGuard, PoliciesGuard)
@ApiBearerAuth()
@ApiTags('company')
@Controller('companies/api-keys')
export class CompanyApiKeyController {
public constructor(private readonly companyApiKeyService: CompanyApiKeyService) {}
@Get('/')
@CheckPolicies((ability) => canViewApiKeys(ability))
public async list(@CurrentUserCompany() company: Company) {
return this.companyApiKeyService.list(company.id);
}
@Post('/')
@CheckPolicies((ability) => canCreateApiKeys(ability))
public async create(
@CurrentUserCompany() company: Company,
@Body() createApiKeyDto: CompanyApiKeyDto,
@CurrentAuthenticatedContext() authenticatedContext: AuthenticatedContext,
) {
return this.companyApiKeyService.create(company, authenticatedContext, createApiKeyDto);
}
@Delete('/:id')
@CheckPolicies((ability) => canDeleteApiKeys(ability))
public async delete(
@CurrentUserCompany() company: Company,
@Param('id', new UuidPipe()) id: string,
@CurrentAuthenticatedContext() authenticatedContext: AuthenticatedContext,
) {
await this.companyApiKeyService.delete(company, authenticatedContext, id);
}
}
|