listo
This commit is contained in:
@@ -24,4 +24,4 @@ try {
|
||||
|
||||
// process.env.SALT_ROUNDS = process.env.SALT_ROUNDS
|
||||
|
||||
process.env.CADUCIDAD_TOKEN = 60 * 30 ;
|
||||
process.env.CADUCIDAD_TOKEN = 1800000;
|
||||
|
||||
@@ -8,7 +8,7 @@ const Programa = require('../../db/tablas/Programa');
|
||||
const registroValidado = async (body) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let fechaNacimiento = validar.validarFecha(body.fechaNacimiento);
|
||||
let telefono = validar.validarNumero(body.telefono, 10);
|
||||
let telefono = validar.validarNumero(body.telefono, 15);
|
||||
let direccion = validar.validarAlfanumerico(
|
||||
body.direccion,
|
||||
'La dirección',
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
const drive = require('../../helper/drive');
|
||||
const validar = require('../../helper/validar');
|
||||
const Servicio = require('../../db/tablas/Servicio');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
|
||||
const update = async (body, files) => {
|
||||
let idServicio = validar.validarId(body.idServicio);
|
||||
let dataUpdate = {};
|
||||
|
||||
return Servicio.findOne({ where: { idServicio } })
|
||||
.then(async (res) => {
|
||||
if (!res) throw new Error('Este Servicio Social no existe en la db.');
|
||||
|
||||
try {
|
||||
if (files['cartaAceptacion'][0].filename)
|
||||
dataUpdate.cartaAceptacion = await drive.uploadFile(
|
||||
`./server/uploads/${files['cartaAceptacion'][0].filename}`,
|
||||
`Carta_Aceptacion.pdf`,
|
||||
'application/pdf',
|
||||
res.carpeta
|
||||
);
|
||||
if (files['cartaTermino'][0].filename)
|
||||
dataUpdate.cartaTermino = await drive.uploadFile(
|
||||
`./server/uploads/${files['cartaTermino'][0].filename}`,
|
||||
`Carta_Termino.pdf`,
|
||||
'application/pdf',
|
||||
res.carpeta
|
||||
);
|
||||
if (files['informeGlobal'][0].filename)
|
||||
dataUpdate.informeGlobal = await drive.uploadFile(
|
||||
`./server/uploads/${files['informeGlobal'][0].filename}`,
|
||||
`Informe_Global.pdf`,
|
||||
'application/pdf',
|
||||
res.carpeta
|
||||
);
|
||||
} catch (err) {}
|
||||
if (body.correo) dataUpdate.correo = validar.validarCorreo(body.correo);
|
||||
if (body.fechaInicio)
|
||||
dataUpdate.fechaInicio = validar.validarFecha(body.fechaInicio);
|
||||
if (body.fechaFin)
|
||||
dataUpdate.fechaFin = validar.validarFecha(body.fechaFin);
|
||||
if (body.fechaNacimiento)
|
||||
dataUpdate.fechaNacimiento = validar.validarFecha(body.fechaNacimiento);
|
||||
if (body.direccion)
|
||||
dataUpdate.direccion = validar.validarAlfanumerico(
|
||||
body.direccion,
|
||||
'La dirección',
|
||||
200
|
||||
);
|
||||
if (body.telefono)
|
||||
dataUpdate.telefono = validar.validarNumero(body.telefono, 15);
|
||||
|
||||
if (validar.isObjectEmpty(dataUpdate))
|
||||
throw new Error(
|
||||
'No se envio nada para actualizar este Servicio Social'
|
||||
);
|
||||
return Servicio.update(dataUpdate, { where: { idServicio } });
|
||||
})
|
||||
.then((res) => {
|
||||
return {
|
||||
message: 'Se guadro correctamente los cambios de este servicio.',
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = update;
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
const { Op } = require('sequelize');
|
||||
const validar = require('../../helper/validar');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
|
||||
const responsableUpdate = async (body) => {
|
||||
let isObjectEmpty = (obj) => {
|
||||
for (let key in obj) {
|
||||
if (obj.hasOwnProperty(key)) return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
let idUsuario = validar.validarId(body.idUsuario);
|
||||
let dataUpdate = {};
|
||||
|
||||
@@ -18,24 +13,20 @@ const responsableUpdate = async (body) => {
|
||||
if (res.idTipoUsuario !== 2)
|
||||
throw new Error('No es un usuaior de tipo responasble.');
|
||||
if (body.correo) {
|
||||
let yaUsado = await Usuario.findOne({
|
||||
where: { usuario: body.correo },
|
||||
}).then((res) => res);
|
||||
const yaUsado = await Usuario.findOne({
|
||||
where: { usuario: body.correo, idUsuario: { [Op.not]: idUsuario } },
|
||||
});
|
||||
|
||||
if (body.correo === res.usuario)
|
||||
throw new Error('El responable ya tiene ese correo asignado.');
|
||||
if (yaUsado)
|
||||
throw new Error(
|
||||
'No se puede asignar este correo a esta cuenta porque esta siendo ocupado por otro resposanble.'
|
||||
);
|
||||
dataUpdate.usuario = validar.validarCorreo(body.correo);
|
||||
}
|
||||
if (body.nombre) {
|
||||
if (body.nombre === res.nombre)
|
||||
throw new Error('El responable ya tiene ese nombre asignado.');
|
||||
if (body.nombre)
|
||||
dataUpdate.nombre = validar.validarTexto(body.nombre, 'el nombre', 70);
|
||||
}
|
||||
if (isObjectEmpty(dataUpdate))
|
||||
|
||||
if (validar.isObjectEmpty(dataUpdate))
|
||||
throw new Error('No se a envio nada para actualizar.');
|
||||
return Usuario.update(dataUpdate, { where: { idUsuario } });
|
||||
})
|
||||
|
||||
@@ -120,6 +120,13 @@ const validarPreTermino = (idServicio) => {
|
||||
});
|
||||
};
|
||||
|
||||
const isObjectEmpty = (obj) => {
|
||||
for (let key in obj) {
|
||||
if (obj.hasOwnProperty(key)) return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
validar,
|
||||
noValido,
|
||||
@@ -133,4 +140,5 @@ module.exports = {
|
||||
validarFecha,
|
||||
validarNumero,
|
||||
validarPreTermino,
|
||||
isObjectEmpty,
|
||||
};
|
||||
|
||||
@@ -19,6 +19,7 @@ const verificaToken = (req, res, next) => {
|
||||
};
|
||||
|
||||
const crearToken = (info) => {
|
||||
console.log(process.env.CADUCIDAD_TOKEN)
|
||||
return jwt.sign({ info }, process.env.KEY, {
|
||||
expiresIn: process.env.CADUCIDAD_TOKEN,
|
||||
});
|
||||
|
||||
@@ -20,6 +20,11 @@ const liberacion = require('../controller/Servicio/liberacion');
|
||||
const rechazarAceptacion = require('../controller/Servicio/rechazarAceptacion');
|
||||
const rechazarTermino = require('../controller/Servicio/rechazarTermino');
|
||||
const rechazarInforme = require('../controller/Servicio/rechazarInforme');
|
||||
const update = require('../controller/Servicio/update');
|
||||
|
||||
const eliminarArchivo = (filename) => {
|
||||
fs.unlinkSync(`./server/uploads/${filename}`);
|
||||
};
|
||||
|
||||
app.post(
|
||||
`${route}/nuevo`,
|
||||
@@ -31,8 +36,8 @@ app.post(
|
||||
res.status(201).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (req.file.filename)
|
||||
fs.unlinkSync(`./server/uploads/${req.file.filename}`);
|
||||
if (req.file.filename) eliminarArchivo(req.file.filename);
|
||||
// fs.unlinkSync(`./server/uploads/${req.file.filename}`);
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
@@ -118,8 +123,8 @@ app.put(
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (req.file.filename)
|
||||
fs.unlinkSync(`./server/uploads/${req.file.filename}`);
|
||||
if (req.file.filename) eliminarArchivo(req.file.filename);
|
||||
// fs.unlinkSync(`./server/uploads/${req.file.filename}`);
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
@@ -135,8 +140,8 @@ app.put(
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (req.file.filename)
|
||||
fs.unlinkSync(`./server/uploads/${req.file.filename}`);
|
||||
if (req.file.filename) eliminarArchivo(req.file.filename);
|
||||
// fs.unlinkSync(`./server/uploads/${req.file.filename}`);
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
@@ -152,8 +157,8 @@ app.put(
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (req.file.filename)
|
||||
fs.unlinkSync(`./server/uploads/${req.file.filename}`);
|
||||
if (req.file.filename) eliminarArchivo(req.file.filename);
|
||||
// fs.unlinkSync(`./server/uploads/${req.file.filename}`);
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
@@ -199,4 +204,29 @@ app.put(`${route}/rechazar_informe`, verificaToken, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.put(
|
||||
`${route}/update`,
|
||||
// verificaToken ,
|
||||
upload.fields([
|
||||
{ name: 'cartaAceptacion', maxCount: 1 },
|
||||
{ name: 'cartaTermino', maxCount: 1 },
|
||||
{ name: 'informeGlobal', maxCount: 1 },
|
||||
]),
|
||||
(req, res) => {
|
||||
return update(JSON.parse(req.body.data), req.files)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (req.files['cartaAceptacion'][0].filename)
|
||||
eliminarArchivo(req.files['cartaAceptacion'][0].filename);
|
||||
if (req.files['cartaTermino'][0].filename)
|
||||
eliminarArchivo(req.files['cartaTermino'][0].filename);
|
||||
if (req.files['informeGlobal'][0].filename)
|
||||
eliminarArchivo(req.files['informeGlobal'][0].filename);
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = app;
|
||||
|
||||
Reference in New Issue
Block a user