mejoras al formulario de registro organizaciones productivas
This commit is contained in:
@@ -1,68 +1,114 @@
|
||||
import { Controller, Get, Post, Body, Patch, Param, Delete, Query } from '@nestjs/common';
|
||||
import { TrainingService } from './training.service';
|
||||
import { CreateTrainingDto } from './dto/create-training.dto';
|
||||
import { UpdateTrainingDto } from './dto/update-training.dto';
|
||||
import { ApiOperation, ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Patch,
|
||||
Post,
|
||||
Query,
|
||||
UploadedFiles,
|
||||
UseInterceptors,
|
||||
} from '@nestjs/common';
|
||||
import { FilesInterceptor } from '@nestjs/platform-express';
|
||||
import {
|
||||
ApiConsumes,
|
||||
ApiOperation,
|
||||
ApiResponse,
|
||||
ApiTags,
|
||||
} from '@nestjs/swagger';
|
||||
import { PaginationDto } from '../../common/dto/pagination.dto';
|
||||
|
||||
import { ImageProcessingPipe } from '../../common/pipes/image-processing.pipe';
|
||||
import { CreateTrainingDto } from './dto/create-training.dto';
|
||||
import { TrainingStatisticsFilterDto } from './dto/training-statistics-filter.dto';
|
||||
import { UpdateTrainingDto } from './dto/update-training.dto';
|
||||
import { TrainingService } from './training.service';
|
||||
|
||||
@ApiTags('training')
|
||||
@Controller('training')
|
||||
export class TrainingController {
|
||||
constructor(private readonly trainingService: TrainingService) { }
|
||||
constructor(private readonly trainingService: TrainingService) {}
|
||||
|
||||
@Get()
|
||||
@ApiOperation({ summary: 'Get all training records with pagination and filters' })
|
||||
@ApiResponse({ status: 200, description: 'Return paginated training records.' })
|
||||
async findAll(@Query() paginationDto: PaginationDto) {
|
||||
const result = await this.trainingService.findAll(paginationDto);
|
||||
return {
|
||||
message: 'Training records fetched successfully',
|
||||
data: result.data,
|
||||
meta: result.meta
|
||||
};
|
||||
}
|
||||
@Get()
|
||||
@ApiOperation({
|
||||
summary: 'Get all training records with pagination and filters',
|
||||
})
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Return paginated training records.',
|
||||
})
|
||||
async findAll(@Query() paginationDto: PaginationDto) {
|
||||
const result = await this.trainingService.findAll(paginationDto);
|
||||
return {
|
||||
message: 'Training records fetched successfully',
|
||||
data: result.data,
|
||||
meta: result.meta,
|
||||
};
|
||||
}
|
||||
|
||||
@Get('statistics')
|
||||
@ApiOperation({ summary: 'Get training statistics' })
|
||||
@ApiResponse({ status: 200, description: 'Return training statistics.' })
|
||||
async getStatistics(@Query() filterDto: TrainingStatisticsFilterDto) {
|
||||
const data = await this.trainingService.getStatistics(filterDto);
|
||||
return { message: 'Training statistics fetched successfully', data };
|
||||
}
|
||||
@Get('statistics')
|
||||
@ApiOperation({ summary: 'Get training statistics' })
|
||||
@ApiResponse({ status: 200, description: 'Return training statistics.' })
|
||||
async getStatistics(@Query() filterDto: TrainingStatisticsFilterDto) {
|
||||
const data = await this.trainingService.getStatistics(filterDto);
|
||||
return { message: 'Training statistics fetched successfully', data };
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get a training record by ID' })
|
||||
@ApiResponse({ status: 200, description: 'Return the training record.' })
|
||||
@ApiResponse({ status: 404, description: 'Training record not found.' })
|
||||
async findOne(@Param('id') id: string) {
|
||||
const data = await this.trainingService.findOne(+id);
|
||||
return { message: 'Training record fetched successfully', data };
|
||||
}
|
||||
@Get(':id')
|
||||
@ApiOperation({ summary: 'Get a training record by ID' })
|
||||
@ApiResponse({ status: 200, description: 'Return the training record.' })
|
||||
@ApiResponse({ status: 404, description: 'Training record not found.' })
|
||||
async findOne(@Param('id') id: string) {
|
||||
const data = await this.trainingService.findOne(+id);
|
||||
return { message: 'Training record fetched successfully', data };
|
||||
}
|
||||
|
||||
@Post()
|
||||
@ApiOperation({ summary: 'Create a new training record' })
|
||||
@ApiResponse({ status: 201, description: 'Training record created successfully.' })
|
||||
async create(@Body() createTrainingDto: CreateTrainingDto) {
|
||||
const data = await this.trainingService.create(createTrainingDto);
|
||||
return { message: 'Training record created successfully', data };
|
||||
}
|
||||
@Post()
|
||||
@UseInterceptors(FilesInterceptor('files', 3))
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@ApiOperation({ summary: 'Create a new training record' })
|
||||
@ApiResponse({
|
||||
status: 201,
|
||||
description: 'Training record created successfully.',
|
||||
})
|
||||
async create(
|
||||
@Body() createTrainingDto: CreateTrainingDto,
|
||||
@UploadedFiles(ImageProcessingPipe) files: Express.Multer.File[],
|
||||
) {
|
||||
const data = await this.trainingService.create(createTrainingDto, files);
|
||||
return { message: 'Training record created successfully', data };
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
@ApiOperation({ summary: 'Update a training record' })
|
||||
@ApiResponse({ status: 200, description: 'Training record updated successfully.' })
|
||||
@ApiResponse({ status: 404, description: 'Training record not found.' })
|
||||
async update(@Param('id') id: string, @Body() updateTrainingDto: UpdateTrainingDto) {
|
||||
const data = await this.trainingService.update(+id, updateTrainingDto);
|
||||
return { message: 'Training record updated successfully', data };
|
||||
}
|
||||
@Patch(':id')
|
||||
@UseInterceptors(FilesInterceptor('files', 3))
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@ApiOperation({ summary: 'Update a training record' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Training record updated successfully.',
|
||||
})
|
||||
@ApiResponse({ status: 404, description: 'Training record not found.' })
|
||||
async update(
|
||||
@Param('id') id: string,
|
||||
@Body() updateTrainingDto: UpdateTrainingDto,
|
||||
@UploadedFiles(ImageProcessingPipe) files: Express.Multer.File[],
|
||||
) {
|
||||
const data = await this.trainingService.update(
|
||||
+id,
|
||||
updateTrainingDto,
|
||||
files,
|
||||
);
|
||||
return { message: 'Training record updated successfully', data };
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete a training record' })
|
||||
@ApiResponse({ status: 200, description: 'Training record deleted successfully.' })
|
||||
@ApiResponse({ status: 404, description: 'Training record not found.' })
|
||||
async remove(@Param('id') id: string) {
|
||||
return await this.trainingService.remove(+id);
|
||||
}
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Delete a training record' })
|
||||
@ApiResponse({
|
||||
status: 200,
|
||||
description: 'Training record deleted successfully.',
|
||||
})
|
||||
@ApiResponse({ status: 404, description: 'Training record not found.' })
|
||||
async remove(@Param('id') id: string) {
|
||||
return await this.trainingService.remove(+id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user