feat: add generated code
This commit is contained in:
51
backend/prisma/schema.prisma
Normal file
51
backend/prisma/schema.prisma
Normal file
@@ -0,0 +1,51 @@
|
||||
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
|
||||
statusChanges ChangeEquipmentStatus[]
|
||||
|
||||
@@unique([serialNumber])
|
||||
@@index([status])
|
||||
@@index([dateOfInspection])
|
||||
@@index([commissionedAt])
|
||||
}
|
||||
|
||||
model ChangeEquipmentStatus {
|
||||
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], onDelete: Cascade)
|
||||
|
||||
@@id([equipmentId, newStatus])
|
||||
@@index([date])
|
||||
@@index([responsible])
|
||||
}
|
||||
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 { AuthModule } from './auth/auth.module';
|
||||
import { PrismaService } from './prisma/prisma.service';
|
||||
import { EquipmentModule } from './equipment/equipment.module';
|
||||
import { ChangeEquipmentStatusModule } from './change-equipment-status/change-equipment-status.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
AuthModule,
|
||||
EquipmentModule,
|
||||
ChangeEquipmentStatusModule,
|
||||
],
|
||||
providers: [PrismaService],
|
||||
})
|
||||
export class AppModule {}
|
||||
@@ -0,0 +1,96 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseGuards } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags, ApiOperation, ApiResponse, ApiParam } 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 { ChangeEquipmentStatusListRequestDto } from './dto/change-equipment-status-list-request.dto';
|
||||
import { ChangeEquipmentStatusListResponseDto } from './dto/change-equipment-status-list-response.dto';
|
||||
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, type: ChangeEquipmentStatusListResponseDto })
|
||||
async listChangeEquipmentStatus(@Body() dto: ChangeEquipmentStatusListRequestDto) {
|
||||
const { content, total } = await this.changeEquipmentStatusService.findManyWithPagination({
|
||||
skip: dto.page?.skip,
|
||||
take: dto.page?.take,
|
||||
where: dto.filter?.where,
|
||||
orderBy: dto.filter?.orderBy,
|
||||
});
|
||||
|
||||
return {
|
||||
content,
|
||||
pageInfo: {
|
||||
skip: dto.page?.skip || 0,
|
||||
take: dto.page?.take || 25,
|
||||
total,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@Get(':equipmentId/:newStatus')
|
||||
@ApiOperation({ summary: 'Получить документ изменения статуса по ключу' })
|
||||
@ApiParam({ name: 'equipmentId', description: 'Оборудование' })
|
||||
@ApiParam({
|
||||
name: 'newStatus',
|
||||
enum: EquipmentStatus,
|
||||
enumName: 'EquipmentStatus',
|
||||
description: 'Новый статус'
|
||||
})
|
||||
async findOne(
|
||||
@Param('equipmentId') equipmentId: string,
|
||||
@Param('newStatus') newStatus: EquipmentStatus,
|
||||
) {
|
||||
return this.changeEquipmentStatusService.findOne({ equipmentId_newStatus: { equipmentId, newStatus } });
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Создать документ изменения статуса' })
|
||||
async create(@Body() dto: CreateChangeEquipmentStatusDto) {
|
||||
return this.changeEquipmentStatusService.create(dto);
|
||||
}
|
||||
|
||||
@Patch(':equipmentId/:newStatus')
|
||||
@ApiOperation({ summary: 'Обновить документ изменения статуса' })
|
||||
@ApiParam({ name: 'equipmentId', description: 'Оборудование' })
|
||||
@ApiParam({
|
||||
name: 'newStatus',
|
||||
enum: EquipmentStatus,
|
||||
enumName: 'EquipmentStatus',
|
||||
description: 'Новый статус'
|
||||
})
|
||||
async 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: 'Удалить документ изменения статуса' })
|
||||
@ApiParam({ name: 'equipmentId', description: 'Оборудование' })
|
||||
@ApiParam({
|
||||
name: 'newStatus',
|
||||
enum: EquipmentStatus,
|
||||
enumName: 'EquipmentStatus',
|
||||
description: 'Новый статус'
|
||||
})
|
||||
async remove(
|
||||
@Param('equipmentId') equipmentId: string,
|
||||
@Param('newStatus') newStatus: EquipmentStatus,
|
||||
) {
|
||||
return this.changeEquipmentStatusService.remove({ equipmentId_newStatus: { equipmentId, newStatus } });
|
||||
}
|
||||
}
|
||||
@@ -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,51 @@
|
||||
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 });
|
||||
}
|
||||
|
||||
async findOne(where: Prisma.ChangeEquipmentStatusWhereUniqueInput): Promise<ChangeEquipmentStatus | null> {
|
||||
return this.prisma.changeEquipmentStatus.findUnique({ where });
|
||||
}
|
||||
|
||||
async create(data: Prisma.ChangeEquipmentStatusCreateInput): Promise<ChangeEquipmentStatus> {
|
||||
return this.prisma.changeEquipmentStatus.create({ data });
|
||||
}
|
||||
|
||||
async update(params: {
|
||||
where: Prisma.ChangeEquipmentStatusWhereUniqueInput;
|
||||
data: Prisma.ChangeEquipmentStatusUpdateInput;
|
||||
}): Promise<ChangeEquipmentStatus> {
|
||||
return this.prisma.changeEquipmentStatus.update(params);
|
||||
}
|
||||
|
||||
async remove(where: Prisma.ChangeEquipmentStatusWhereUniqueInput): Promise<ChangeEquipmentStatus> {
|
||||
return this.prisma.changeEquipmentStatus.delete({ where });
|
||||
}
|
||||
|
||||
async findManyWithPagination(params: {
|
||||
skip?: number;
|
||||
take?: number;
|
||||
where?: Prisma.ChangeEquipmentStatusWhereInput;
|
||||
orderBy?: Prisma.ChangeEquipmentStatusOrderByWithRelationInput;
|
||||
}): Promise<{ content: ChangeEquipmentStatus[]; total: number }> {
|
||||
const { skip, take, where, orderBy } = params;
|
||||
const [content, total] = await Promise.all([
|
||||
this.prisma.changeEquipmentStatus.findMany({ skip, take, where, orderBy }),
|
||||
this.prisma.changeEquipmentStatus.count({ where }),
|
||||
]);
|
||||
return { content, total };
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsOptional, ValidateNested } from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { FilterDto } from './filter.dto';
|
||||
import { PageRequestDto } from './page-request.dto';
|
||||
|
||||
export class ChangeEquipmentStatusListRequestDto {
|
||||
@IsOptional()
|
||||
@ValidateNested()
|
||||
@Type(() => FilterDto)
|
||||
@ApiProperty({ description: 'Фильтр', required: false })
|
||||
filter?: FilterDto;
|
||||
|
||||
@ValidateNested()
|
||||
@Type(() => PageRequestDto)
|
||||
@ApiProperty({ description: 'Параметры пагинации' })
|
||||
page: PageRequestDto;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { ChangeEquipmentStatusDto } from './change-equipment-status.dto';
|
||||
import { PageInfoDto } from './page-info.dto';
|
||||
|
||||
export class ChangeEquipmentStatusListResponseDto {
|
||||
@ApiProperty({ description: 'Список документов изменения статуса', type: [ChangeEquipmentStatusDto] })
|
||||
content: ChangeEquipmentStatusDto[];
|
||||
|
||||
@ApiProperty({ description: 'Метаданные пагинации' })
|
||||
pageInfo: PageInfoDto;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { EquipmentStatus } from '@prisma/client';
|
||||
|
||||
export class ChangeEquipmentStatusDto {
|
||||
@ApiProperty({ description: 'Оборудование' })
|
||||
equipmentId: string;
|
||||
|
||||
@ApiProperty({
|
||||
enum: EquipmentStatus,
|
||||
enumName: 'EquipmentStatus',
|
||||
description: 'Новый статус'
|
||||
})
|
||||
newStatus: EquipmentStatus;
|
||||
|
||||
@ApiProperty({ description: 'Номер', required: false })
|
||||
number?: string;
|
||||
|
||||
@ApiProperty({ description: 'Дата изменения статуса' })
|
||||
date: Date;
|
||||
|
||||
@ApiProperty({ description: 'Ответственный', required: false })
|
||||
responsible?: string;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { IsString, IsOptional, IsDateString } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { EquipmentStatus } from '@prisma/client';
|
||||
|
||||
export class CreateChangeEquipmentStatusDto {
|
||||
@IsString()
|
||||
@ApiProperty({ description: 'Оборудование' })
|
||||
equipmentId: string;
|
||||
|
||||
@ApiProperty({
|
||||
enum: EquipmentStatus,
|
||||
enumName: 'EquipmentStatus',
|
||||
description: 'Новый статус'
|
||||
})
|
||||
newStatus: EquipmentStatus;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiProperty({ description: 'Номер', required: false })
|
||||
number?: string;
|
||||
|
||||
@IsDateString()
|
||||
@ApiProperty({ description: 'Дата изменения статуса' })
|
||||
date: Date;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiProperty({ description: 'Ответственный', required: false })
|
||||
responsible?: string;
|
||||
}
|
||||
9
backend/src/change-equipment-status/dto/filter.dto.ts
Normal file
9
backend/src/change-equipment-status/dto/filter.dto.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class FilterDto {
|
||||
@ApiProperty({ description: 'Условия фильтрации', required: false })
|
||||
where?: any;
|
||||
|
||||
@ApiProperty({ description: 'Порядок сортировки', required: false })
|
||||
orderBy?: any;
|
||||
}
|
||||
12
backend/src/change-equipment-status/dto/page-info.dto.ts
Normal file
12
backend/src/change-equipment-status/dto/page-info.dto.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class PageInfoDto {
|
||||
@ApiProperty({ description: 'Количество пропускаемых записей' })
|
||||
skip: number;
|
||||
|
||||
@ApiProperty({ description: 'Количество записей на странице' })
|
||||
take: number;
|
||||
|
||||
@ApiProperty({ description: 'Общее количество записей' })
|
||||
total: number;
|
||||
}
|
||||
16
backend/src/change-equipment-status/dto/page-request.dto.ts
Normal file
16
backend/src/change-equipment-status/dto/page-request.dto.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsOptional, IsNumber, Min } from 'class-validator';
|
||||
|
||||
export class PageRequestDto {
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
@ApiProperty({ description: 'Количество пропускаемых записей', required: false, default: 0 })
|
||||
skip?: number = 0;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
@ApiProperty({ description: 'Количество записей на странице', required: false, default: 25 })
|
||||
take?: number = 25;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { IsString, IsOptional, IsDateString } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { EquipmentStatus } from '@prisma/client';
|
||||
|
||||
export class UpdateChangeEquipmentStatusDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiProperty({ description: 'Оборудование', required: false })
|
||||
equipmentId?: string;
|
||||
|
||||
@IsOptional()
|
||||
@ApiProperty({
|
||||
enum: EquipmentStatus,
|
||||
enumName: 'EquipmentStatus',
|
||||
description: 'Новый статус',
|
||||
required: false
|
||||
})
|
||||
newStatus?: EquipmentStatus;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiProperty({ description: 'Номер', required: false })
|
||||
number?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
@ApiProperty({ description: 'Дата изменения статуса', required: false })
|
||||
date?: Date;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiProperty({ description: 'Ответственный', required: false })
|
||||
responsible?: string;
|
||||
}
|
||||
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 { IsString, IsOptional, IsDateString } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { EquipmentStatus } from '@prisma/client';
|
||||
|
||||
export class CreateEquipmentDto {
|
||||
@IsString()
|
||||
@ApiProperty({ description: 'Название оборудования' })
|
||||
name: string;
|
||||
|
||||
@IsString()
|
||||
@ApiProperty({ description: 'Заводской (серийный) номер' })
|
||||
serialNumber: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
@ApiProperty({ description: 'Дата поверки', required: false })
|
||||
dateOfInspection?: Date;
|
||||
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
@ApiProperty({ description: 'Дата изготовления', required: false })
|
||||
commissionedAt?: Date;
|
||||
|
||||
@IsOptional()
|
||||
@ApiProperty({
|
||||
enum: EquipmentStatus,
|
||||
enumName: 'EquipmentStatus',
|
||||
description: 'Текущий статус',
|
||||
required: false
|
||||
})
|
||||
status?: EquipmentStatus;
|
||||
}
|
||||
18
backend/src/equipment/dto/equipment-list-request.dto.ts
Normal file
18
backend/src/equipment/dto/equipment-list-request.dto.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsOptional, ValidateNested } from 'class-validator';
|
||||
import { Type } from 'class-transformer';
|
||||
import { FilterDto } from './filter.dto';
|
||||
import { PageRequestDto } from './page-request.dto';
|
||||
|
||||
export class EquipmentListRequestDto {
|
||||
@IsOptional()
|
||||
@ValidateNested()
|
||||
@Type(() => FilterDto)
|
||||
@ApiProperty({ description: 'Фильтр', required: false })
|
||||
filter?: FilterDto;
|
||||
|
||||
@ValidateNested()
|
||||
@Type(() => PageRequestDto)
|
||||
@ApiProperty({ description: 'Параметры пагинации' })
|
||||
page: PageRequestDto;
|
||||
}
|
||||
11
backend/src/equipment/dto/equipment-list-response.dto.ts
Normal file
11
backend/src/equipment/dto/equipment-list-response.dto.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { EquipmentDto } from './equipment.dto';
|
||||
import { PageInfoDto } from './page-info.dto';
|
||||
|
||||
export class EquipmentListResponseDto {
|
||||
@ApiProperty({ description: 'Список оборудования', type: [EquipmentDto] })
|
||||
content: EquipmentDto[];
|
||||
|
||||
@ApiProperty({ description: 'Метаданные пагинации' })
|
||||
pageInfo: PageInfoDto;
|
||||
}
|
||||
26
backend/src/equipment/dto/equipment.dto.ts
Normal file
26
backend/src/equipment/dto/equipment.dto.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { EquipmentStatus } from '@prisma/client';
|
||||
|
||||
export class EquipmentDto {
|
||||
@ApiProperty({ description: 'Идентификатор оборудования' })
|
||||
id: string;
|
||||
|
||||
@ApiProperty({ description: 'Название оборудования' })
|
||||
name: string;
|
||||
|
||||
@ApiProperty({ description: 'Заводской (серийный) номер' })
|
||||
serialNumber: string;
|
||||
|
||||
@ApiProperty({ description: 'Дата поверки', required: false })
|
||||
dateOfInspection?: Date;
|
||||
|
||||
@ApiProperty({ description: 'Дата изготовления', required: false })
|
||||
commissionedAt?: Date;
|
||||
|
||||
@ApiProperty({
|
||||
enum: EquipmentStatus,
|
||||
enumName: 'EquipmentStatus',
|
||||
description: 'Текущий статус'
|
||||
})
|
||||
status: EquipmentStatus;
|
||||
}
|
||||
10
backend/src/equipment/dto/filter.dto.ts
Normal file
10
backend/src/equipment/dto/filter.dto.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Prisma } from '@prisma/client';
|
||||
|
||||
export class FilterDto {
|
||||
@ApiProperty({ description: 'Условия фильтрации', required: false })
|
||||
where?: any;
|
||||
|
||||
@ApiProperty({ description: 'Порядок сортировки', required: false })
|
||||
orderBy?: any;
|
||||
}
|
||||
12
backend/src/equipment/dto/page-info.dto.ts
Normal file
12
backend/src/equipment/dto/page-info.dto.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class PageInfoDto {
|
||||
@ApiProperty({ description: 'Количество пропускаемых записей' })
|
||||
skip: number;
|
||||
|
||||
@ApiProperty({ description: 'Количество записей на странице' })
|
||||
take: number;
|
||||
|
||||
@ApiProperty({ description: 'Общее количество записей' })
|
||||
total: number;
|
||||
}
|
||||
16
backend/src/equipment/dto/page-request.dto.ts
Normal file
16
backend/src/equipment/dto/page-request.dto.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsOptional, IsNumber, Min } from 'class-validator';
|
||||
|
||||
export class PageRequestDto {
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Min(0)
|
||||
@ApiProperty({ description: 'Количество пропускаемых записей', required: false, default: 0 })
|
||||
skip?: number = 0;
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
@Min(1)
|
||||
@ApiProperty({ description: 'Количество записей на странице', required: false, default: 25 })
|
||||
take?: number = 25;
|
||||
}
|
||||
34
backend/src/equipment/dto/update-equipment.dto.ts
Normal file
34
backend/src/equipment/dto/update-equipment.dto.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { IsString, IsOptional, IsDateString } from 'class-validator';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { EquipmentStatus } from '@prisma/client';
|
||||
|
||||
export class UpdateEquipmentDto {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiProperty({ description: 'Название оборудования', required: false })
|
||||
name?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ApiProperty({ description: 'Заводской (серийный) номер', required: false })
|
||||
serialNumber?: string;
|
||||
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
@ApiProperty({ description: 'Дата поверки', required: false })
|
||||
dateOfInspection?: Date;
|
||||
|
||||
@IsOptional()
|
||||
@IsDateString()
|
||||
@ApiProperty({ description: 'Дата изготовления', required: false })
|
||||
commissionedAt?: Date;
|
||||
|
||||
@IsOptional()
|
||||
@ApiProperty({
|
||||
enum: EquipmentStatus,
|
||||
enumName: 'EquipmentStatus',
|
||||
description: 'Текущий статус',
|
||||
required: false
|
||||
})
|
||||
status?: EquipmentStatus;
|
||||
}
|
||||
61
backend/src/equipment/equipment.controller.ts
Normal file
61
backend/src/equipment/equipment.controller.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { Controller, Get, Post, Body, Patch, 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 { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { EquipmentListRequestDto } from './dto/equipment-list-request.dto';
|
||||
import { EquipmentListResponseDto } from './dto/equipment-list-response.dto';
|
||||
|
||||
@ApiTags('equipment')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('equipment')
|
||||
export class EquipmentController {
|
||||
constructor(private readonly equipmentService: EquipmentService) {}
|
||||
|
||||
@Post('page')
|
||||
@ApiOperation({ summary: 'Постраничный список оборудования с фильтрацией' })
|
||||
@ApiResponse({ status: 200, type: EquipmentListResponseDto })
|
||||
async listEquipment(@Body() dto: EquipmentListRequestDto) {
|
||||
const { content, total } = await this.equipmentService.findManyWithPagination({
|
||||
skip: dto.page?.skip,
|
||||
take: dto.page?.take,
|
||||
where: dto.filter?.where,
|
||||
orderBy: dto.filter?.orderBy,
|
||||
});
|
||||
|
||||
return {
|
||||
content,
|
||||
pageInfo: {
|
||||
skip: dto.page?.skip || 0,
|
||||
take: dto.page?.take || 25,
|
||||
total,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Получить оборудование по идентификатору' })
|
||||
async findOne(@Param('id') id: string) {
|
||||
return this.equipmentService.findOne({ id });
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Создать оборудование' })
|
||||
async create(@Body() dto: CreateEquipmentDto) {
|
||||
return this.equipmentService.create(dto);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
@ApiOperation({ summary: 'Обновить оборудование' })
|
||||
async update(@Param('id') id: string, @Body() dto: UpdateEquipmentDto) {
|
||||
return this.equipmentService.update({ where: { id }, data: dto });
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Удалить оборудование' })
|
||||
async 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 {}
|
||||
51
backend/src/equipment/equipment.service.ts
Normal file
51
backend/src/equipment/equipment.service.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
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 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 });
|
||||
}
|
||||
|
||||
async findManyWithPagination(params: {
|
||||
skip?: number;
|
||||
take?: number;
|
||||
where?: Prisma.EquipmentWhereInput;
|
||||
orderBy?: Prisma.EquipmentOrderByWithRelationInput;
|
||||
}): Promise<{ content: Equipment[]; total: number }> {
|
||||
const { skip, take, where, orderBy } = params;
|
||||
const [content, total] = await Promise.all([
|
||||
this.prisma.equipment.findMany({ skip, take, where, orderBy }),
|
||||
this.prisma.equipment.count({ where }),
|
||||
]);
|
||||
return { content, total };
|
||||
}
|
||||
}
|
||||
27
frontend/src/App.tsx
Normal file
27
frontend/src/App.tsx
Normal file
@@ -0,0 +1,27 @@
|
||||
import { Admin, Resource } from 'react-admin';
|
||||
import { dataProvider } from './dataProvider';
|
||||
import { authProvider } from './authProvider';
|
||||
|
||||
import { EquipmentList, EquipmentCreate, EquipmentEdit, EquipmentShow } from './resources/equipment';
|
||||
import { ChangeEquipmentStatusList, ChangeEquipmentStatusCreate, ChangeEquipmentStatusEdit, ChangeEquipmentStatusShow } from './resources/change-equipment-status';
|
||||
|
||||
const App = () => (
|
||||
<Admin dataProvider={dataProvider} authProvider={authProvider}>
|
||||
<Resource
|
||||
name="equipment"
|
||||
list={EquipmentList}
|
||||
create={EquipmentCreate}
|
||||
edit={EquipmentEdit}
|
||||
show={EquipmentShow}
|
||||
/>
|
||||
<Resource
|
||||
name="change-equipment-status"
|
||||
list={ChangeEquipmentStatusList}
|
||||
create={ChangeEquipmentStatusCreate}
|
||||
edit={ChangeEquipmentStatusEdit}
|
||||
show={ChangeEquipmentStatusShow}
|
||||
/>
|
||||
</Admin>
|
||||
);
|
||||
|
||||
export default App;
|
||||
13
frontend/src/main.tsx
Normal file
13
frontend/src/main.tsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom/client';
|
||||
import { initKeycloak } from './authProvider';
|
||||
import App from './App';
|
||||
|
||||
// Initialize Keycloak before rendering the app
|
||||
initKeycloak().then(() => {
|
||||
ReactDOM.createRoot(document.getElementById('root')!).render(
|
||||
<React.StrictMode>
|
||||
<App />
|
||||
</React.StrictMode>
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,25 @@
|
||||
import { Create, SimpleForm, TextInput, DateInput, SelectInput, ReferenceInput } from 'react-admin';
|
||||
|
||||
const statusChoices = [
|
||||
{ id: 'Active', name: 'В эксплуатации' },
|
||||
{ id: 'Repair', name: 'В ремонте' },
|
||||
{ id: 'Reserve', name: 'В резерве' },
|
||||
{ id: 'WriteOff', name: 'Списано' },
|
||||
];
|
||||
|
||||
export const ChangeEquipmentStatusCreate = () => (
|
||||
<Create>
|
||||
<SimpleForm>
|
||||
<ReferenceInput source="equipmentId" reference="equipment" label="Оборудование" required />
|
||||
<SelectInput
|
||||
source="newStatus"
|
||||
label="Новый статус"
|
||||
choices={statusChoices}
|
||||
required
|
||||
/>
|
||||
<TextInput source="number" label="Номер" fullWidth />
|
||||
<DateInput source="date" label="Дата изменения статуса" required />
|
||||
<TextInput source="responsible" label="Ответственный" fullWidth />
|
||||
</SimpleForm>
|
||||
</Create>
|
||||
);
|
||||
@@ -0,0 +1,24 @@
|
||||
import { Edit, SimpleForm, TextInput, DateInput, SelectInput, ReferenceInput } from 'react-admin';
|
||||
|
||||
const statusChoices = [
|
||||
{ id: 'Active', name: 'В эксплуатации' },
|
||||
{ id: 'Repair', name: 'В ремонте' },
|
||||
{ id: 'Reserve', name: 'В резерве' },
|
||||
{ id: 'WriteOff', name: 'Списано' },
|
||||
];
|
||||
|
||||
export const ChangeEquipmentStatusEdit = () => (
|
||||
<Edit>
|
||||
<SimpleForm>
|
||||
<ReferenceInput source="equipmentId" reference="equipment" label="Оборудование" />
|
||||
<SelectInput
|
||||
source="newStatus"
|
||||
label="Новый статус"
|
||||
choices={statusChoices}
|
||||
/>
|
||||
<TextInput source="number" label="Номер" fullWidth />
|
||||
<DateInput source="date" label="Дата изменения статуса" />
|
||||
<TextInput source="responsible" label="Ответственный" fullWidth />
|
||||
</SimpleForm>
|
||||
</Edit>
|
||||
);
|
||||
@@ -0,0 +1,35 @@
|
||||
import { List, DataTable, TextField, DateField, EditButton, ShowButton, ReferenceField } from 'react-admin';
|
||||
|
||||
const statusChoices = [
|
||||
{ id: 'Active', name: 'В эксплуатации' },
|
||||
{ id: 'Repair', name: 'В ремонте' },
|
||||
{ id: 'Reserve', name: 'В резерве' },
|
||||
{ id: 'WriteOff', name: 'Списано' },
|
||||
];
|
||||
|
||||
const StatusField = ({ source, record }: { source: string; record?: any }) => {
|
||||
const status = record?.[source];
|
||||
const statusLabel = statusChoices.find(choice => choice.id === status)?.name || status;
|
||||
return <span>{statusLabel}</span>;
|
||||
};
|
||||
|
||||
export const ChangeEquipmentStatusList = () => (
|
||||
<List>
|
||||
<DataTable>
|
||||
<DataTable.Col source="equipmentId" label="Оборудование">
|
||||
<ReferenceField source="equipmentId" reference="equipment" />
|
||||
</DataTable.Col>
|
||||
<DataTable.Col source="newStatus" label="Новый статус">
|
||||
<StatusField source="newStatus" />
|
||||
</DataTable.Col>
|
||||
<DataTable.Col source="number" label="Номер" />
|
||||
<DataTable.Col source="date" label="Дата изменения статуса" field={DateField} />
|
||||
<DataTable.Col source="responsible" label="Ответственный" />
|
||||
<DataTable.Col source="createdAt" label="Создано" field={DateField} />
|
||||
<DataTable.Col>
|
||||
<ShowButton />
|
||||
<EditButton />
|
||||
</DataTable.Col>
|
||||
</DataTable>
|
||||
</List>
|
||||
);
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Show, SimpleShowLayout, TextField, DateField, ReferenceField } from 'react-admin';
|
||||
|
||||
const statusChoices = [
|
||||
{ id: 'Active', name: 'В эксплуатации' },
|
||||
{ id: 'Repair', name: 'В ремонте' },
|
||||
{ id: 'Reserve', name: 'В резерве' },
|
||||
{ id: 'WriteOff', name: 'Списано' },
|
||||
];
|
||||
|
||||
const StatusField = ({ source, record }: { source: string; record?: any }) => {
|
||||
const status = record?.[source];
|
||||
const statusLabel = statusChoices.find(choice => choice.id === status)?.name || status;
|
||||
return <span>{statusLabel}</span>;
|
||||
};
|
||||
|
||||
export const ChangeEquipmentStatusShow = () => (
|
||||
<Show>
|
||||
<SimpleShowLayout>
|
||||
<ReferenceField source="equipmentId" reference="equipment" label="Оборудование" />
|
||||
<StatusField source="newStatus" label="Новый статус" />
|
||||
<TextField source="number" label="Номер" />
|
||||
<DateField source="date" label="Дата изменения статуса" />
|
||||
<TextField source="responsible" label="Ответственный" />
|
||||
<DateField source="createdAt" label="Создано" />
|
||||
<DateField source="updatedAt" label="Обновлено" />
|
||||
</SimpleShowLayout>
|
||||
</Show>
|
||||
);
|
||||
4
frontend/src/resources/change-equipment-status/index.ts
Normal file
4
frontend/src/resources/change-equipment-status/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export { ChangeEquipmentStatusList } from './ChangeEquipmentStatusList';
|
||||
export { ChangeEquipmentStatusCreate } from './ChangeEquipmentStatusCreate';
|
||||
export { ChangeEquipmentStatusEdit } from './ChangeEquipmentStatusEdit';
|
||||
export { ChangeEquipmentStatusShow } from './ChangeEquipmentStatusShow';
|
||||
1
frontend/src/resources/change-equipment-status/types.ts
Normal file
1
frontend/src/resources/change-equipment-status/types.ts
Normal file
@@ -0,0 +1 @@
|
||||
export type EquipmentStatus = 'Active' | 'Repair' | 'Reserve' | 'WriteOff';
|
||||
24
frontend/src/resources/equipment/EquipmentCreate.tsx
Normal file
24
frontend/src/resources/equipment/EquipmentCreate.tsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { Create, SimpleForm, TextInput, DateInput, SelectInput } from 'react-admin';
|
||||
|
||||
const statusChoices = [
|
||||
{ id: 'Active', name: 'В эксплуатации' },
|
||||
{ id: 'Repair', name: 'В ремонте' },
|
||||
{ id: 'Reserve', name: 'В резерве' },
|
||||
{ id: 'WriteOff', name: 'Списано' },
|
||||
];
|
||||
|
||||
export const EquipmentCreate = () => (
|
||||
<Create>
|
||||
<SimpleForm>
|
||||
<TextInput source="name" label="Название оборудования" fullWidth required />
|
||||
<TextInput source="serialNumber" label="Заводской (серийный) номер" fullWidth required />
|
||||
<DateInput source="dateOfInspection" label="Дата поверки" />
|
||||
<DateInput source="commissionedAt" label="Дата изготовления" />
|
||||
<SelectInput
|
||||
source="status"
|
||||
label="Текущий статус"
|
||||
choices={statusChoices}
|
||||
/>
|
||||
</SimpleForm>
|
||||
</Create>
|
||||
);
|
||||
25
frontend/src/resources/equipment/EquipmentEdit.tsx
Normal file
25
frontend/src/resources/equipment/EquipmentEdit.tsx
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Edit, SimpleForm, TextInput, DateInput, SelectInput } from 'react-admin';
|
||||
|
||||
const statusChoices = [
|
||||
{ id: 'Active', name: 'В эксплуатации' },
|
||||
{ id: 'Repair', name: 'В ремонте' },
|
||||
{ id: 'Reserve', name: 'В резерве' },
|
||||
{ id: 'WriteOff', name: 'Списано' },
|
||||
];
|
||||
|
||||
export const EquipmentEdit = () => (
|
||||
<Edit>
|
||||
<SimpleForm>
|
||||
<TextInput disabled source="id" label="Идентификатор" />
|
||||
<TextInput source="name" label="Название оборудования" fullWidth />
|
||||
<TextInput source="serialNumber" label="Заводской (серийный) номер" fullWidth />
|
||||
<DateInput source="dateOfInspection" label="Дата поверки" />
|
||||
<DateInput source="commissionedAt" label="Дата изготовления" />
|
||||
<SelectInput
|
||||
source="status"
|
||||
label="Текущий статус"
|
||||
choices={statusChoices}
|
||||
/>
|
||||
</SimpleForm>
|
||||
</Edit>
|
||||
);
|
||||
35
frontend/src/resources/equipment/EquipmentList.tsx
Normal file
35
frontend/src/resources/equipment/EquipmentList.tsx
Normal file
@@ -0,0 +1,35 @@
|
||||
import { List, DataTable, TextField, DateField, EditButton, ShowButton } from 'react-admin';
|
||||
import { EquipmentStatus } from './types';
|
||||
|
||||
const statusChoices = [
|
||||
{ id: 'Active', name: 'В эксплуатации' },
|
||||
{ id: 'Repair', name: 'В ремонте' },
|
||||
{ id: 'Reserve', name: 'В резерве' },
|
||||
{ id: 'WriteOff', name: 'Списано' },
|
||||
];
|
||||
|
||||
const StatusField = ({ source, record }: { source: string; record?: any }) => {
|
||||
const status = record?.[source];
|
||||
const statusLabel = statusChoices.find(choice => choice.id === status)?.name || status;
|
||||
return <span>{statusLabel}</span>;
|
||||
};
|
||||
|
||||
export const EquipmentList = () => (
|
||||
<List>
|
||||
<DataTable>
|
||||
<DataTable.Col source="id" />
|
||||
<DataTable.Col source="name" label="Название" />
|
||||
<DataTable.Col source="serialNumber" label="Серийный номер" />
|
||||
<DataTable.Col source="dateOfInspection" label="Дата поверки" field={DateField} />
|
||||
<DataTable.Col source="commissionedAt" label="Дата изготовления" field={DateField} />
|
||||
<DataTable.Col source="status" label="Статус">
|
||||
<StatusField source="status" />
|
||||
</DataTable.Col>
|
||||
<DataTable.Col source="createdAt" label="Создано" field={DateField} />
|
||||
<DataTable.Col>
|
||||
<ShowButton />
|
||||
<EditButton />
|
||||
</DataTable.Col>
|
||||
</DataTable>
|
||||
</List>
|
||||
);
|
||||
29
frontend/src/resources/equipment/EquipmentShow.tsx
Normal file
29
frontend/src/resources/equipment/EquipmentShow.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import { Show, SimpleShowLayout, TextField, DateField } from 'react-admin';
|
||||
|
||||
const statusChoices = [
|
||||
{ id: 'Active', name: 'В эксплуатации' },
|
||||
{ id: 'Repair', name: 'В ремонте' },
|
||||
{ id: 'Reserve', name: 'В резерве' },
|
||||
{ id: 'WriteOff', name: 'Списано' },
|
||||
];
|
||||
|
||||
const StatusField = ({ source, record }: { source: string; record?: any }) => {
|
||||
const status = record?.[source];
|
||||
const statusLabel = statusChoices.find(choice => choice.id === status)?.name || status;
|
||||
return <span>{statusLabel}</span>;
|
||||
};
|
||||
|
||||
export const EquipmentShow = () => (
|
||||
<Show>
|
||||
<SimpleShowLayout>
|
||||
<TextField source="id" label="Идентификатор" />
|
||||
<TextField source="name" label="Название оборудования" />
|
||||
<TextField source="serialNumber" label="Заводской (серийный) номер" />
|
||||
<DateField source="dateOfInspection" label="Дата поверки" />
|
||||
<DateField source="commissionedAt" label="Дата изготовления" />
|
||||
<StatusField source="status" label="Текущий статус" />
|
||||
<DateField source="createdAt" label="Создано" />
|
||||
<DateField source="updatedAt" label="Обновлено" />
|
||||
</SimpleShowLayout>
|
||||
</Show>
|
||||
);
|
||||
4
frontend/src/resources/equipment/index.ts
Normal file
4
frontend/src/resources/equipment/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export { EquipmentList } from './EquipmentList';
|
||||
export { EquipmentCreate } from './EquipmentCreate';
|
||||
export { EquipmentEdit } from './EquipmentEdit';
|
||||
export { EquipmentShow } from './EquipmentShow';
|
||||
1
frontend/src/resources/equipment/types.ts
Normal file
1
frontend/src/resources/equipment/types.ts
Normal file
@@ -0,0 +1 @@
|
||||
export type EquipmentStatus = 'Active' | 'Repair' | 'Reserve' | 'WriteOff';
|
||||
Reference in New Issue
Block a user