55 lines
1.6 KiB
TypeScript
55 lines
1.6 KiB
TypeScript
import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseGuards } from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
|
import { EquipmentService } from './equipment.service';
|
|
import { CreateEquipmentDto } from './dto/create-equipment.dto';
|
|
import { UpdateEquipmentDto } from './dto/update-equipment.dto';
|
|
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
|
|
|
const parseJson = <T>(value?: string): T | undefined => {
|
|
if (!value) return undefined;
|
|
try { return JSON.parse(value) as T; } catch { return undefined; }
|
|
};
|
|
|
|
@ApiTags('equipment')
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Controller('equipment')
|
|
export class EquipmentController {
|
|
constructor(private readonly equipmentService: EquipmentService) {}
|
|
|
|
@Get()
|
|
findAll(
|
|
@Query('skip') skip?: string,
|
|
@Query('take') take?: string,
|
|
@Query('orderBy') orderBy?: string,
|
|
@Query('where') where?: string,
|
|
) {
|
|
return this.equipmentService.findAll({
|
|
skip: skip ? Number(skip) : 0,
|
|
take: take ? Number(take) : 25,
|
|
orderBy: parseJson(orderBy),
|
|
where: parseJson(where),
|
|
});
|
|
}
|
|
|
|
@Get(':id')
|
|
findOne(@Param('id') id: string) {
|
|
return this.equipmentService.findOne({ id });
|
|
}
|
|
|
|
@Post()
|
|
create(@Body() dto: CreateEquipmentDto) {
|
|
return this.equipmentService.create(dto);
|
|
}
|
|
|
|
@Patch(':id')
|
|
update(@Param('id') id: string, @Body() dto: UpdateEquipmentDto) {
|
|
return this.equipmentService.update({ where: { id }, data: dto });
|
|
}
|
|
|
|
@Delete(':id')
|
|
remove(@Param('id') id: string) {
|
|
return this.equipmentService.remove({ id });
|
|
}
|
|
}
|