pre registro sin subir achrivo
This commit is contained in:
@@ -6,15 +6,17 @@ const Carrera = require('../../db/tablas/Carrera');
|
|||||||
const validar = require('../../helper/validar');
|
const validar = require('../../helper/validar');
|
||||||
|
|
||||||
const nuevo = async (body) => {
|
const nuevo = async (body) => {
|
||||||
let idUsuario = validar.validarId(body.idUsuarioAlumno);
|
console.log('hola');
|
||||||
|
let idUsuario = validar.validarId(body.idUsuario);
|
||||||
let idPrograma = validar.validarId(body.idPrograma);
|
let idPrograma = validar.validarId(body.idPrograma);
|
||||||
let idCarrera = validar.validarId(body.idCarrera);
|
let idCarrera = validar.validarId(body.idCarrera);
|
||||||
let creditos = body.creditos;
|
let creditos = validar.validarNumero(body.creditos);
|
||||||
let nombre = validar.validarTexto(body.nombre);
|
let nombre = validar.validarTexto(body.nombre);
|
||||||
let correo = validar.validarCorreo(body.correo);
|
let correo = validar.validarCorreo(body.correo);
|
||||||
let fechaInicio = validar.validarFecha(boyd.fechaInicio);
|
let fechaInicio = validar.validarFecha(body.fechaInicio);
|
||||||
let fechaFin = validar.validarFecha(boyd.fechaFin);
|
let fechaFin = validar.validarFecha(body.fechaFin);
|
||||||
let cartaAceptacion = body.cartaAceptacion;
|
let carpeta = '';
|
||||||
|
let cartaAceptacion = '';
|
||||||
|
|
||||||
return Usuario.findOne({
|
return Usuario.findOne({
|
||||||
where: { [Op.and]: [{ idUsuario }, { idTipoUsuario: 3 }] },
|
where: { [Op.and]: [{ idUsuario }, { idTipoUsuario: 3 }] },
|
||||||
@@ -45,6 +47,7 @@ const nuevo = async (body) => {
|
|||||||
correo,
|
correo,
|
||||||
fechaInicio,
|
fechaInicio,
|
||||||
fechaFin,
|
fechaFin,
|
||||||
|
carpeta,
|
||||||
cartaAceptacion,
|
cartaAceptacion,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
const validar = require('../../helper/validar');
|
const validar = require('../../helper/validar');
|
||||||
const Servicio = require('../../db/tablas/Servicio');
|
const Servicio = require('../../db/tablas/Servicio');
|
||||||
const Usuario = require('../../db/tablas/Usuario');
|
const Usuario = require('../../db/tablas/Usuario');
|
||||||
|
const Carrera = require('../../db/tablas/Carrera');
|
||||||
|
const Status = require('../../db/tablas/Status');
|
||||||
|
const TipoUsuario = require('../../db/tablas/TipoUsuario');
|
||||||
|
|
||||||
const serviciosAdmin = async (body) => {
|
const serviciosAdmin = async (body) => {
|
||||||
let pagina = body.pagina;
|
let pagina = body.pagina;
|
||||||
@@ -8,11 +11,38 @@ const serviciosAdmin = async (body) => {
|
|||||||
let numeroCuenta = body.numeroCuenta;
|
let numeroCuenta = body.numeroCuenta;
|
||||||
let idStatus = body.idStatus;
|
let idStatus = body.idStatus;
|
||||||
|
|
||||||
return Servicio.findAll({ include: { model: Usuario } }).then((res) => {
|
return Servicio.findAll({
|
||||||
|
include: [
|
||||||
|
{ model: Usuario, include: { model: TipoUsuario } },
|
||||||
|
{ model: Carrera },
|
||||||
|
{ model: Status },
|
||||||
|
],
|
||||||
|
}).then((res) => {
|
||||||
let data = [];
|
let data = [];
|
||||||
|
|
||||||
for (let i = pagina * 25 - 25; i < res.length && i < pagina * 25; i++)
|
for (let i = pagina * 25 - 25; i < res.length && i < pagina * 25; i++)
|
||||||
data.push(res[i]);
|
data.push({
|
||||||
|
idServicio: res[i].idServicio,
|
||||||
|
nombre: res[i].nombre,
|
||||||
|
fechaInicio: res[i].fechaInicio,
|
||||||
|
fechaFin: res[i].fechaFin,
|
||||||
|
Usuario: {
|
||||||
|
idUsuario: res[i].Usuario.idUsuario,
|
||||||
|
usuario: res[i].Usuario.usuario,
|
||||||
|
TipoUsuario: {
|
||||||
|
idTipoUsuario: res[i].Usuario.TipoUsuario.idTipoUsuario,
|
||||||
|
tipoUsuario: res[i].Usuario.TipoUsuario.tipoUsuario,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Carrera: {
|
||||||
|
idCarrera: res[i].Carrera.idCarrera,
|
||||||
|
carrera: res[i].Carrera.carrera,
|
||||||
|
},
|
||||||
|
Status: {
|
||||||
|
idStatus: res[i].Status.idStatus,
|
||||||
|
status: res[i].Status.status,
|
||||||
|
},
|
||||||
|
});
|
||||||
return {
|
return {
|
||||||
registros: res.length,
|
registros: res.length,
|
||||||
faltantes: res.length - data.length - (pagina - 1) * 25,
|
faltantes: res.length - data.length - (pagina - 1) * 25,
|
||||||
|
|||||||
@@ -22,11 +22,11 @@ Servicio.init(
|
|||||||
allowNull: false,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
nombre: {
|
nombre: {
|
||||||
type: DataTypes.STRING(30),
|
type: DataTypes.STRING(40),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
correo: {
|
correo: {
|
||||||
type: DataTypes.STRING(30),
|
type: DataTypes.STRING(80),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
telefono: {
|
telefono: {
|
||||||
@@ -35,7 +35,7 @@ Servicio.init(
|
|||||||
defaultValue: null,
|
defaultValue: null,
|
||||||
},
|
},
|
||||||
direccion: {
|
direccion: {
|
||||||
type: DataTypes.STRING(30),
|
type: DataTypes.STRING(150),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
defaultValue: null,
|
defaultValue: null,
|
||||||
},
|
},
|
||||||
@@ -54,30 +54,30 @@ Servicio.init(
|
|||||||
defaultValue: null,
|
defaultValue: null,
|
||||||
},
|
},
|
||||||
carpeta: {
|
carpeta: {
|
||||||
type: DataTypes.STRING(30),
|
type: DataTypes.STRING(50),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
cartaAceptacion: {
|
cartaAceptacion: {
|
||||||
type: DataTypes.STRING(30),
|
type: DataTypes.STRING(50),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
cartaTermino: {
|
cartaTermino: {
|
||||||
type: DataTypes.STRING(30),
|
type: DataTypes.STRING(50),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
defaultValue: null,
|
defaultValue: null,
|
||||||
},
|
},
|
||||||
informeGlobal: {
|
informeGlobal: {
|
||||||
type: DataTypes.STRING(30),
|
type: DataTypes.STRING(50),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
defaultValue: null,
|
defaultValue: null,
|
||||||
},
|
},
|
||||||
programaInterno: {
|
programaInterno: {
|
||||||
type: DataTypes.STRING(30),
|
type: DataTypes.STRING(80),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
defaultValue: null,
|
defaultValue: null,
|
||||||
},
|
},
|
||||||
profesor: {
|
profesor: {
|
||||||
type: DataTypes.STRING(30),
|
type: DataTypes.STRING(50),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
defaultValue: null,
|
defaultValue: null,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const validator = require('validator');
|
|||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
|
|
||||||
const noValido = (campo) => {
|
const noValido = (campo) => {
|
||||||
throw new Error(`El ${campo} no es valido.`);
|
throw new Error(`${campo} no es valido.`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const noHay = (variable, campo) => {
|
const noHay = (variable, campo) => {
|
||||||
@@ -10,11 +10,11 @@ const noHay = (variable, campo) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const yaExiste = (campo) => {
|
const yaExiste = (campo) => {
|
||||||
throw new Error(`El ${campo} ya se encuentra en uso.`);
|
throw new Error(`${campo} ya se encuentra en uso.`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const validarId = (id) => {
|
const validarId = (id) => {
|
||||||
let campo = 'id';
|
let campo = 'El id';
|
||||||
|
|
||||||
noHay(id, campo);
|
noHay(id, campo);
|
||||||
if (typeof id === 'number') id = id.toString();
|
if (typeof id === 'number') id = id.toString();
|
||||||
@@ -24,7 +24,7 @@ const validarId = (id) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const validarCorreo = (correo) => {
|
const validarCorreo = (correo) => {
|
||||||
let campo = 'correo';
|
let campo = 'El correo';
|
||||||
|
|
||||||
noHay(correo, campo);
|
noHay(correo, campo);
|
||||||
if (typeof correo !== 'string' || !validator.isEmail(correo)) noValido(campo);
|
if (typeof correo !== 'string' || !validator.isEmail(correo)) noValido(campo);
|
||||||
@@ -42,7 +42,7 @@ const validarTexto = (texto, campo) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const validarNumeroCuenta = (numeroCuenta) => {
|
const validarNumeroCuenta = (numeroCuenta) => {
|
||||||
let campo = 'numero de cuenta';
|
let campo = 'El numero de cuenta';
|
||||||
|
|
||||||
noHay(numeroCuenta, campo);
|
noHay(numeroCuenta, campo);
|
||||||
if (
|
if (
|
||||||
@@ -55,14 +55,26 @@ const validarNumeroCuenta = (numeroCuenta) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const validarFecha = (fecha) => {
|
const validarFecha = (fecha) => {
|
||||||
let campo = 'fecha';
|
let campo = 'La fecha';
|
||||||
let fechaMoment = moment(fecha);
|
let fechaMoment = moment(fecha);
|
||||||
|
|
||||||
noHay(fecha, campo);
|
noHay(fecha, campo);
|
||||||
if (fechaMoment.isValid()) noValido(campo);
|
if (!fechaMoment.isValid()) noValido(campo);
|
||||||
return fechaMoment;
|
return fechaMoment;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const validarNumero = (numero) => {
|
||||||
|
let campo = 'El numero';
|
||||||
|
|
||||||
|
noHay(numero, campo);
|
||||||
|
if (
|
||||||
|
typeof numero !== 'string' ||
|
||||||
|
!validator.isNumeric(numero, { no_symbols: true })
|
||||||
|
)
|
||||||
|
noValido(campo);
|
||||||
|
return numero;
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
noValido,
|
noValido,
|
||||||
yaExiste,
|
yaExiste,
|
||||||
@@ -72,4 +84,8 @@ module.exports = {
|
|||||||
validarTexto,
|
validarTexto,
|
||||||
validarNumeroCuenta,
|
validarNumeroCuenta,
|
||||||
validarFecha,
|
validarFecha,
|
||||||
|
validarNumero,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// console.log(moment('2020-01-01').format());
|
||||||
|
// 2020-01-01T00:00:00-06:00
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ app.post(`${route}/nuevo`, (req, res) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get(`${route}/serviciosAdmin`, (req, res) => {
|
app.get(`${route}/servicios_admin`, (req, res) => {
|
||||||
return serviciosAdmin(req.query)
|
return serviciosAdmin(req.query)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
console.log(data)
|
console.log(data)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ const escolares = require('../controller/Usuario/escolares');
|
|||||||
app.get(`${route}/escolares`, (req, res) => {
|
app.get(`${route}/escolares`, (req, res) => {
|
||||||
return escolares(req.query)
|
return escolares(req.query)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(201).json(data);
|
res.status(200).json(data);
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
res.status(400).json({ message: err.message });
|
res.status(400).json({ message: err.message });
|
||||||
|
|||||||
Reference in New Issue
Block a user