listo, faltan correo y pruebas
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
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 infoInvitados = async (body) => {
|
||||
const idProfesor = validar.validarNumeroEntero(body.idProfesor, 'idProfesor');
|
||||
const invitados = body.invitados;
|
||||
const numeroInvitados = invitados.length;
|
||||
|
||||
if (!numeroInvitados === 0 || numeroInvitados > 3)
|
||||
throw new Error('El número de invitados no puede ser cero ni 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.')
|
||||
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}`,
|
||||
true
|
||||
);
|
||||
const edad = validar.validarNumeroEntero(
|
||||
invitado.edad,
|
||||
`edad invitado ${i+1}`,
|
||||
false
|
||||
);
|
||||
|
||||
const res = await Invitado.create({
|
||||
nombreCompleto: nombre,
|
||||
edad: edad,
|
||||
idProfesor: idProfesor,
|
||||
});
|
||||
if (!res)
|
||||
throw new Error('No se ha podido ingresar los datos del invitado');
|
||||
respuesta.push(res);
|
||||
}
|
||||
|
||||
const dataProf = await Profesor.findOne({where: idProfesor})
|
||||
const Mail = correo(
|
||||
dataProf.nombre,
|
||||
dataProf.numeroTrabajador,
|
||||
dataProf.numeroInvitados,
|
||||
);
|
||||
|
||||
gmail(
|
||||
Mail.subject,
|
||||
`yosoymarco3@gmail.com`,
|
||||
// `${dataProf.numeroTrabajador}@pcpuma.acatlan.unam.mx`,
|
||||
Mail.message
|
||||
);
|
||||
return {
|
||||
message:
|
||||
'Se registró correctamente sus invitados. Se enviaron los pases de entrada a su correo institucional pcpuma.',
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = infoInvitados;
|
||||
@@ -0,0 +1,29 @@
|
||||
const csv = require('csvtojson');
|
||||
const { eliminarArchivo } = require('../../helper/helper');
|
||||
const Profesor = require('../../db/tablas/Profesor');
|
||||
|
||||
const cargaMasiva = async (file) => {
|
||||
const path = `server/uploads/${file}`;
|
||||
let res = [];
|
||||
|
||||
await csv()
|
||||
.fromFile(path)
|
||||
.then(async (profesores) => {
|
||||
for (let i = 0; i < profesores.length; i++) {
|
||||
const resp = await Profesor.create({
|
||||
numeroTrabajador: profesores[i].numeroTrabajador,
|
||||
nombre: profesores[i].nombre,
|
||||
correo: `${profesores[i].numeroTrabajador}@pcpuma.acatlan.unam.mx`,
|
||||
adscripcion: profesores[i].adscripcion,
|
||||
})
|
||||
res.push(resp)
|
||||
}
|
||||
await eliminarArchivo(path);
|
||||
});
|
||||
return {
|
||||
message: 'Se subió correctamente el archivo csv.',
|
||||
res
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = cargaMasiva;
|
||||
@@ -0,0 +1,22 @@
|
||||
const Profesor = require('../../db/tablas/Profesor');
|
||||
const validar = require('../../helper/validar');
|
||||
|
||||
const entradaInvitado = async (body) => {
|
||||
const idProfesor = validar.validarNumeroEntero(body.idProfesor, 'idProfesor');
|
||||
|
||||
const profesor = await Profesor.findOne({ where: idProfesor });
|
||||
if (!profesor) throw new Error('Este profesor no existe');
|
||||
let noInvDentro = profesor.dataValues.numeroInvitadosDentro;
|
||||
let noInv = profesor.dataValues.numeroInvitados;
|
||||
if (noInvDentro && noInvDentro >= noInv)
|
||||
throw new Error('Este profesor ya ingreso a todos sus invitados.');
|
||||
|
||||
const res = await profesor.update({ numeroInvitadosDentro: noInvDentro + 1 });
|
||||
if (!res)
|
||||
throw new Error(
|
||||
'Ha ocurrido un error al actualizar los datos del profesor.'
|
||||
);
|
||||
return res;
|
||||
};
|
||||
|
||||
module.exports = entradaInvitado;
|
||||
@@ -1,5 +0,0 @@
|
||||
// const Invitado = require('../../db/tablas/Invitado');
|
||||
|
||||
// const get = () => Invitado.findAll();
|
||||
|
||||
// module.exports = get;
|
||||
@@ -20,12 +20,14 @@ const dataUsuarios = async () => {
|
||||
const dataProfesores = async () => {
|
||||
let usuario = ['4163132', '123456778', '1234567890'];
|
||||
let adscripcion = ['Adscripcion 1', 'Adscripcion 2', 'Adscripcion 3'];
|
||||
let nombre = ['Nombre 1', 'Nombre 2', 'Nombre 3'];
|
||||
let correo = ['correo 1', 'correo 2', 'correo 3'];
|
||||
|
||||
for (let i = 0; i < usuario.length; i++) {
|
||||
await Profesor.create({
|
||||
numeroTrabajador: usuario[i],
|
||||
adscripcion: adscripcion[i],
|
||||
nombre: nombre[i],
|
||||
correo: correo[i],
|
||||
numeroInvitados: i+1,
|
||||
});
|
||||
|
||||
@@ -16,19 +16,27 @@ Profesor.init(
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
},
|
||||
nombre: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: false,
|
||||
},
|
||||
adscripcion: {
|
||||
type: DataTypes.STRING(80),
|
||||
allowNull: false
|
||||
allowNull: false,
|
||||
},
|
||||
correo: {
|
||||
type: DataTypes.STRING(50),
|
||||
allowNull: true,
|
||||
defaultValue: null
|
||||
defaultValue: null,
|
||||
},
|
||||
numeroInvitados: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true
|
||||
}
|
||||
allowNull: true,
|
||||
},
|
||||
numeroInvitadosDentro: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
@@ -38,5 +46,4 @@ Profesor.init(
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
module.exports = Profesor;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const moment = require('moment');
|
||||
|
||||
const correoAlumno = (numeroCuenta, lic, date, idAlumno) => {
|
||||
const fecha = moment(date);
|
||||
const correo = (nombre, numeroTrabajador, numeroInvitados) => {
|
||||
// const fecha = moment(date);
|
||||
|
||||
return {
|
||||
subject: `Comprobante de registro invitados.`,
|
||||
@@ -10,15 +10,7 @@ const correoAlumno = (numeroCuenta, lic, date, idAlumno) => {
|
||||
<div style="font-size: 15px;">
|
||||
<p>
|
||||
Gracias por registrarte para participar en este recorrido por la FES Acatlán, tu Facultad. La cita es en
|
||||
la entrada peatonal (sobre Av. San Juan Totoltepec), el próximo <b>${
|
||||
fecha.date() < 10 ? '0' + fecha.date() : fecha.date()
|
||||
}/${
|
||||
fecha.month() + 1 < 10 ? '0' + (fecha.month() + 1) : fecha.month() + 1
|
||||
}/${fecha.year()}</b> a las <b>${
|
||||
fecha.hour() < 10 ? '0' + fecha.hour() : fecha.hour()
|
||||
}:${
|
||||
fecha.minute() < 10 ? '0' + fecha.minute() : fecha.minute()
|
||||
} h</b>. Te pedimos
|
||||
la entrada peatonal (sobre Av. San Juan Totoltepec), el próximo <b>h</b>. Te pedimos
|
||||
asistir en la fecha y horarios elegidos (no puedes modificarlos).
|
||||
</p>
|
||||
|
||||
@@ -40,14 +32,14 @@ const correoAlumno = (numeroCuenta, lic, date, idAlumno) => {
|
||||
|
||||
<p>¡Estaremos felices de recibirte!</p>
|
||||
|
||||
<img src="https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https://api.qrserver.com/v1/create-qr-code/?size=200x200&data={%22numeroCuenta%22:%22${numeroCuenta}%22,%22idAlumno%22:${idAlumno}}" alt="qr_img" />
|
||||
|
||||
<p><i>"Por mi raza hablará el espíritu"</i></p>
|
||||
|
||||
<p><b><i>Facultad de Estudios Superiores Acatlán</i></b></p>
|
||||
</div>
|
||||
`,
|
||||
};
|
||||
};
|
||||
};
|
||||
// <img src="https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=https://api.qrserver.com/v1/create-qr-code/?size=200x200&data={%22numeroCuenta%22:%22${numeroCuenta}%22,%22idAlumno%22:${idAlumno}}" alt="qr_img" />
|
||||
|
||||
module.exports = { correoAlumno };
|
||||
module.exports = { correo };
|
||||
@@ -5,9 +5,9 @@ const send = require('gmail-send')({
|
||||
pass: process.env.GMAILPASSWORD,
|
||||
});
|
||||
|
||||
const gmail = (subject, to, text) => {
|
||||
const gmail = (subject, to, html) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
send({ subject, to, text }, (error, result, fullResult) => {
|
||||
send({ subject, to, html }, (error, result, fullResult) => {
|
||||
if (error) reject(error);
|
||||
console.log(fullResult);
|
||||
resolve(result);
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
// const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/invitado';
|
||||
const controllerPath = '../controller/Invitado';
|
||||
const get = require(`${controllerPath}/invitados`);
|
||||
const infoInvitados = require(`${controllerPath}/infoInvitados`);
|
||||
|
||||
app.get(`${route}/get`, (req, res) => {
|
||||
return get()
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.post(`${route}/infoInvitados`, (req, res) => {
|
||||
return infoInvitados(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
// app.post(`${route}/entradaInvitado`, (req, res) => {
|
||||
// return entradaInvitado(req.body)
|
||||
// .then((data) => {
|
||||
// res.status(200).json(data);
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// res.status(400).json({ message: err.message });
|
||||
// });
|
||||
// });
|
||||
|
||||
module.exports = app;
|
||||
+32
-18
@@ -1,9 +1,13 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const multer = require('multer');
|
||||
const upload = multer({ dest: 'server/uploads' });
|
||||
// const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/profesor';
|
||||
const controllerPath = '../controller/Profesor';
|
||||
const login = require(`${controllerPath}/login`);
|
||||
const entradaInvitado = require(`${controllerPath}/entradaInvitado`);
|
||||
const cargarDatos = require(`${controllerPath}/cargarDatos`);
|
||||
|
||||
app.post(`${route}/login`, (req, res) => {
|
||||
return login(req.body)
|
||||
@@ -15,24 +19,34 @@ app.post(`${route}/login`, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
// app.post(`${route}/loginOperador`, (req, res) => {
|
||||
// return loginOperador(req.body)
|
||||
// .then((data) => {
|
||||
// res.status(200).json(data);
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// res.status(400).json({ message: err.message });
|
||||
// });
|
||||
// });
|
||||
app.post(`${route}/entradaInvitado`, (req, res) => {
|
||||
return entradaInvitado(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
// app.post(`${route}/entradaInvitado`, (req, res) => {
|
||||
// return entradaInvitado(req.body)
|
||||
// .then((data) => {
|
||||
// res.status(200).json(data);
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// res.status(400).json({ message: err.message });
|
||||
// });
|
||||
// });
|
||||
app.post(
|
||||
`${route}/cargarDatos`,
|
||||
// verificaToken,
|
||||
upload.single('recfile'),
|
||||
(req, res) => {
|
||||
if (req.file) {
|
||||
return cargarDatos(req.file.filename)
|
||||
.then((data) => {
|
||||
res.status(201).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
}
|
||||
res
|
||||
.status(400)
|
||||
.json({ message: 'No se envio un archivo csv para la carga masiva.' });
|
||||
}
|
||||
);
|
||||
|
||||
module.exports = app;
|
||||
|
||||
+10
-10
@@ -5,7 +5,7 @@ const route = '/usuario';
|
||||
const controllerPath = '../controller/Usuario';
|
||||
const loginAdmin = require(`${controllerPath}/loginAdmin`);
|
||||
const loginOperador = require(`${controllerPath}/loginOperador`);
|
||||
const entradaInvitado = require(`${controllerPath}/entradaInvitado`);
|
||||
// const entradaInvitado = require(`${controllerPath}/entradaInvitado`);
|
||||
|
||||
app.post(`${route}/loginAdmin`, (req, res) => {
|
||||
return loginAdmin(req.body)
|
||||
@@ -27,14 +27,14 @@ app.post(`${route}/loginOperador`, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.post(`${route}/entradaInvitado`, (req, res) => {
|
||||
return entradaInvitado(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
// app.post(`${route}/entradaInvitado`, (req, res) => {
|
||||
// return entradaInvitado(req.body)
|
||||
// .then((data) => {
|
||||
// res.status(200).json(data);
|
||||
// })
|
||||
// .catch((err) => {
|
||||
// res.status(400).json({ message: err.message });
|
||||
// });
|
||||
// });
|
||||
|
||||
module.exports = app;
|
||||
|
||||
@@ -3,5 +3,6 @@ const app = express();
|
||||
|
||||
app.use(require("./Usuario"));
|
||||
app.use(require("./Profesor"));
|
||||
app.use(require("./Invitado"));
|
||||
|
||||
module.exports = app;
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
numeroTrabajador,nombre,adscripcion
|
||||
316019251,Marco Antonio Romero,Adscripcion 1
|
||||
316019244,Jeremy Carreras,Adscripcion 2
|
||||
@@ -0,0 +1,3 @@
|
||||
numeroTrabajador,nombre,adscripcion
|
||||
316019251,Marco Antonio Romero,Adscripcion 1
|
||||
316019244,Jeremy Carreras,Adscripcion 2
|
||||
@@ -0,0 +1,3 @@
|
||||
numeroTrabajador,nombre,adscripcion
|
||||
316019251,Marco Antonio Romero,Adscripción 1
|
||||
316019244,Jeremy Carreras,Adscripción 2
|
||||
@@ -0,0 +1,3 @@
|
||||
numeroTrabajador,nombre,adscripcion
|
||||
3162019251,Marco Antonio Romero,Adscripcion 1
|
||||
3162019244,Jeremy Carreras,Adscripcion 2
|
||||
@@ -0,0 +1,3 @@
|
||||
numeroTrabajador,nombre,adscripcion
|
||||
33160149251,Marco Antonio Romero,Adscripcion 1
|
||||
3416219244,Jeremy Carreras,Adscripcion 2
|
||||
@@ -0,0 +1,3 @@
|
||||
numeroTrabajador,nombre,adscripcion
|
||||
331601492,Marco Antonio Romero,Adscripcion 1
|
||||
3416219244,Jeremy Carreras,Adscripcion 2
|
||||
Reference in New Issue
Block a user