215 lines
6.1 KiB
TypeScript
215 lines
6.1 KiB
TypeScript
import {
|
|
Controller,
|
|
Get,
|
|
Post,
|
|
Put,
|
|
Body,
|
|
Query,
|
|
UploadedFile,
|
|
UploadedFiles,
|
|
UseGuards,
|
|
UseInterceptors,
|
|
Res,
|
|
ParseIntPipe,
|
|
Param,
|
|
Req,
|
|
} from '@nestjs/common';
|
|
import {
|
|
FileInterceptor,
|
|
FileFieldsInterceptor,
|
|
} from '@nestjs/platform-express';
|
|
import { ServicioService } from './servicio.service';
|
|
import { AuthGuard } from '@nestjs/passport';
|
|
import { CrearServicioDto } from './dto/create-servicio.dto';
|
|
import { Response } from 'express';
|
|
import { ServiciosAdminDto } from './dto/servicios-admin.dto';
|
|
import { ServiciosResponsableDto } from './dto/servicios-responsable.dto';
|
|
import { RegistroValidadoDto } from './dto/registro-validado.dto';
|
|
import { multerConfig } from './multer';
|
|
|
|
@Controller('servicio')
|
|
export class ServicioController {
|
|
constructor(private readonly servicioService: ServicioService) { }
|
|
|
|
// ------------------ POST ------------------
|
|
|
|
// Garegue un nuevo endpoint para hacer pruebas
|
|
@Post('test-upload')
|
|
@UseInterceptors(FileInterceptor('file'))
|
|
uploadTest(
|
|
@UploadedFile() file: Express.Multer.File,
|
|
@Req() req: any,
|
|
) {
|
|
console.log('FILE:', file);
|
|
console.log('FILES REQ:', req.file);
|
|
console.log('FILES BODY:', req.body);
|
|
return { ok: true };
|
|
}
|
|
|
|
@Post('registro-validado')
|
|
async registroValidado(
|
|
@Body() dto: RegistroValidadoDto,
|
|
): Promise<{ message: string }> {
|
|
return this.servicioService.registroValidado(dto);
|
|
}
|
|
|
|
@Post('nuevo')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@UseInterceptors(FileInterceptor('cartaAceptacion'))
|
|
async crearServicio(
|
|
@UploadedFile() file: Express.Multer.File,
|
|
@Body('alumno') alumnoJson: string,
|
|
) {
|
|
const dto: CrearServicioDto = JSON.parse(alumnoJson);
|
|
|
|
console.log('Archivo recibido:', file);
|
|
|
|
return await this.servicioService.registrarNuevoServicio(dto, file);
|
|
}
|
|
|
|
// ------------------ GET ------------------
|
|
|
|
@Get('todos')
|
|
//@UseGuards(AuthGuard('jwt'))
|
|
async obtenerTodosLosServicios() {
|
|
return this.servicioService.obtenerTodosLosServicios();
|
|
}
|
|
|
|
@Get('admin')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
async obtenerServiciosAdmin(@Query() dto: ServiciosAdminDto) {
|
|
return await this.servicioService.obtenerServiciosAdmin(dto);
|
|
}
|
|
|
|
@Get('servicios_responsable')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
async obtenerServiciosResponsable(@Query() dto: ServiciosResponsableDto) {
|
|
return await this.servicioService.obtenerServiciosResponsable(dto);
|
|
}
|
|
|
|
@Get('admin/:idServicio')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
async obtenerAdmin(@Param('idServicio') idServicio: number) {
|
|
return this.servicioService.obtenerDetalleServicio(idServicio);
|
|
}
|
|
|
|
@Get('alumno')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
async obtenerAlumno(@Query('idUsuario', ParseIntPipe) idUsuario: number) {
|
|
return this.servicioService.obtenerServicioAlumno(idUsuario);
|
|
}
|
|
|
|
@Get('gustavo_baz_prada')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
async gustavoBaz(
|
|
@Query('year', ParseIntPipe) year: number,
|
|
@Res() res: Response,
|
|
) {
|
|
const path = await this.servicioService.generarGustavoBazPrada(year);
|
|
return res.download(path);
|
|
}
|
|
|
|
// Corregi el endpoint tenia llamando a otrea funcion
|
|
@Get('reporte')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
async generarReporte(
|
|
@Query('inicio') inicio: string,
|
|
@Query('fin') fin: string,
|
|
@Res() res: Response) {
|
|
const path = await this.servicioService.generarReporte(inicio, fin);
|
|
return res.download(path);
|
|
}
|
|
|
|
// ------------------ PUT ------------------
|
|
|
|
@Put('cancelar')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
async cancelar(@Body() body: { idServicio: number; mensaje: string }) {
|
|
return this.servicioService.cancelarServicio(body);
|
|
}
|
|
|
|
@Put('carta_aceptacion')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@UseInterceptors(FileInterceptor('cartaAceptacion'))
|
|
async subirCartaAceptacion(
|
|
@UploadedFile() file: Express.Multer.File,
|
|
@Body('data') dataJson: string,
|
|
) {
|
|
const body = JSON.parse(dataJson);
|
|
console.log('file:', file)
|
|
return this.servicioService.cartaTermino(body.idServicio, file);
|
|
}
|
|
|
|
@Put('carta_termino')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@UseInterceptors(FileInterceptor('cartaTermino'))
|
|
async subirCartaTermino(
|
|
@UploadedFile() file: Express.Multer.File,
|
|
@Body('data') dataJson: string,
|
|
) {
|
|
const body = JSON.parse(dataJson);
|
|
console.log("file", file);
|
|
return this.servicioService.subirCartaTermino(body.idServicio, file);
|
|
}
|
|
|
|
@Put('informe_global')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@UseInterceptors(FileInterceptor('informeGlobal'))
|
|
async subirInformeGlobal(
|
|
@UploadedFile() file: Express.Multer.File,
|
|
@Body('data') dataJson: string,
|
|
) {
|
|
const body = JSON.parse(dataJson);
|
|
return this.servicioService.subirInformeGlobal(body.idServicio, file);
|
|
}
|
|
|
|
@Put('liberacion')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
async liberarServicio(
|
|
@Body('idServicio', ParseIntPipe) idServicio: number,
|
|
@Body('vistoBuenoAcatlan') vistoBuenoAcatlan: boolean,
|
|
) {
|
|
return this.servicioService.liberarServicio(idServicio, vistoBuenoAcatlan);
|
|
}
|
|
|
|
@Put('rechazar_aceptacion')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
async rechazarAceptacion(
|
|
@Body() body: { idServicio: number; mensaje: string },
|
|
) {
|
|
return this.servicioService.rechazar(body.idServicio, body.mensaje);
|
|
}
|
|
|
|
@Put('rechazar_informe')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
async rechazarInforme(@Body() body: { idServicio: number; mensaje: string }) {
|
|
return this.servicioService.rechazarInforme(body.idServicio, body.mensaje);
|
|
}
|
|
|
|
@Put('rechazar_termino')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
async rechazarTermino(@Body() body: { idServicio: number; mensaje: string }) {
|
|
return this.servicioService.rechazarTermino(body.idServicio, body.mensaje);
|
|
}
|
|
|
|
@Put('update')
|
|
@UseGuards(AuthGuard('jwt'))
|
|
@UseInterceptors(
|
|
FileFieldsInterceptor([
|
|
{ name: 'cartaAceptacion', maxCount: 1 },
|
|
{ name: 'cartaTermino', maxCount: 1 },
|
|
{ name: 'informeGlobal', maxCount: 1 },
|
|
], multerConfig,),
|
|
|
|
)
|
|
async actualizarServicio(
|
|
@UploadedFiles() files: Record<string, Express.Multer.File[]>,
|
|
@Body('data') dataJson: string,
|
|
) {
|
|
const data = JSON.parse(dataJson);
|
|
|
|
return this.servicioService.update(data, files);
|
|
}
|
|
|
|
}
|