no subir archivos

This commit is contained in:
2021-03-02 10:30:47 -06:00
parent 699fa144cd
commit 280ab38ba6
2 changed files with 5 additions and 18 deletions
+3 -11
View File
@@ -1,21 +1,13 @@
const drive = require('../../helper/drive');
const validar = require('../../helper/validar');
const CasoEspecial = require('../../db/tablas/CasoEspecial');
const update = async (body, file) => {
const update = async (body) => {
const idCasoEspecial = validar.validarId(body.idCasoEspecial);
const dataUpdate = {};
return CasoEspecial.findOne({ where: { idCasoEspecial } })
.then(async (res) => {
if (!res) throw new Error('Este Caso Especiaal no existe en la db.');
if (file)
dataUpdate.archivoZip = await drive.uploadFile(
`./server/uploads/${file}`,
`archivos.pdf`,
'application/zip',
res.carpeta
);
if (!res) throw new Error('Este Caso Especial no existe en la db.');
if (body.correo) dataUpdate.correo = validar.validarCorreo(body.correo);
if (body.fechaInicio)
dataUpdate.fechaInicio = validar.validarFecha(body.fechaInicio);
@@ -51,7 +43,7 @@ const update = async (body, file) => {
);
if (validar.isObjectEmpty(dataUpdate))
throw new Error(
'No se envio nada para actualizar este Caso Especiaal.'
'No se envio nada para actualizar este Caso Especial.'
);
return CasoEspecial.update(dataUpdate, { where: { idCasoEspecial } });
})
+2 -7
View File
@@ -76,17 +76,12 @@ app.put(
app.put(
`${route}/update`,
// verificaToken,
upload.single('archivos'),
(req, res) => {
return update(
JSON.parse(req.body.alumno),
req.file ? req.file.filename : ''
)
return update(req.body)
.then((data) => {
res.status(201).json(data);
res.status(200).json(data);
})
.catch((err) => {
if (req.file) eliminarArchivo(req.file.filename);
res.status(400).json({ message: err.message });
});
}