feat: add generated code
This commit is contained in:
@@ -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 { ConfirmationDocumentService } from './confirmation-document.service';
|
||||
import { CreateConfirmationDocumentDto } from './dto/create-confirmation-document.dto';
|
||||
import { UpdateConfirmationDocumentDto } from './dto/update-confirmation-document.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('confirmation-document')
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Controller('confirmation-document')
|
||||
export class ConfirmationDocumentController {
|
||||
constructor(private readonly confirmationDocumentService: ConfirmationDocumentService) {}
|
||||
|
||||
@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.confirmationDocumentService.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.confirmationDocumentService.findOne({ id });
|
||||
}
|
||||
|
||||
@Post()
|
||||
create(@Body() dto: CreateConfirmationDocumentDto) {
|
||||
return this.confirmationDocumentService.create(dto);
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
update(@Param('id') id: string, @Body() dto: UpdateConfirmationDocumentDto) {
|
||||
return this.confirmationDocumentService.update({ where: { id }, data: dto });
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
remove(@Param('id') id: string) {
|
||||
return this.confirmationDocumentService.remove({ id });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfirmationDocumentService } from './confirmation-document.service';
|
||||
import { ConfirmationDocumentController } from './confirmation-document.controller';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
|
||||
@Module({
|
||||
controllers: [ConfirmationDocumentController],
|
||||
providers: [ConfirmationDocumentService, PrismaService],
|
||||
})
|
||||
export class ConfirmationDocumentModule {}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { ConfirmationDocument, Prisma } from '@prisma/client';
|
||||
|
||||
@Injectable()
|
||||
export class ConfirmationDocumentService {
|
||||
constructor(private prisma: PrismaService) {}
|
||||
|
||||
async findAll(params: {
|
||||
skip?: number;
|
||||
take?: number;
|
||||
where?: Prisma.ConfirmationDocumentWhereInput;
|
||||
orderBy?: Prisma.ConfirmationDocumentOrderByWithRelationInput;
|
||||
}): Promise<{ data: ConfirmationDocument[]; total: number }> {
|
||||
const { skip, take, where, orderBy } = params;
|
||||
const [data, total] = await this.prisma.$transaction([
|
||||
this.prisma.confirmationDocument.findMany({ skip, take, where, orderBy }),
|
||||
this.prisma.confirmationDocument.count({ where }),
|
||||
]);
|
||||
return { data, total };
|
||||
}
|
||||
|
||||
async findOne(where: Prisma.ConfirmationDocumentWhereUniqueInput): Promise<ConfirmationDocument | null> {
|
||||
return this.prisma.confirmationDocument.findUnique({ where });
|
||||
}
|
||||
|
||||
async create(data: Prisma.ConfirmationDocumentCreateInput): Promise<ConfirmationDocument> {
|
||||
return this.prisma.confirmationDocument.create({ data });
|
||||
}
|
||||
|
||||
async update(params: {
|
||||
where: Prisma.ConfirmationDocumentWhereUniqueInput;
|
||||
data: Prisma.ConfirmationDocumentUpdateInput;
|
||||
}): Promise<ConfirmationDocument> {
|
||||
return this.prisma.confirmationDocument.update(params);
|
||||
}
|
||||
|
||||
async remove(where: Prisma.ConfirmationDocumentWhereUniqueInput): Promise<ConfirmationDocument> {
|
||||
return this.prisma.confirmationDocument.delete({ where });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Type } from 'class-transformer';
|
||||
import { IsString, IsNotEmpty, IsISO8601, IsOptional, IsBoolean } from 'class-validator';
|
||||
|
||||
export class CreateConfirmationDocumentDto {
|
||||
@ApiProperty({ required: false, description: 'Номер' })
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
number?: string;
|
||||
|
||||
@ApiProperty({ description: 'Дата согласования' })
|
||||
@IsISO8601()
|
||||
@Type(() => Date)
|
||||
date: Date;
|
||||
|
||||
@ApiProperty({ required: false, description: 'Код руководителя' })
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
managerCode?: string;
|
||||
|
||||
@ApiProperty({ description: 'Идентификатор заявки' })
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
orderId: string;
|
||||
|
||||
@ApiProperty({ required: false, description: 'Согласовано/Не согласовано' })
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
confirmed?: boolean;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
import { PartialType } from '@nestjs/mapped-types';
|
||||
import { CreateConfirmationDocumentDto } from './create-confirmation-document.dto';
|
||||
|
||||
export class UpdateConfirmationDocumentDto extends PartialType(CreateConfirmationDocumentDto) {}
|
||||
Reference in New Issue
Block a user