feat: add generated code
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseGuards } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags, ApiParam, ApiQuery } from '@nestjs/swagger';
|
||||
import { ChangeEquipmentStatusService } from './change-equipment-status.service';
|
||||
import { CreateChangeEquipmentStatusDto } from './dto/create-change-equipment-status.dto';
|
||||
import { UpdateChangeEquipmentStatusDto } from './dto/update-change-equipment-status.dto';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { EquipmentStatus } from '@prisma/client';
|
||||
|
||||
const parseJson = <T>(value?: string): T | undefined => {
|
||||
if (!value) return undefined;
|
||||
try { return JSON.parse(value) as T; } catch { return undefined; }
|
||||
};
|
||||
|
||||
@ApiTags('change-equipment-status')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('change-equipment-status')
|
||||
export class ChangeEquipmentStatusController {
|
||||
constructor(private readonly changeEquipmentStatusService: ChangeEquipmentStatusService) {}
|
||||
|
||||
@Get()
|
||||
findAll(
|
||||
@Query('skip') skip?: string,
|
||||
@Query('take') take?: string,
|
||||
@Query('orderBy') orderBy?: string,
|
||||
@Query('where') where?: string,
|
||||
) {
|
||||
return this.changeEquipmentStatusService.findAll({
|
||||
skip: skip ? Number(skip) : 0,
|
||||
take: take ? Number(take) : 25,
|
||||
orderBy: parseJson(orderBy),
|
||||
where: parseJson(where),
|
||||
});
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiParam({ name: 'id', type: String, description: 'Идентификатор документа изменения статуса' })
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.changeEquipmentStatusService.findOne({ id });
|
||||
}
|
||||
|
||||
// Special endpoint for composite key lookup (equipmentId + newStatus)
|
||||
@Get('by-composite/:equipmentId/:newStatus')
|
||||
@ApiParam({ name: 'equipmentId', type: String, description: 'Оборудование' })
|
||||
@ApiParam({ name: 'newStatus', enum: EquipmentStatus, enumName: 'EquipmentStatus', description: 'Новый статус' })
|
||||
findByCompositeKey(
|
||||
@Param('equipmentId') equipmentId: string,
|
||||
@Param('newStatus') newStatus: EquipmentStatus,
|
||||
) {
|
||||
return this.changeEquipmentStatusService.findByCompositeKey(equipmentId, newStatus);
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() dto: CreateChangeEquipmentStatusDto) {
|
||||
return this.changeEquipmentStatusService.create(dto);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
@ApiParam({ name: 'id', type: String, description: 'Идентификатор документа изменения статуса' })
|
||||
update(@Param('id') id: string, @Body() dto: UpdateChangeEquipmentStatusDto) {
|
||||
return this.changeEquipmentStatusService.update({ where: { id }, data: dto });
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiParam({ name: 'id', type: String, description: 'Идентификатор документа изменения статуса' })
|
||||
remove(@Param('id') id: string) {
|
||||
return this.changeEquipmentStatusService.remove({ id });
|
||||
}
|
||||
|
||||
// Special endpoint for composite key deletion (equipmentId + newStatus)
|
||||
@Delete('by-composite/:equipmentId/:newStatus')
|
||||
@ApiParam({ name: 'equipmentId', type: String, description: 'Оборудование' })
|
||||
@ApiParam({ name: 'newStatus', enum: EquipmentStatus, enumName: 'EquipmentStatus', description: 'Новый статус' })
|
||||
removeByCompositeKey(
|
||||
@Param('equipmentId') equipmentId: string,
|
||||
@Param('newStatus') newStatus: EquipmentStatus,
|
||||
) {
|
||||
return this.changeEquipmentStatusService.findByCompositeKey(equipmentId, newStatus).then(doc => {
|
||||
if (doc) {
|
||||
return this.changeEquipmentStatusService.remove({ id: doc.id });
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user