nuevo servicio especial listo
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user