QueenEvaluation-Modell (Volksstaerke, Sanftmut, Wabensitz, Schwarm- trieb, Brutbild, Honigertrag je Skala 1-5) als Sub-Ressource der Queens-API: GET/POST /queens/:id/evaluations. Vorgezogen vor Modul 27 (Statistik), da dessen Koeniginnen-Auswertungen auf diesen Daten aufbauen.
83 lines
2.2 KiB
TypeScript
83 lines
2.2 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
|
import { QueenStatus, 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 { CreateQueenDto } from './dto/create-queen.dto';
|
|
import { UpdateQueenDto } from './dto/update-queen.dto';
|
|
import { AssignColonyDto } from './dto/assign-colony.dto';
|
|
import { CreateQueenEvaluationDto } from './dto/create-queen-evaluation.dto';
|
|
import { QueensService } from './queens.service';
|
|
|
|
@ApiTags('queens')
|
|
@ApiBearerAuth()
|
|
@Controller('queens')
|
|
export class QueensController {
|
|
constructor(private readonly queensService: QueensService) {}
|
|
|
|
@Get()
|
|
findAll(@Query('status') status?: QueenStatus) {
|
|
return this.queensService.findAll({ status });
|
|
}
|
|
|
|
@Get(':id')
|
|
findOne(@Param('id') id: string) {
|
|
return this.queensService.findById(id);
|
|
}
|
|
|
|
@Get(':id/history')
|
|
getHistory(@Param('id') id: string) {
|
|
return this.queensService.getHistory(id);
|
|
}
|
|
|
|
@Roles(Role.ADMIN, Role.BEEKEEPER)
|
|
@Post()
|
|
create(@Body() dto: CreateQueenDto, @CurrentUser() actor: AuthenticatedUser) {
|
|
return this.queensService.create(dto, actor.id);
|
|
}
|
|
|
|
@Roles(Role.ADMIN, Role.BEEKEEPER)
|
|
@Patch(':id')
|
|
update(
|
|
@Param('id') id: string,
|
|
@Body() dto: UpdateQueenDto,
|
|
@CurrentUser() actor: AuthenticatedUser,
|
|
) {
|
|
return this.queensService.update(id, dto, actor.id);
|
|
}
|
|
|
|
@Roles(Role.ADMIN, Role.BEEKEEPER)
|
|
@Post(':id/assign-colony')
|
|
assignColony(
|
|
@Param('id') id: string,
|
|
@Body() dto: AssignColonyDto,
|
|
@CurrentUser() actor: AuthenticatedUser,
|
|
) {
|
|
return this.queensService.assignColony(id, dto, actor.id);
|
|
}
|
|
|
|
@Get(':id/evaluations')
|
|
getEvaluations(@Param('id') id: string) {
|
|
return this.queensService.getEvaluations(id);
|
|
}
|
|
|
|
@Roles(Role.ADMIN, Role.BEEKEEPER)
|
|
@Post(':id/evaluations')
|
|
addEvaluation(
|
|
@Param('id') id: string,
|
|
@Body() dto: CreateQueenEvaluationDto,
|
|
@CurrentUser() actor: AuthenticatedUser,
|
|
) {
|
|
return this.queensService.addEvaluation(id, dto, actor.id);
|
|
}
|
|
}
|