nuevo servicio especial listo

This commit is contained in:
2021-02-10 16:45:15 -06:00
parent 027fddf9cc
commit f76237ea20
8 changed files with 162 additions and 38 deletions
+88
View File
@@ -0,0 +1,88 @@
const { Op } = require('sequelize');
const drive = require('../../helper/drive');
const CasoEspecial = require('../../db/tablas/CasoEspecial');
const Usuario = require('../../db/tablas/Usuario');
const Carrera = require('../../db/tablas/Carrera');
const validar = require('../../helper/validar');
const nuevo = async (body, file) => {
console.log('Hola');
const idUsuario = validar.validarId(body.idUsuario);
const idCarrera = validar.validarId(body.idCarrera);
const idStatus = validar.validarId(body.idStatus);
const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
const creditos = validar.validarNumero(body.creditos);
const correo = validar.validarCorreo(body.correo);
const fechaInicio = validar.validarFecha(body.fechaInicio);
const fechaFin = validar.validarFecha(body.fechaFin);
const fechaNacimiento = validar.validarFecha(body.fechaNacimiento);
const path = `./server/uploads/${validar.validar(file, 'El archivo', 1000)}`;
const institucion = body.institucion
? validar.validarTexto(body.institucion, 'El texto institucion.', 100)
: '';
const dependencia = body.dependencia
? validar.validarTexto(body.dependencia, 'El texto dependencia.', 100)
: '';
const incapacidad = body.incapacidad
? validar.validarTexto(body.incapacidad, 'El texto incapacidad.', 100)
: '';
const direccion = validar.validarAlfanumerico(
body.direccion,
'La dirección',
200
);
let carpeta = '';
return Usuario.findOne({
where: { idUsuario },
})
.then((res) => {
if (!res) throw new Error('Este alumno no existe en la db.');
if (res.idTipoUsuario !== 3)
throw new Error('Este usuario no es de tipo Alumno.');
return Carrera.findOne({ where: { idCarrera } });
})
.then((res) => {
if (!res) throw new Error('Esta carrera no existe en la db.');
return CasoEspecial.findOne({
where: { idUsuario },
});
})
.then(async (res) => {
if (res) throw new Error('Este alumno ya tienen un Servicio Especial.');
return drive.folder(numeroCuenta);
})
.then((res) => {
carpeta = res;
return drive.uploadFile(
path,
`archivos.rar`,
'application/x-rar',
carpeta
);
})
.then((res) =>
CasoEspecial.create({
idUsuario,
idCarrera,
idStatus,
creditos,
correo,
institucion,
dependencia,
incapacidad,
direccion,
fechaInicio,
fechaFin,
fechaNacimiento,
carpeta,
archivoZip: res,
})
)
.then((res) => ({
message: `Se ha registro el Servicio Especial correctamente.`,
}));
};
module.exports = nuevo;
+2 -2
View File
@@ -20,7 +20,7 @@ const nuevo = async (body, file) => {
? validar.validarTexto(
body.programaInterno,
'El texto programa interno.',
80
250
)
: '';
const profesor = body.profesor
@@ -44,7 +44,7 @@ const nuevo = async (body, file) => {
.then((res) => {
if (!res) throw new Error('Esta carrera no existe en la db.');
return Servicio.findOne({
where: { idUsuario, idStatus: { [Op.ne]: 10 } },
where: { idUsuario, idStatus: { [Op.lt]: 10 } },
});
})
.then(async (res) => {