no subir archivos
This commit is contained in:
@@ -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 } });
|
||||
})
|
||||
|
||||
@@ -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 });
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user