correcciones y nueva base
This commit is contained in:
@@ -2,31 +2,37 @@ const Invitado = require('../../db/tablas/Invitado');
|
||||
const Profesor = require('../../db/tablas/Profesor');
|
||||
const validar = require('../../helper/validar');
|
||||
const { correo } = require('../../helper/correos');
|
||||
const gmail = require('../../helper/gmail')
|
||||
const gmail = require('../../helper/gmail');
|
||||
|
||||
const infoInvitados = async (body) => {
|
||||
const idProfesor = validar.validarNumeroEntero(body.idProfesor, 'idProfesor');
|
||||
const invitados = body.invitados;
|
||||
const numeroInvitados = invitados.length;
|
||||
|
||||
invitados.forEach((invitado) => {
|
||||
if (invitado.edad < 18)
|
||||
throw new Error('Los invitados deben de ser mayores de edad.');
|
||||
});
|
||||
|
||||
if (numeroInvitados > 3)
|
||||
throw new Error('El número de invitados no puede ser mayor que 3.');
|
||||
|
||||
|
||||
const prof = await Profesor.findOne({ where: idProfesor });
|
||||
if(prof.numeroInvitados) throw new Error('A este profesor ya se le han guardado sus invitados.')
|
||||
if (prof.numeroInvitados)
|
||||
throw new Error('A este profesor ya se le han guardado sus invitados.');
|
||||
prof.update({ numeroInvitados: numeroInvitados });
|
||||
|
||||
|
||||
const respuesta = [];
|
||||
for (let i = 0; i < numeroInvitados; i++) {
|
||||
const invitado = invitados[i];
|
||||
const nombre = validar.validacionBasicaStr(
|
||||
invitado.nombreCompleto,
|
||||
`nombre completo invitado ${i+1}`,
|
||||
`nombre completo invitado ${i + 1}`,
|
||||
true
|
||||
);
|
||||
const edad = validar.validarNumeroEntero(
|
||||
invitado.edad,
|
||||
`edad invitado ${i+1}`,
|
||||
`edad invitado ${i + 1}`,
|
||||
false
|
||||
);
|
||||
|
||||
@@ -40,11 +46,11 @@ const infoInvitados = async (body) => {
|
||||
respuesta.push(res);
|
||||
}
|
||||
|
||||
const dataProf = await Profesor.findOne({where: idProfesor})
|
||||
const dataProf = await Profesor.findOne({ where: idProfesor });
|
||||
const Mail = correo(
|
||||
dataProf.nombre,
|
||||
dataProf.numeroTrabajador,
|
||||
dataProf.numeroInvitados,
|
||||
dataProf.numeroInvitados
|
||||
);
|
||||
|
||||
gmail(
|
||||
|
||||
@@ -1,8 +1,16 @@
|
||||
const Carrito = require('../../db/tablas/Profesor');
|
||||
const Profesor = require('../../db/tablas/Profesor');
|
||||
|
||||
const equipos = async () => {
|
||||
return Carrito.findAll({
|
||||
const adscripciones = async () => {
|
||||
return Profesor.findAll({
|
||||
attributes: ['adscripcion'],
|
||||
}).then((res) => {
|
||||
const result = [];
|
||||
res.forEach((item) => {
|
||||
if (!result.includes(item.adscripcion)) {
|
||||
result.push(item.adscripcion);
|
||||
}
|
||||
});
|
||||
return result
|
||||
});
|
||||
};
|
||||
module.exports = equipos;
|
||||
module.exports = adscripciones;
|
||||
|
||||
@@ -6,6 +6,7 @@ const entradaInvitado = async (body) => {
|
||||
|
||||
const profesor = await Profesor.findOne({ where: idProfesor });
|
||||
if (!profesor) throw new Error('Este profesor no existe');
|
||||
if (!profesor.noInvitados) throw new Error('Este profesor no registró a ninún invitado.')
|
||||
let noInvDentro = profesor.dataValues.numeroInvitadosDentro;
|
||||
let noInv = profesor.dataValues.numeroInvitados;
|
||||
if (noInvDentro && noInvDentro >= noInv)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
const Premiacion = require('./Premiacion');
|
||||
const Profesor = require('./Profesor');
|
||||
|
||||
class Invitado extends Model {}
|
||||
@@ -37,4 +38,12 @@ Invitado.belongsTo(Profesor, {
|
||||
},
|
||||
});
|
||||
|
||||
Invitado.belongsTo(Premiacion, {
|
||||
foreignKey: {
|
||||
name: 'idPremiacion',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = Invitado;
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
const { DataTypes, Model } = require('sequelize');
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
|
||||
class Premiacion extends Model {}
|
||||
Premiacion.init(
|
||||
{
|
||||
idPremiacion: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
premiacion: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: false,
|
||||
},
|
||||
fecha: {
|
||||
type: DataTypes.DATEONLY,
|
||||
allowNull: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Premiacion',
|
||||
tableName: 'premiacion',
|
||||
timestamps: false,
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = Premiacion;
|
||||
Reference in New Issue
Block a user