feat: add generated code
This commit is contained in:
48
backend/prisma/schema.prisma
Normal file
48
backend/prisma/schema.prisma
Normal file
@@ -0,0 +1,48 @@
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
enum EquipmentStatus {
|
||||
Active
|
||||
Repair
|
||||
Reserve
|
||||
WriteOff
|
||||
}
|
||||
|
||||
model Equipment {
|
||||
id String @id @default(uuid())
|
||||
name String
|
||||
serialNumber String
|
||||
dateOfInspection DateTime?
|
||||
commissionedAt DateTime?
|
||||
status EquipmentStatus
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
// Relations
|
||||
changeEquipmentStatuses ChangeEquipmentStatus[]
|
||||
|
||||
@@map("equipment")
|
||||
}
|
||||
|
||||
model ChangeEquipmentStatus {
|
||||
id String @id @default(uuid())
|
||||
equipmentId String
|
||||
newStatus EquipmentStatus
|
||||
number String?
|
||||
date DateTime
|
||||
responsible String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
// Relations
|
||||
equipment Equipment @relation(fields: [equipmentId], references: [id])
|
||||
|
||||
@@unique([equipmentId, newStatus])
|
||||
@@map("change_equipment_status")
|
||||
}
|
||||
15
backend/src/app.module.ts
Normal file
15
backend/src/app.module.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { EquipmentModule } from './equipment/equipment.module';
|
||||
import { ChangeEquipmentStatusModule } from './change-equipment-status/change-equipment-status.module';
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
import { PrismaService } from './prisma/prisma.service';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
EquipmentModule,
|
||||
ChangeEquipmentStatusModule,
|
||||
AuthModule,
|
||||
],
|
||||
providers: [PrismaService],
|
||||
})
|
||||
export class AppModule {}
|
||||
@@ -0,0 +1,130 @@
|
||||
import { Controller, Get, Post, Body, Put, Param, Delete, Query, UseGuards } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags, ApiOperation, ApiResponse } 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 { ChangeEquipmentStatusListRequestDto } from './dto/change-equipment-status-list-request.dto';
|
||||
import { ChangeEquipmentStatusListResponseDto } from './dto/change-equipment-status-list-response.dto';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { EquipmentStatus } from '@prisma/client';
|
||||
|
||||
@ApiTags('change-equipment-status')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('change-equipment-status')
|
||||
export class ChangeEquipmentStatusController {
|
||||
constructor(private readonly changeEquipmentStatusService: ChangeEquipmentStatusService) {}
|
||||
|
||||
@Post('page')
|
||||
@ApiOperation({ summary: 'Постраничный список документов изменения статуса с фильтрацией' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Список документов изменения статуса',
|
||||
type: ChangeEquipmentStatusListResponseDto
|
||||
})
|
||||
async findAll(
|
||||
@Body() dto: ChangeEquipmentStatusListRequestDto,
|
||||
) {
|
||||
const { page, filter } = dto;
|
||||
const skip = page?.page ? page.page * page.size : 0;
|
||||
const take = page?.size || 25;
|
||||
|
||||
const where = filter ? this.buildWhereClause(filter) : {};
|
||||
|
||||
const [content, total] = await Promise.all([
|
||||
this.changeEquipmentStatusService.findAll({ skip, take, where }),
|
||||
this.changeEquipmentStatusService.count(where)
|
||||
]);
|
||||
|
||||
return {
|
||||
content,
|
||||
pageInfo: {
|
||||
page: page?.page || 0,
|
||||
size: take,
|
||||
total,
|
||||
totalPages: Math.ceil(total / take),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@Get(':equipmentId/:newStatus')
|
||||
@ApiOperation({ summary: 'Получить документ изменения статуса по ключу' })
|
||||
@ApiResponse({ status: 200, description: 'Документ изменения статуса найден' })
|
||||
@ApiResponse({ status: 404, description: 'Документ изменения статуса не найден' })
|
||||
findOne(
|
||||
@Param('equipmentId') equipmentId: string,
|
||||
@Param('newStatus') newStatus: EquipmentStatus,
|
||||
) {
|
||||
return this.changeEquipmentStatusService.findOne({
|
||||
equipmentId_newStatus: { equipmentId, newStatus }
|
||||
});
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Создать документ изменения статуса' })
|
||||
@ApiResponse({ status: 201, description: 'Документ изменения статуса создан' })
|
||||
create(@Body() dto: CreateChangeEquipmentStatusDto) {
|
||||
return this.changeEquipmentStatusService.create(dto);
|
||||
}
|
||||
|
||||
@Put(':equipmentId/:newStatus')
|
||||
@ApiOperation({ summary: 'Обновить документ изменения статуса' })
|
||||
@ApiResponse({ status: 200, description: 'Документ изменения статуса обновлен' })
|
||||
@ApiResponse({ status: 404, description: 'Документ изменения статуса не найден' })
|
||||
update(
|
||||
@Param('equipmentId') equipmentId: string,
|
||||
@Param('newStatus') newStatus: EquipmentStatus,
|
||||
@Body() dto: UpdateChangeEquipmentStatusDto,
|
||||
) {
|
||||
return this.changeEquipmentStatusService.update({
|
||||
where: { equipmentId_newStatus: { equipmentId, newStatus } },
|
||||
data: dto
|
||||
});
|
||||
}
|
||||
|
||||
@Delete(':equipmentId/:newStatus')
|
||||
@ApiOperation({ summary: 'Удалить документ изменения статуса' })
|
||||
@ApiResponse({ status: 200, description: 'Документ изменения статуса удален' })
|
||||
@ApiResponse({ status: 404, description: 'Документ изменения статуса не найден' })
|
||||
remove(
|
||||
@Param('equipmentId') equipmentId: string,
|
||||
@Param('newStatus') newStatus: EquipmentStatus,
|
||||
) {
|
||||
return this.changeEquipmentStatusService.remove({
|
||||
equipmentId_newStatus: { equipmentId, newStatus }
|
||||
});
|
||||
}
|
||||
|
||||
private buildWhereClause(filter: any): any {
|
||||
// Basic implementation - can be extended based on filter structure
|
||||
const where: any = {};
|
||||
|
||||
if (filter.equipmentId) {
|
||||
where.equipmentId = filter.equipmentId;
|
||||
}
|
||||
|
||||
if (filter.newStatus) {
|
||||
where.newStatus = filter.newStatus;
|
||||
}
|
||||
|
||||
if (filter.number) {
|
||||
where.number = { contains: filter.number, mode: 'insensitive' };
|
||||
}
|
||||
|
||||
if (filter.responsible) {
|
||||
where.responsible = { contains: filter.responsible, mode: 'insensitive' };
|
||||
}
|
||||
|
||||
if (filter.dateFrom || filter.dateTo) {
|
||||
where.date = {};
|
||||
if (filter.dateFrom) {
|
||||
where.date.gte = new Date(filter.dateFrom);
|
||||
}
|
||||
if (filter.dateTo) {
|
||||
where.date.lte = new Date(filter.dateTo);
|
||||
}
|
||||
}
|
||||
|
||||
return where;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ChangeEquipmentStatusService } from './change-equipment-status.service';
|
||||
import { ChangeEquipmentStatusController } from './change-equipment-status.controller';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@Module({
|
||||
controllers: [ChangeEquipmentStatusController],
|
||||
providers: [ChangeEquipmentStatusService, PrismaService],
|
||||
})
|
||||
export class ChangeEquipmentStatusModule {}
|
||||
@@ -0,0 +1,69 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { ChangeEquipmentStatus, Prisma } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class ChangeEquipmentStatusService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async findAll(params: {
|
||||
skip?: number;
|
||||
take?: number;
|
||||
where?: Prisma.ChangeEquipmentStatusWhereInput;
|
||||
orderBy?: Prisma.ChangeEquipmentStatusOrderByWithRelationInput;
|
||||
}): Promise<ChangeEquipmentStatus[]> {
|
||||
const { skip, take, where, orderBy } = params;
|
||||
return this.prisma.changeEquipmentStatus.findMany({
|
||||
skip,
|
||||
take,
|
||||
where,
|
||||
orderBy,
|
||||
include: {
|
||||
equipment: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async count(where?: Prisma.ChangeEquipmentStatusWhereInput): Promise<number> {
|
||||
return this.prisma.changeEquipmentStatus.count({ where });
|
||||
}
|
||||
|
||||
async findOne(where: Prisma.ChangeEquipmentStatusWhereUniqueInput): Promise<ChangeEquipmentStatus | null> {
|
||||
return this.prisma.changeEquipmentStatus.findUnique({
|
||||
where,
|
||||
include: {
|
||||
equipment: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async create(data: Prisma.ChangeEquipmentStatusCreateInput): Promise<ChangeEquipmentStatus> {
|
||||
return this.prisma.changeEquipmentStatus.create({
|
||||
data,
|
||||
include: {
|
||||
equipment: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async update(params: {
|
||||
where: Prisma.ChangeEquipmentStatusWhereUniqueInput;
|
||||
data: Prisma.ChangeEquipmentStatusUpdateInput;
|
||||
}): Promise<ChangeEquipmentStatus> {
|
||||
return this.prisma.changeEquipmentStatus.update({
|
||||
...params,
|
||||
include: {
|
||||
equipment: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async remove(where: Prisma.ChangeEquipmentStatusWhereUniqueInput): Promise<ChangeEquipmentStatus> {
|
||||
return this.prisma.changeEquipmentStatus.delete({
|
||||
where,
|
||||
include: {
|
||||
equipment: true,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsOptional, ValidateNested } from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { PageRequestDto } from '../../common/dto/page-request.dto';
|
||||
|
||||
export class ChangeEquipmentStatusListRequestDto {
|
||||
@ApiProperty({ description: 'Фильтр', required: false })
|
||||
@IsOptional()
|
||||
filter?: any; // Using any since DTO.Filter is not defined in the schema
|
||||
|
||||
@ApiProperty({ description: 'Параметры пагинации' })
|
||||
@ValidateNested()
|
||||
@Type(() => PageRequestDto)
|
||||
page: PageRequestDto;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { PageInfoDto } from '../../common/dto/page-info.dto';
|
||||
|
||||
export class ChangeEquipmentStatusListResponseDto {
|
||||
@ApiProperty({ description: 'Список документов изменения статуса', type: () => Object, isArray: true })
|
||||
content: any[];
|
||||
|
||||
@ApiProperty({ description: 'Метаданные пагинации', type: () => PageInfoDto })
|
||||
pageInfo: PageInfoDto;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsString, IsOptional, IsDateString, IsUUID } from 'class-validator';
|
||||
import { EquipmentStatus } from '@prisma/client';
|
||||
|
||||
export class CreateChangeEquipmentStatusDto {
|
||||
@ApiProperty({ description: 'Оборудование' })
|
||||
@IsUUID()
|
||||
equipmentId: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Новый статус',
|
||||
enum: EquipmentStatus,
|
||||
enumName: 'EquipmentStatus'
|
||||
})
|
||||
newStatus: EquipmentStatus;
|
||||
|
||||
@ApiProperty({ description: 'Номер', required: false })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
number?: string;
|
||||
|
||||
@ApiProperty({ description: 'Дата изменения статуса' })
|
||||
@IsDateString()
|
||||
date: string;
|
||||
|
||||
@ApiProperty({ description: 'Ответственный', required: false })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
responsible?: string;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsString, IsOptional, IsDateString, IsUUID } from 'class-validator';
|
||||
import { EquipmentStatus } from '@prisma/client';
|
||||
import { PartialType } from '@nestjs/swagger';
|
||||
import { CreateChangeEquipmentStatusDto } from './create-change-equipment-status.dto';
|
||||
|
||||
export class UpdateChangeEquipmentStatusDto extends PartialType(CreateChangeEquipmentStatusDto) {
|
||||
@ApiProperty({ description: 'Оборудование', required: false })
|
||||
@IsOptional()
|
||||
@IsUUID()
|
||||
equipmentId?: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Новый статус',
|
||||
enum: EquipmentStatus,
|
||||
enumName: 'EquipmentStatus',
|
||||
required: false
|
||||
})
|
||||
@IsOptional()
|
||||
newStatus?: EquipmentStatus;
|
||||
|
||||
@ApiProperty({ description: 'Номер', required: false })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
number?: string;
|
||||
|
||||
@ApiProperty({ description: 'Дата изменения статуса', required: false })
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
date?: string;
|
||||
|
||||
@ApiProperty({ description: 'Ответственный', required: false })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
responsible?: string;
|
||||
}
|
||||
15
backend/src/common/dto/page-info.dto.ts
Normal file
15
backend/src/common/dto/page-info.dto.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class PageInfoDto {
|
||||
@ApiProperty({ description: 'Номер страницы' })
|
||||
page: number;
|
||||
|
||||
@ApiProperty({ description: 'Размер страницы' })
|
||||
size: number;
|
||||
|
||||
@ApiProperty({ description: 'Общее количество элементов' })
|
||||
total: number;
|
||||
|
||||
@ApiProperty({ description: 'Общее количество страниц' })
|
||||
totalPages: number;
|
||||
}
|
||||
16
backend/src/common/dto/page-request.dto.ts
Normal file
16
backend/src/common/dto/page-request.dto.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNumber, IsOptional, Min } from 'class-validator';
|
||||
|
||||
export class PageRequestDto {
|
||||
@ApiProperty({ description: 'Номер страницы', required: false, default: 0 })
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
page?: number = 0;
|
||||
|
||||
@ApiProperty({ description: 'Размер страницы', required: false, default: 25 })
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
size?: number = 25;
|
||||
}
|
||||
32
backend/src/equipment/dto/create-equipment.dto.ts
Normal file
32
backend/src/equipment/dto/create-equipment.dto.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsString, IsOptional, IsDateString } from 'class-validator';
|
||||
import { EquipmentStatus } from '@prisma/client';
|
||||
|
||||
export class CreateEquipmentDto {
|
||||
@ApiProperty({ description: 'Название оборудования' })
|
||||
@IsString()
|
||||
name: string;
|
||||
|
||||
@ApiProperty({ description: 'Заводской (серийный) номер' })
|
||||
@IsString()
|
||||
serialNumber: string;
|
||||
|
||||
@ApiProperty({ description: 'Дата поверки', required: false })
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
dateOfInspection?: string;
|
||||
|
||||
@ApiProperty({ description: 'Дата изготовления', required: false })
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
commissionedAt?: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Текущий статус',
|
||||
enum: EquipmentStatus,
|
||||
enumName: 'EquipmentStatus',
|
||||
required: false
|
||||
})
|
||||
@IsOptional()
|
||||
status?: EquipmentStatus;
|
||||
}
|
||||
15
backend/src/equipment/dto/equipment-list-request.dto.ts
Normal file
15
backend/src/equipment/dto/equipment-list-request.dto.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsOptional, ValidateNested } from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { PageRequestDto } from '../../common/dto/page-request.dto';
|
||||
|
||||
export class EquipmentListRequestDto {
|
||||
@ApiProperty({ description: 'Фильтр', required: false })
|
||||
@IsOptional()
|
||||
filter?: any; // Using any since DTO.Filter is not defined in the schema
|
||||
|
||||
@ApiProperty({ description: 'Параметры пагинации' })
|
||||
@ValidateNested()
|
||||
@Type(() => PageRequestDto)
|
||||
page: PageRequestDto;
|
||||
}
|
||||
10
backend/src/equipment/dto/equipment-list-response.dto.ts
Normal file
10
backend/src/equipment/dto/equipment-list-response.dto.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { PageInfoDto } from '../../common/dto/page-info.dto';
|
||||
|
||||
export class EquipmentListResponseDto {
|
||||
@ApiProperty({ description: 'Список оборудования', type: () => Object, isArray: true })
|
||||
content: any[];
|
||||
|
||||
@ApiProperty({ description: 'Метаданные пагинации', type: () => PageInfoDto })
|
||||
pageInfo: PageInfoDto;
|
||||
}
|
||||
36
backend/src/equipment/dto/update-equipment.dto.ts
Normal file
36
backend/src/equipment/dto/update-equipment.dto.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsString, IsOptional, IsDateString } from 'class-validator';
|
||||
import { EquipmentStatus } from '@prisma/client';
|
||||
import { PartialType } from '@nestjs/swagger';
|
||||
import { CreateEquipmentDto } from './create-equipment.dto';
|
||||
|
||||
export class UpdateEquipmentDto extends PartialType(CreateEquipmentDto) {
|
||||
@ApiProperty({ description: 'Название оборудования', required: false })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
name?: string;
|
||||
|
||||
@ApiProperty({ description: 'Заводской (серийный) номер', required: false })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
serialNumber?: string;
|
||||
|
||||
@ApiProperty({ description: 'Дата поверки', required: false })
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
dateOfInspection?: string;
|
||||
|
||||
@ApiProperty({ description: 'Дата изготовления', required: false })
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
commissionedAt?: string;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'Текущий статус',
|
||||
enum: EquipmentStatus,
|
||||
enumName: 'EquipmentStatus',
|
||||
required: false
|
||||
})
|
||||
@IsOptional()
|
||||
status?: EquipmentStatus;
|
||||
}
|
||||
98
backend/src/equipment/equipment.controller.ts
Normal file
98
backend/src/equipment/equipment.controller.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import { Controller, Get, Post, Body, Put, Param, Delete, Query, UseGuards } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
|
||||
import { EquipmentService } from './equipment.service';
|
||||
import { CreateEquipmentDto } from './dto/create-equipment.dto';
|
||||
import { UpdateEquipmentDto } from './dto/update-equipment.dto';
|
||||
import { EquipmentListRequestDto } from './dto/equipment-list-request.dto';
|
||||
import { EquipmentListResponseDto } from './dto/equipment-list-response.dto';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
|
||||
@ApiTags('equipment')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('equipment')
|
||||
export class EquipmentController {
|
||||
constructor(private readonly equipmentService: EquipmentService) {}
|
||||
|
||||
@Post('page')
|
||||
@ApiOperation({ summary: 'Постраничный список оборудования с фильтрацией' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Список оборудования',
|
||||
type: EquipmentListResponseDto
|
||||
})
|
||||
async findAll(
|
||||
@Body() dto: EquipmentListRequestDto,
|
||||
) {
|
||||
const { page, filter } = dto;
|
||||
const skip = page?.page ? page.page * page.size : 0;
|
||||
const take = page?.size || 25;
|
||||
|
||||
const where = filter ? this.buildWhereClause(filter) : {};
|
||||
|
||||
const [content, total] = await Promise.all([
|
||||
this.equipmentService.findAll({ skip, take, where }),
|
||||
this.equipmentService.count(where)
|
||||
]);
|
||||
|
||||
return {
|
||||
content,
|
||||
pageInfo: {
|
||||
page: page?.page || 0,
|
||||
size: take,
|
||||
total,
|
||||
totalPages: Math.ceil(total / take),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Получить оборудование по идентификатору' })
|
||||
@ApiResponse({ status: 200, description: 'Оборудование найдено' })
|
||||
@ApiResponse({ status: 404, description: 'Оборудование не найдено' })
|
||||
findOne(@Param('id') id: string) {
|
||||
return this.equipmentService.findOne({ id });
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Создать оборудование' })
|
||||
@ApiResponse({ status: 201, description: 'Оборудование создано' })
|
||||
create(@Body() dto: CreateEquipmentDto) {
|
||||
return this.equipmentService.create(dto);
|
||||
}
|
||||
|
||||
@Put(':id')
|
||||
@ApiOperation({ summary: 'Обновить оборудование' })
|
||||
@ApiResponse({ status: 200, description: 'Оборудование обновлено' })
|
||||
@ApiResponse({ status: 404, description: 'Оборудование не найдено' })
|
||||
update(@Param('id') id: string, @Body() dto: UpdateEquipmentDto) {
|
||||
return this.equipmentService.update({ where: { id }, data: dto });
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Удалить оборудование' })
|
||||
@ApiResponse({ status: 200, description: 'Оборудование удалено' })
|
||||
@ApiResponse({ status: 404, description: 'Оборудование не найдено' })
|
||||
remove(@Param('id') id: string) {
|
||||
return this.equipmentService.remove({ id });
|
||||
}
|
||||
|
||||
private buildWhereClause(filter: any): any {
|
||||
// Basic implementation - can be extended based on filter structure
|
||||
const where: any = {};
|
||||
|
||||
if (filter.name) {
|
||||
where.name = { contains: filter.name, mode: 'insensitive' };
|
||||
}
|
||||
|
||||
if (filter.serialNumber) {
|
||||
where.serialNumber = { contains: filter.serialNumber, mode: 'insensitive' };
|
||||
}
|
||||
|
||||
if (filter.status) {
|
||||
where.status = filter.status;
|
||||
}
|
||||
|
||||
return where;
|
||||
}
|
||||
}
|
||||
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<Equipment[]> {
|
||||
const { skip, take, where, orderBy } = params;
|
||||
return this.prisma.equipment.findMany({ skip, take, where, orderBy });
|
||||
}
|
||||
|
||||
async count(where?: Prisma.EquipmentWhereInput): Promise<number> {
|
||||
return this.prisma.equipment.count({ where });
|
||||
}
|
||||
|
||||
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