Files
formularios_api/src/trabajadores/trabajadores.controller.ts
T
miguel 74de90eda8 Add xlsx support and enhance Trabajadores module with file upload functionality
- Updated package.json and package-lock.json to include xlsx dependency.
- Enhanced AlumnosService to return UsuarioData type.
- Modified CuestionarioRespondidoService to include event start and end dates in responses.
- Updated TrabajadoresController to add file upload endpoint for processing Excel files.
- Implemented file processing logic in TrabajadoresService to handle worker registration from Excel.
- Created TrabajadorApiDocumentation for API documentation of the new file upload feature.
- Refactored RegistroTrabajador entity to include carrera field and changed num_trabajador type.
2025-06-19 18:36:29 -06:00

70 lines
1.9 KiB
TypeScript

import {
Controller,
Get,
Post,
Body,
Patch,
Param,
Delete,
UseInterceptors,
UploadedFile,
NotFoundException,
} from '@nestjs/common';
import { TrabajadoresService } from './trabajadores.service';
import { CreateTrabajadoreDto } from './dto/create-trabajadore.dto';
import { UpdateTrabajadoreDto } from './dto/update-trabajadore.dto';
import { FileInterceptor } from '@nestjs/platform-express';
import { diskStorage } from 'multer';
import { extname } from 'path';
import { TrabajadorApiDocumentation } from './docs/trabajadores.docs';
@Controller('trabajadores')
@TrabajadorApiDocumentation.ApiController
export class TrabajadoresController {
constructor(private readonly trabajadoresService: TrabajadoresService) {}
@Post('cargar')
@TrabajadorApiDocumentation.ApiCargarArchivo
@UseInterceptors(
FileInterceptor('file', {
storage: diskStorage({
destination: './uploads',
filename: (_, file, callback) => {
const uniqueName = `${Date.now()}${extname(file.originalname)}`;
callback(null, uniqueName);
},
}),
}),
)
async cargarArchivo(@UploadedFile() file: Express.Multer.File) {
return this.trabajadoresService.procesarArchivo(file.path);
}
@Post()
create(@Body() createTrabajadoreDto: CreateTrabajadoreDto) {
return this.trabajadoresService.create(createTrabajadoreDto);
}
@Get(':rfc')
findByRfc(@Param('rfc') rfc: string) {
const trabajador = this.trabajadoresService.findByRfc(rfc);
if (!trabajador) {
throw new NotFoundException(`No se encontró trabajador con RFC ${rfc}`);
}
return trabajador;
}
@Patch(':id')
update(
@Param('id') id: string,
@Body() updateTrabajadoreDto: UpdateTrabajadoreDto,
) {
return this.trabajadoresService.update(+id, updateTrabajadoreDto);
}
@Delete(':id')
remove(@Param('id') id: string) {
return this.trabajadoresService.remove(+id);
}
}