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 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 idCarrera = validar.validarId(body.idCarrera);
|
||||
let creditos = body.creditos;
|
||||
let creditos = validar.validarNumero(body.creditos);
|
||||
let nombre = validar.validarTexto(body.nombre);
|
||||
let correo = validar.validarCorreo(body.correo);
|
||||
let fechaInicio = validar.validarFecha(boyd.fechaInicio);
|
||||
let fechaFin = validar.validarFecha(boyd.fechaFin);
|
||||
let cartaAceptacion = body.cartaAceptacion;
|
||||
let fechaInicio = validar.validarFecha(body.fechaInicio);
|
||||
let fechaFin = validar.validarFecha(body.fechaFin);
|
||||
let carpeta = '';
|
||||
let cartaAceptacion = '';
|
||||
|
||||
return Usuario.findOne({
|
||||
where: { [Op.and]: [{ idUsuario }, { idTipoUsuario: 3 }] },
|
||||
@@ -45,6 +47,7 @@ const nuevo = async (body) => {
|
||||
correo,
|
||||
fechaInicio,
|
||||
fechaFin,
|
||||
carpeta,
|
||||
cartaAceptacion,
|
||||
});
|
||||
})
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const Servicio = require('../../db/tablas/Servicio');
|
||||
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) => {
|
||||
let pagina = body.pagina;
|
||||
@@ -8,11 +11,38 @@ const serviciosAdmin = async (body) => {
|
||||
let numeroCuenta = body.numeroCuenta;
|
||||
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 = [];
|
||||
|
||||
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 {
|
||||
registros: res.length,
|
||||
faltantes: res.length - data.length - (pagina - 1) * 25,
|
||||
|
||||
@@ -22,11 +22,11 @@ Servicio.init(
|
||||
allowNull: false,
|
||||
},
|
||||
nombre: {
|
||||
type: DataTypes.STRING(30),
|
||||
type: DataTypes.STRING(40),
|
||||
allowNull: false,
|
||||
},
|
||||
correo: {
|
||||
type: DataTypes.STRING(30),
|
||||
type: DataTypes.STRING(80),
|
||||
allowNull: false,
|
||||
},
|
||||
telefono: {
|
||||
@@ -35,7 +35,7 @@ Servicio.init(
|
||||
defaultValue: null,
|
||||
},
|
||||
direccion: {
|
||||
type: DataTypes.STRING(30),
|
||||
type: DataTypes.STRING(150),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
@@ -54,30 +54,30 @@ Servicio.init(
|
||||
defaultValue: null,
|
||||
},
|
||||
carpeta: {
|
||||
type: DataTypes.STRING(30),
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: false,
|
||||
},
|
||||
cartaAceptacion: {
|
||||
type: DataTypes.STRING(30),
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: false,
|
||||
},
|
||||
cartaTermino: {
|
||||
type: DataTypes.STRING(30),
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
informeGlobal: {
|
||||
type: DataTypes.STRING(30),
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
programaInterno: {
|
||||
type: DataTypes.STRING(30),
|
||||
type: DataTypes.STRING(80),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
profesor: {
|
||||
type: DataTypes.STRING(30),
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
|
||||
@@ -2,7 +2,7 @@ const validator = require('validator');
|
||||
const moment = require('moment');
|
||||
|
||||
const noValido = (campo) => {
|
||||
throw new Error(`El ${campo} no es valido.`);
|
||||
throw new Error(`${campo} no es valido.`);
|
||||
};
|
||||
|
||||
const noHay = (variable, campo) => {
|
||||
@@ -10,11 +10,11 @@ const noHay = (variable, 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) => {
|
||||
let campo = 'id';
|
||||
let campo = 'El id';
|
||||
|
||||
noHay(id, campo);
|
||||
if (typeof id === 'number') id = id.toString();
|
||||
@@ -24,7 +24,7 @@ const validarId = (id) => {
|
||||
};
|
||||
|
||||
const validarCorreo = (correo) => {
|
||||
let campo = 'correo';
|
||||
let campo = 'El correo';
|
||||
|
||||
noHay(correo, campo);
|
||||
if (typeof correo !== 'string' || !validator.isEmail(correo)) noValido(campo);
|
||||
@@ -42,7 +42,7 @@ const validarTexto = (texto, campo) => {
|
||||
};
|
||||
|
||||
const validarNumeroCuenta = (numeroCuenta) => {
|
||||
let campo = 'numero de cuenta';
|
||||
let campo = 'El numero de cuenta';
|
||||
|
||||
noHay(numeroCuenta, campo);
|
||||
if (
|
||||
@@ -55,14 +55,26 @@ const validarNumeroCuenta = (numeroCuenta) => {
|
||||
};
|
||||
|
||||
const validarFecha = (fecha) => {
|
||||
let campo = 'fecha';
|
||||
let campo = 'La fecha';
|
||||
let fechaMoment = moment(fecha);
|
||||
|
||||
noHay(fecha, campo);
|
||||
if (fechaMoment.isValid()) noValido(campo);
|
||||
if (!fechaMoment.isValid()) noValido(campo);
|
||||
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 = {
|
||||
noValido,
|
||||
yaExiste,
|
||||
@@ -72,4 +84,8 @@ module.exports = {
|
||||
validarTexto,
|
||||
validarNumeroCuenta,
|
||||
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)
|
||||
.then((data) => {
|
||||
console.log(data)
|
||||
|
||||
@@ -28,7 +28,7 @@ const escolares = require('../controller/Usuario/escolares');
|
||||
app.get(`${route}/escolares`, (req, res) => {
|
||||
return escolares(req.query)
|
||||
.then((data) => {
|
||||
res.status(201).json(data);
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
|
||||
Reference in New Issue
Block a user