90 lines
2.6 KiB
TypeScript
90 lines
2.6 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
Patch,
|
|
Post,
|
|
Query,
|
|
} from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
|
import { HoneyBatchStatus } from '../../generated/prisma';
|
|
import { RequirePermission } from '../auth/decorators/require-permission.decorator';
|
|
import { CurrentUser } from '../auth/decorators/current-user.decorator';
|
|
import type { AuthenticatedUser } from '../auth/types/authenticated-user';
|
|
import { CreateHoneyBatchDto } from './dto/create-honey-batch.dto';
|
|
import { UpdateHoneyBatchDto } from './dto/update-honey-batch.dto';
|
|
import { CreateHoneyMeasurementDto } from './dto/create-honey-measurement.dto';
|
|
import { RelocateHoneyBatchDto } from './dto/relocate-honey-batch.dto';
|
|
import { HoneyBatchesService } from './honey-batches.service';
|
|
|
|
@ApiTags('honey-batches')
|
|
@ApiBearerAuth()
|
|
@Controller('honey-batches')
|
|
export class HoneyBatchesController {
|
|
constructor(private readonly honeyBatchesService: HoneyBatchesService) {}
|
|
|
|
@RequirePermission('honey-batches:read')
|
|
@Get()
|
|
findAll(@Query('status') status?: HoneyBatchStatus) {
|
|
return this.honeyBatchesService.findAll({ status });
|
|
}
|
|
|
|
@RequirePermission('honey-batches:read')
|
|
@Get(':id')
|
|
findOne(@Param('id') id: string) {
|
|
return this.honeyBatchesService.findById(id);
|
|
}
|
|
|
|
@RequirePermission('honey-batches:read')
|
|
@Get(':id/traceability')
|
|
traceability(@Param('id') id: string) {
|
|
return this.honeyBatchesService.traceability(id);
|
|
}
|
|
|
|
@RequirePermission('honey-batches:read')
|
|
@Get(':id/relocations')
|
|
findRelocations(@Param('id') id: string) {
|
|
return this.honeyBatchesService.findRelocations(id);
|
|
}
|
|
|
|
@RequirePermission('honey-batches:relocate')
|
|
@Post(':id/relocate')
|
|
relocate(
|
|
@Param('id') id: string,
|
|
@Body() dto: RelocateHoneyBatchDto,
|
|
@CurrentUser() actor: AuthenticatedUser,
|
|
) {
|
|
return this.honeyBatchesService.relocate(id, dto, actor.id);
|
|
}
|
|
|
|
@RequirePermission('honey-batches:create')
|
|
@Post()
|
|
create(
|
|
@Body() dto: CreateHoneyBatchDto,
|
|
@CurrentUser() actor: AuthenticatedUser,
|
|
) {
|
|
return this.honeyBatchesService.create(dto, actor.id);
|
|
}
|
|
|
|
@RequirePermission('honey-batches:update')
|
|
@Patch(':id')
|
|
update(
|
|
@Param('id') id: string,
|
|
@Body() dto: UpdateHoneyBatchDto,
|
|
@CurrentUser() actor: AuthenticatedUser,
|
|
) {
|
|
return this.honeyBatchesService.update(id, dto, actor.id);
|
|
}
|
|
|
|
@RequirePermission('honey-batches:measure')
|
|
@Post(':id/measurements')
|
|
addMeasurement(
|
|
@Param('id') id: string,
|
|
@Body() dto: CreateHoneyMeasurementDto,
|
|
@CurrentUser() actor: AuthenticatedUser,
|
|
) {
|
|
return this.honeyBatchesService.addMeasurement(id, dto, actor.id);
|
|
}
|
|
}
|