update caso especial
This commit is contained in:
@@ -11,6 +11,7 @@ const nuevo = async (body, file) => {
|
||||
const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
|
||||
const creditos = validar.validarNumero(body.creditos);
|
||||
const correo = validar.validarCorreo(body.correo);
|
||||
const telefono = validar.validarNumero(body.telefono, 15);
|
||||
const fechaInicio = validar.validarFecha(body.fechaInicio);
|
||||
const fechaFin = validar.validarFecha(body.fechaFin);
|
||||
const fechaNacimiento = validar.validarFecha(body.fechaNacimiento);
|
||||
@@ -20,10 +21,10 @@ const nuevo = async (body, file) => {
|
||||
200
|
||||
);
|
||||
const institucion = body.institucion
|
||||
? validar.validarTexto(body.institucion, 'El texto institucion.', 100)
|
||||
? validar.validarTexto(body.institucion, 'El texto institucion.', 200)
|
||||
: '';
|
||||
const dependencia = body.dependencia
|
||||
? validar.validarTexto(body.dependencia, 'El texto dependencia.', 100)
|
||||
? validar.validarTexto(body.dependencia, 'El texto dependencia.', 200)
|
||||
: '';
|
||||
const motivo = body.motivo
|
||||
? validar.validarNumero(body.motivo, 'El texto motivo.', 1)
|
||||
@@ -52,12 +53,7 @@ const nuevo = async (body, file) => {
|
||||
})
|
||||
.then((res) => {
|
||||
carpeta = res;
|
||||
return drive.uploadFile(
|
||||
path,
|
||||
`archivos.zip`,
|
||||
'application/zip',
|
||||
carpeta
|
||||
);
|
||||
return drive.uploadFile(path, `archivos.zip`, 'application/zip', carpeta);
|
||||
})
|
||||
.then((res) =>
|
||||
CasoEspecial.create({
|
||||
@@ -66,6 +62,7 @@ const nuevo = async (body, file) => {
|
||||
idStatus,
|
||||
creditos,
|
||||
correo,
|
||||
telefono,
|
||||
institucion,
|
||||
dependencia,
|
||||
motivo,
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
const drive = require('../../helper/drive');
|
||||
const validar = require('../../helper/validar');
|
||||
const CasoEspecial = require('../../db/tablas/CasoEspecial');
|
||||
|
||||
const update = async (body, file) => {
|
||||
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 (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 (body.institucion)
|
||||
dataUpdate.institucion = validar.validarTexto(
|
||||
body.institucion,
|
||||
'El texto institucion.',
|
||||
200
|
||||
);
|
||||
if (body.dependencia)
|
||||
dataUpdate.dependencia = validar.validarTexto(
|
||||
body.dependencia,
|
||||
'El texto dependencia.',
|
||||
200
|
||||
);
|
||||
if (body.motivo)
|
||||
dataUpdate.motivo = validar.validarNumero(
|
||||
body.motivo,
|
||||
'El texto motivo.',
|
||||
1
|
||||
);
|
||||
if (validar.isObjectEmpty(dataUpdate))
|
||||
throw new Error(
|
||||
'No se envio nada para actualizar este Caso Especiaal.'
|
||||
);
|
||||
return CasoEspecial.update(dataUpdate, { where: { idCasoEspecial } });
|
||||
})
|
||||
.then((res) => ({
|
||||
message: 'Se guardo correctamente los cambios de este servicio.',
|
||||
}));
|
||||
};
|
||||
|
||||
module.exports = update;
|
||||
@@ -58,7 +58,7 @@ const update = async (body, files) => {
|
||||
return Servicio.update(dataUpdate, { where: { idServicio } });
|
||||
})
|
||||
.then((res) => ({
|
||||
message: 'Se guadro correctamente los cambios de este servicio.',
|
||||
message: 'Se guardo correctamente los cambios de este servicio.',
|
||||
}));
|
||||
};
|
||||
|
||||
|
||||
@@ -22,13 +22,17 @@ CasoEspecial.init(
|
||||
type: DataTypes.STRING(60),
|
||||
allowNull: false,
|
||||
},
|
||||
telefono: {
|
||||
type: DataTypes.STRING(15),
|
||||
allowNull: false,
|
||||
},
|
||||
institucion: {
|
||||
type: DataTypes.STRING(100),
|
||||
type: DataTypes.STRING(200),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
dependencia: {
|
||||
type: DataTypes.STRING(100),
|
||||
type: DataTypes.STRING(200),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
|
||||
@@ -9,6 +9,7 @@ const nuevo = require('../controller/CasoEspecial/nuevo');
|
||||
const serviciosEspeciales = require('../controller/CasoEspecial/serviciosEspeciales');
|
||||
const casoEspecial = require('../controller/CasoEspecial/casoEspecial');
|
||||
const liberacion = require('../controller/CasoEspecial/liberacion');
|
||||
const update = require('../controller/CasoEspecial/update');
|
||||
|
||||
const eliminarArchivo = (filename) => {
|
||||
fs.unlinkSync(`./server/uploads/${filename}`);
|
||||
@@ -72,4 +73,23 @@ app.put(
|
||||
}
|
||||
);
|
||||
|
||||
app.put(
|
||||
`${route}/update`,
|
||||
// verificaToken,
|
||||
upload.single('archivos'),
|
||||
(req, res) => {
|
||||
return update(
|
||||
JSON.parse(req.body.alumno),
|
||||
req.file ? req.file.filename : ''
|
||||
)
|
||||
.then((data) => {
|
||||
res.status(201).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
if (req.file) eliminarArchivo(req.file.filename);
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = app;
|
||||
|
||||
Reference in New Issue
Block a user