import { Body, Controller, Get, Param, Patch, Post, Query, } from '@nestjs/common'; import { ApiBearerAuth, ApiTags } from '@nestjs/swagger'; import { ApiaryStatus, LegacyRole as Role } from '../../generated/prisma'; import { Roles } from '../auth/decorators/roles.decorator'; import { CurrentUser } from '../auth/decorators/current-user.decorator'; import type { AuthenticatedUser } from '../auth/types/authenticated-user'; import { CreateApiaryDto } from './dto/create-apiary.dto'; import { UpdateApiaryDto } from './dto/update-apiary.dto'; import { ApiariesService } from './apiaries.service'; @ApiTags('apiaries') @ApiBearerAuth() @Controller('apiaries') export class ApiariesController { constructor(private readonly apiariesService: ApiariesService) {} @Get() findAll( @Query('status') status?: ApiaryStatus, @Query('location') location?: string, ) { return this.apiariesService.findAll({ status, location }); } @Get(':id') findOne(@Param('id') id: string) { return this.apiariesService.findById(id); } @Roles(Role.ADMIN, Role.BEEKEEPER) @Post() create( @Body() dto: CreateApiaryDto, @CurrentUser() actor: AuthenticatedUser, ) { return this.apiariesService.create(dto, actor.id); } @Roles(Role.ADMIN, Role.BEEKEEPER) @Patch(':id') update( @Param('id') id: string, @Body() dto: UpdateApiaryDto, @CurrentUser() actor: AuthenticatedUser, ) { return this.apiariesService.update(id, dto, actor.id); } @Roles(Role.ADMIN, Role.BEEKEEPER) @Post(':id/deactivate') deactivate(@Param('id') id: string, @CurrentUser() actor: AuthenticatedUser) { return this.apiariesService.deactivate(id, actor.id); } @Roles(Role.ADMIN, Role.BEEKEEPER) @Post(':id/reactivate') reactivate(@Param('id') id: string, @CurrentUser() actor: AuthenticatedUser) { return this.apiariesService.reactivate(id, actor.id); } }