Merge branch 'dev' of https://repositorio.acatlan.unam.mx/CIDWA/servicio_social_api
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.rar`,
|
||||
'application/x-rar',
|
||||
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,55 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const CasoEspecial = require('../../db/tablas/CasoEspecial');
|
||||
|
||||
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 Especial no existe en la db.');
|
||||
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 Especial.'
|
||||
);
|
||||
return CasoEspecial.update(dataUpdate, { where: { idCasoEspecial } });
|
||||
})
|
||||
.then((res) => ({
|
||||
message: 'Se guardo correctamente los cambios de este servicio.',
|
||||
}));
|
||||
};
|
||||
|
||||
module.exports = update;
|
||||
@@ -67,7 +67,7 @@ const get = async (body) => {
|
||||
try {
|
||||
fs.unlinkSync(path);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
console.log(err);
|
||||
}
|
||||
fs.appendFile(path, convertArrayToCSV(data), (err) => {
|
||||
if (err) throw new Error(err);
|
||||
|
||||
@@ -43,7 +43,7 @@ const get = async (body) => {
|
||||
try {
|
||||
fs.unlinkSync(path);
|
||||
} catch (err) {
|
||||
throw new Error(err);
|
||||
console.log(err);
|
||||
}
|
||||
fs.appendFile(path, convertArrayToCSV(data), (err) => {
|
||||
if (err) throw new Error(err);
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const moment = require('moment');
|
||||
const validar = require('../../helper/validar');
|
||||
const gmail = require('../../helper/gmail');
|
||||
const correos = require('../../helper/correos');
|
||||
@@ -48,7 +49,11 @@ const liberacion = async (body) => {
|
||||
throw new Error('Id status no valido.');
|
||||
}
|
||||
})
|
||||
.then((res) => Servicio.update(update, { where: { idServicio } }))
|
||||
.then((res) =>
|
||||
Servicio.update(update, {
|
||||
where: { idServicio, fechaLiberacion: moment() },
|
||||
})
|
||||
)
|
||||
.then((res) => ({
|
||||
message:
|
||||
'Se cambio de estatus correctamente y se envio un correo al alumno informandole de su liberación.',
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
const fs = require('fs');
|
||||
const { convertArrayToCSV } = require('convert-array-to-csv');
|
||||
const { Op } = require('sequelize');
|
||||
const validar = require('../../helper/validar');
|
||||
const Servicio = require('../../db/tablas/Servicio');
|
||||
const Programa = require('../../db/tablas/Programa');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
const Carrera = require('../../db/tablas/Carrera');
|
||||
|
||||
const get = async (body) => {
|
||||
const inicio = validar.validarFecha(body.inicio);
|
||||
const fin = validar.validarFecha(body.fin);
|
||||
const path = `csv/reporte.csv`;
|
||||
const data = [];
|
||||
|
||||
return Servicio.findAll({
|
||||
where: {
|
||||
fechaInicio: { [Op.gte]: inicio },
|
||||
fechaInicio: { [Op.lte]: fin },
|
||||
},
|
||||
include: [{ model: Programa }, { model: Usuario }, { model: Carrera }],
|
||||
}).then((res) => {
|
||||
for (let i = 0; i < res.length; i++)
|
||||
data.push({
|
||||
numeroCuenta: res[i].Usuario.Usuario,
|
||||
nombre: res[i].Usuario.nombre,
|
||||
licenciatura: res[i].Carrera.carrera,
|
||||
correo: res[i].correo,
|
||||
fehcaInicio: res[i].fechaInicio,
|
||||
fechaFin: res[i].fechaFin,
|
||||
institucion: res[i].Programa.institucion,
|
||||
dependencia: res[i].Programa.dependencia,
|
||||
programa: res[i].Programa.programa,
|
||||
clave: res[i].Programa.clavePrograma,
|
||||
});
|
||||
try {
|
||||
fs.unlinkSync(path);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
fs.appendFile(path, convertArrayToCSV(data), (err) => {
|
||||
if (err) throw new Error(err);
|
||||
});
|
||||
return {
|
||||
message: `Se creo/actualizo correctamente el csv del reporte de servicios sociales.`,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = get;
|
||||
@@ -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,
|
||||
},
|
||||
|
||||
@@ -44,6 +44,11 @@ Servicio.init(
|
||||
allowNull: true, // eliminar
|
||||
defaultValue: null,
|
||||
},
|
||||
fechaLiberacion: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
fechaNacimiento: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: true,
|
||||
|
||||
@@ -22,6 +22,8 @@ const diario = async () => {
|
||||
|
||||
if (fechaFin.year() > now.year())
|
||||
fechaFinDate += 365 * (fechaFin.year() - now.year());
|
||||
if (fechaFin.year() < now.year())
|
||||
fechaFinDate -= 365 * (now.year() - fechaFin.year());
|
||||
if (fechaFinDate - now.dayOfYear() === 7) {
|
||||
let correoAlumno = correos.avisoTerminoAlumno(
|
||||
servicios[i].Usuario.nombre
|
||||
|
||||
@@ -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,18 @@ app.put(
|
||||
}
|
||||
);
|
||||
|
||||
app.put(
|
||||
`${route}/update`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return update(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = app;
|
||||
|
||||
@@ -21,6 +21,7 @@ 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 reporte = require('../controller/Servicio/reporte');
|
||||
|
||||
const eliminarArchivo = (filename) => {
|
||||
fs.unlinkSync(`./server/uploads/${filename}`);
|
||||
@@ -82,6 +83,20 @@ app.get(`${route}/alumno`, verificaToken, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get(
|
||||
`${route}/reporte`,
|
||||
// verificaToken,
|
||||
(req, res) => {
|
||||
return reporte(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
app.put(`${route}/cancelar`, verificaToken, (req, res) => {
|
||||
return cancelar(req.body)
|
||||
.then((data) => {
|
||||
|
||||
@@ -4,7 +4,7 @@ const app = express();
|
||||
app.use(require('./Status'));
|
||||
app.use(require('./Usuario'));
|
||||
app.use(require('./Servicio'));
|
||||
// app.use(require('./CasoEspecial'));
|
||||
app.use(require('./CasoEspecial'));
|
||||
app.use(require('./Programa'));
|
||||
app.use(require('./CuestionarioAlumno'));
|
||||
app.use(require('./CuestionarioPrograma'));
|
||||
|
||||
Reference in New Issue
Block a user