Files
2022-01-02 18:36:46 -06:00

71 lines
2.0 KiB
JavaScript

const helperPath = '../../helper';
const drive = require(`${helperPath}/drive`);
const validar = require(`${helperPath}/validar`);
const Servicio = require('../../db/tablas/Servicio');
const cartaTermino = async (body, file) => {
const idServicio = validar.validarNumeroEntero(
body.idServicio,
'id servicio'
);
const path = `./server/uploads/${validar.validacionBasicaStr(
file,
'archivo',
true,
1000
)}`;
return Servicio.findOne({
where: { idServicio },
})
.then((res) => {
if (!res) throw new Error('Este servicio no existe.');
if (res.cartaAceptacion)
throw new Error('Ya se subio la Carta de Aceptación.');
switch (res.idStatus) {
case 7:
return drive.uploadFile(
path,
`Carta_Aceptacion.pdf`,
'application/pdf',
res.carpeta
);
case 1:
throw new Error(
'Esta linea de la API solo puede ser usada cuando es estatus del Servicio Social sea 7.'
);
case 2:
case 3:
case 4:
case 5:
throw new Error(
'Este Servicio Social ya paso la fase de subir la Carta de Aceptación.'
);
case 6:
throw new Error('Este Servicio Social ya finalizó.');
case 8:
case 9:
throw new Error(
'Este Servicio Social se encuentra rechazado. No se puede avanzar hasta que se corriga lo necesario.'
);
case 10:
throw new Error(
'Este Servicio Social fue cancelado. Comunicate con COESI para solucionar tu problema.'
);
default:
throw new Error('Id status no valido.');
}
})
.then((res) =>
Servicio.update(
{ cartaAceptacion: res, idStatus: 1 },
{ where: { idServicio } }
)
)
.then((res) => ({
message: `Se subio la Carta de Aceptación correctamente.`,
}));
};
module.exports = cartaTermino;