feat: add generated code
This commit is contained in:
73
backend/src/equipment/dto/create-equipment.dto.ts
Normal file
73
backend/src/equipment/dto/create-equipment.dto.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsString, IsNotEmpty, IsEnum, IsISO8601, IsOptional, IsNumber } from 'class-validator';
|
||||
import { EquipmentType, EnumPeriodicityTO, EquipmentStatus } from '@prisma/client';
|
||||
|
||||
export class CreateEquipmentDto {
|
||||
@ApiProperty({ description: 'Название оборудования' })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
name: string;
|
||||
|
||||
@ApiProperty({ description: 'Заводской (серийный) номер' })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
serialNumber: string;
|
||||
|
||||
@ApiProperty({ description: 'Инвентарный номер' })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
inventoryNumber: string;
|
||||
|
||||
@ApiProperty({ enum: EquipmentType, enumName: 'EquipmentType', description: 'Тип оборудования' })
|
||||
@IsEnum(EquipmentType)
|
||||
equipmentType: EquipmentType;
|
||||
|
||||
@ApiProperty({ required: false, description: 'Дата проверки' })
|
||||
@IsISO8601()
|
||||
@IsOptional()
|
||||
@Type(() => Date)
|
||||
dateOfInspection?: Date;
|
||||
|
||||
@ApiProperty({ enum: EnumPeriodicityTO, enumName: 'EnumPeriodicityTO', description: 'Периодичность ТО' })
|
||||
@IsEnum(EnumPeriodicityTO)
|
||||
periodicityTO: EnumPeriodicityTO;
|
||||
|
||||
@ApiProperty({ required: false, description: 'Место эксплуатации / скважина / куст' })
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
location?: string;
|
||||
|
||||
@ApiProperty({ enum: EquipmentStatus, enumName: 'EquipmentStatus', description: 'Текущий статус' })
|
||||
@IsEnum(EquipmentStatus)
|
||||
status: EquipmentStatus;
|
||||
|
||||
@ApiProperty({ required: false, description: 'Год изготовления' })
|
||||
@IsISO8601()
|
||||
@IsOptional()
|
||||
@Type(() => Date)
|
||||
commissionedAt?: Date;
|
||||
|
||||
@ApiProperty({ required: false, description: 'Общая наработка, моточасов' })
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
totalEngineHours?: number;
|
||||
|
||||
@ApiProperty({ required: false, description: 'Наработка с последнего ремонта, моточасов' })
|
||||
@IsNumber()
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
engineHoursSinceLastRepair?: number;
|
||||
|
||||
@ApiProperty({ required: false, description: 'Дата последнего ремонта' })
|
||||
@IsISO8601()
|
||||
@IsOptional()
|
||||
@Type(() => Date)
|
||||
lastRepairAt?: Date;
|
||||
|
||||
@ApiProperty({ required: false, description: 'Примечания' })
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
notes?: string;
|
||||
}
|
||||
4
backend/src/equipment/dto/update-equipment.dto.ts
Normal file
4
backend/src/equipment/dto/update-equipment.dto.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateEquipmentDto } from './create-equipment.dto';
|
||||
|
||||
export class UpdateEquipmentDto extends PartialType(CreateEquipmentDto) {}
|
||||
58
backend/src/equipment/equipment.controller.ts
Normal file
58
backend/src/equipment/equipment.controller.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseGuards } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags, ApiQuery } 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()
|
||||
@ApiQuery({ name: 'skip', required: false, type: String })
|
||||
@ApiQuery({ name: 'take', required: false, type: String })
|
||||
@ApiQuery({ name: 'orderBy', required: false, type: String })
|
||||
@ApiQuery({ name: 'where', required: false, type: String })
|
||||
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 });
|
||||
}
|
||||
}
|
||||
10
backend/src/equipment/equipment.module.ts
Normal file
10
backend/src/equipment/equipment.module.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { EquipmentService } from './equipment.service';
|
||||
import { EquipmentController } from './equipment.controller';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@Module({
|
||||
controllers: [EquipmentController],
|
||||
providers: [EquipmentService, PrismaService],
|
||||
})
|
||||
export class EquipmentModule {}
|
||||
41
backend/src/equipment/equipment.service.ts
Normal file
41
backend/src/equipment/equipment.service.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { Equipment, Prisma } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class EquipmentService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async findAll(params: {
|
||||
skip?: number;
|
||||
take?: number;
|
||||
where?: Prisma.EquipmentWhereInput;
|
||||
orderBy?: Prisma.EquipmentOrderByWithRelationInput;
|
||||
}): Promise<{ data: Equipment[]; total: number }> {
|
||||
const { skip, take, where, orderBy } = params;
|
||||
const [data, total] = await this.prisma.$transaction([
|
||||
this.prisma.equipment.findMany({ skip, take, where, orderBy }),
|
||||
this.prisma.equipment.count({ where }),
|
||||
]);
|
||||
return { data, total };
|
||||
}
|
||||
|
||||
async findOne(where: Prisma.EquipmentWhereUniqueInput): Promise<Equipment | null> {
|
||||
return this.prisma.equipment.findUnique({ where });
|
||||
}
|
||||
|
||||
async create(data: Prisma.EquipmentCreateInput): Promise<Equipment> {
|
||||
return this.prisma.equipment.create({ data });
|
||||
}
|
||||
|
||||
async update(params: {
|
||||
where: Prisma.EquipmentWhereUniqueInput;
|
||||
data: Prisma.EquipmentUpdateInput;
|
||||
}): Promise<Equipment> {
|
||||
return this.prisma.equipment.update(params);
|
||||
}
|
||||
|
||||
async remove(where: Prisma.EquipmentWhereUniqueInput): Promise<Equipment> {
|
||||
return this.prisma.equipment.delete({ where });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user