se agrego drive correctamente
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
Injectable,
|
||||
InternalServerErrorException,
|
||||
NotFoundException,
|
||||
} from '@nestjs/common';
|
||||
import { CrearServicioDto } from './dto/create-servicio.dto';
|
||||
@@ -358,13 +359,10 @@ export class ServicioService {
|
||||
idServicioParam: number,
|
||||
archivo: Express.Multer.File,
|
||||
): Promise<{ message: string }> {
|
||||
// 🔹 Validar idServicio
|
||||
const idServicio: number = this.validacionService.validarNumeroEntero(
|
||||
idServicioParam,
|
||||
'id servicio',
|
||||
);
|
||||
|
||||
// Agregue estas lineas
|
||||
const idServicio: number =
|
||||
this.validacionService.validarNumeroEntero(idServicioParam, 'id servicio');
|
||||
|
||||
if (!archivo) {
|
||||
throw new BadRequestException('No se recibió el archivo');
|
||||
}
|
||||
@@ -374,17 +372,7 @@ export class ServicioService {
|
||||
}
|
||||
|
||||
const rutaArchivo = `./server/uploads/${archivo.filename}`;
|
||||
// Hasta aqui termine de agregar las lineas
|
||||
|
||||
// 🔹 Validar archivo y generar path local
|
||||
// const rutaArchivo: string = `./server/uploads/${this.validacionService.validacionBasicaStr(
|
||||
// archivo,
|
||||
// 'archivo',
|
||||
// true,
|
||||
// 1000,
|
||||
// )}`;
|
||||
|
||||
// 🔹 Buscar servicio
|
||||
const servicio = await this.servicioRepo.findOne({
|
||||
where: { idServicio },
|
||||
relations: ['status'],
|
||||
@@ -394,22 +382,30 @@ export class ServicioService {
|
||||
throw new NotFoundException('Este servicio no existe.');
|
||||
}
|
||||
|
||||
if (!servicio.status?.idStatus) {
|
||||
throw new BadRequestException('El servicio no tiene un status válido.');
|
||||
}
|
||||
|
||||
if (servicio.cartaTermino) {
|
||||
throw new BadRequestException('Ya se subió la Carta de Termino.');
|
||||
}
|
||||
|
||||
// 🔹 Validar status y subir archivo si corresponde
|
||||
let archivoSubido;
|
||||
let archivoSubido: string;
|
||||
|
||||
switch (servicio.status.idStatus) {
|
||||
case 4:
|
||||
case 8:
|
||||
archivoSubido = await this.driveService.uploadFile(
|
||||
rutaArchivo,
|
||||
'Carta_Termino.pdf',
|
||||
'application/pdf',
|
||||
servicio.carpeta,
|
||||
);
|
||||
try {
|
||||
archivoSubido = await this.driveService.uploadFile(
|
||||
rutaArchivo,
|
||||
'Carta_Termino.pdf',
|
||||
'application/pdf',
|
||||
servicio.carpeta,
|
||||
);
|
||||
} catch (err) {
|
||||
if (fs.existsSync(rutaArchivo)) fs.unlinkSync(rutaArchivo);
|
||||
throw err;
|
||||
}
|
||||
break;
|
||||
|
||||
case 1:
|
||||
@@ -427,29 +423,33 @@ export class ServicioService {
|
||||
case 7:
|
||||
case 9:
|
||||
throw new BadRequestException(
|
||||
'Este Servicio Social se encuentra rechazado. No se puede avanzar hasta que se corrija lo necesario.',
|
||||
'Este Servicio Social se encuentra rechazado.',
|
||||
);
|
||||
case 10:
|
||||
throw new BadRequestException(
|
||||
'Este Servicio Social está cancelado. Comunícate con COESI para solucionar tu problema.',
|
||||
'Este Servicio Social está cancelado.',
|
||||
);
|
||||
default:
|
||||
throw new BadRequestException('Id status no válido.');
|
||||
}
|
||||
|
||||
// 🔹 Actualizar el servicio con la carta subida
|
||||
await this.servicioRepo.update(idServicio, { cartaTermino: archivoSubido });
|
||||
if (!archivoSubido) {
|
||||
throw new InternalServerErrorException('Error al subir archivo.');
|
||||
}
|
||||
|
||||
await this.servicioRepo.update(idServicio, {
|
||||
cartaTermino: archivoSubido,
|
||||
});
|
||||
|
||||
// 🔹 Ejecutar validaciones adicionales (pre-termino)
|
||||
const resultadoPreTermino =
|
||||
await this.validacionService.validarPreTermino(idServicio);
|
||||
|
||||
// 🔹 Retornar mensaje
|
||||
return {
|
||||
message: `Se subió la Carta de Termino correctamente. ${resultadoPreTermino}`,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
async generarGustavoBazPrada(yearParam: number): Promise<string> {
|
||||
// 🔹 Validar año
|
||||
const year: number = this.validacionService.validarNumero(
|
||||
|
||||
Reference in New Issue
Block a user