From b96fabb0784368b74103e6e06a196eaee1dfd5c6 Mon Sep 17 00:00:00 2001 From: Lemuel Marquez Date: Tue, 17 Nov 2020 10:12:30 -0600 Subject: [PATCH] pre registro sin subir achrivo --- server/controller/Servicio/nuevo.js | 13 +++++--- server/controller/Servicio/serviciosAdmin.js | 34 ++++++++++++++++++-- server/db/tablas/Servicio.js | 18 +++++------ server/helper/drive.js | 0 server/helper/gmail.js | 0 server/helper/validar.js | 30 +++++++++++++---- server/routes/Servicio.js | 2 +- server/routes/Usuario.js | 2 +- 8 files changed, 74 insertions(+), 25 deletions(-) create mode 100644 server/helper/drive.js create mode 100644 server/helper/gmail.js diff --git a/server/controller/Servicio/nuevo.js b/server/controller/Servicio/nuevo.js index 1ea7636..8c2ab5a 100644 --- a/server/controller/Servicio/nuevo.js +++ b/server/controller/Servicio/nuevo.js @@ -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, }); }) diff --git a/server/controller/Servicio/serviciosAdmin.js b/server/controller/Servicio/serviciosAdmin.js index 49d4c1c..70ec917 100644 --- a/server/controller/Servicio/serviciosAdmin.js +++ b/server/controller/Servicio/serviciosAdmin.js @@ -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, diff --git a/server/db/tablas/Servicio.js b/server/db/tablas/Servicio.js index dd4e09a..af1ee93 100644 --- a/server/db/tablas/Servicio.js +++ b/server/db/tablas/Servicio.js @@ -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, }, diff --git a/server/helper/drive.js b/server/helper/drive.js new file mode 100644 index 0000000..e69de29 diff --git a/server/helper/gmail.js b/server/helper/gmail.js new file mode 100644 index 0000000..e69de29 diff --git a/server/helper/validar.js b/server/helper/validar.js index 03d7811..21cfb3b 100644 --- a/server/helper/validar.js +++ b/server/helper/validar.js @@ -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 diff --git a/server/routes/Servicio.js b/server/routes/Servicio.js index 3a0b50a..34b9119 100644 --- a/server/routes/Servicio.js +++ b/server/routes/Servicio.js @@ -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) diff --git a/server/routes/Usuario.js b/server/routes/Usuario.js index 55bf9f5..92b4df8 100644 --- a/server/routes/Usuario.js +++ b/server/routes/Usuario.js @@ -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 });