Files
servicio_social_api/server/controller/Servicio/cartaAceptacion.js
T

60 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-11-29 17:27:25 -06:00
const validar = require('../../helper/validar');
const drive = require('../../helper/drive');
const Servicio = require('../../db/tablas/Servicio');
const cartaTermino = async (body, file) => {
2021-01-14 03:13:37 -06:00
const idServicio = validar.validarId(body.idServicio);
const path = `./server/uploads/${validar.validar(file, 'El archivo', 1000)}`;
2020-11-29 17:27:25 -06:00
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,
2020-12-08 18:43:06 -06:00
`Carta_Aceptacion.pdf`,
2020-11-29 17:27:25 -06:00
'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.'
);
}
})
2021-01-12 21:09:37 -06:00
.then((res) =>
Servicio.update(
2020-12-08 18:43:06 -06:00
{ cartaAceptacion: res, idStatus: 1 },
{ where: { idServicio } }
2021-01-12 21:09:37 -06:00
)
)
2021-01-14 16:02:57 -06:00
.then((res) => ({
message: `Se subio la Carta de Aceptación correctamente.`,
}));
2020-11-29 17:27:25 -06:00
};
module.exports = cartaTermino;