Compare commits
44 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| de3046936f | |||
| 43551937cc | |||
| c914300997 | |||
| 8629858760 | |||
| a2ac9f2e5c | |||
| 6d85b66486 | |||
| 9d6a87854d | |||
| 703005ef5c | |||
| fb26d8adf7 | |||
| 63fc909859 | |||
| c3954b0110 | |||
| 21b37735b3 | |||
| 10dc4a0e3c | |||
| b1ff83b576 | |||
| ccd18dfe77 | |||
| 975aadcbea | |||
| 3d0043cbc1 | |||
| f8350e3961 | |||
| 9695122cdf | |||
| 5d895e99ec | |||
| b1b2b38d88 | |||
| 4cdadae9ba | |||
| e2a8dd5f98 | |||
| 2bb8336f8a | |||
| 3f1099b29b | |||
| 2cd8c0810c | |||
| 73d661cefc | |||
| 47f48a4464 | |||
| a9d148e714 | |||
| 591905d20e | |||
| 82b0d07c5c | |||
| 028cc45405 | |||
| 52a6cb614b | |||
| c5f488a7c9 | |||
| e8305da5a3 | |||
| 156daa4242 | |||
| 7586cb4aae | |||
| 80852bb2c9 | |||
| 4eb67e7f3f | |||
| 83da896aa4 | |||
| d311b3385d | |||
| 01885c6aef | |||
| c120c86409 | |||
| 7d4a8e150a |
Generated
+25
-8
@@ -19,11 +19,11 @@
|
||||
"dotenv": "^8.2.0",
|
||||
"express": "^4.17.1",
|
||||
"fs": "^0.0.1-security",
|
||||
"gmail-send": "^1.8.14",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"mariadb": "^2.5.3",
|
||||
"moment": "^2.29.1",
|
||||
"multer": "^1.4.4",
|
||||
"nodemailer": "^7.0.5",
|
||||
"sequelize": "^6.6.2",
|
||||
"validator": "^13.6.0"
|
||||
},
|
||||
@@ -1072,6 +1072,15 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/gmail-send": {
|
||||
"version": "1.8.14",
|
||||
"resolved": "https://registry.npmjs.org/gmail-send/-/gmail-send-1.8.14.tgz",
|
||||
"integrity": "sha512-hc+4Ej7ZJtw0G5sync10pmWkpPXIabkQ+p/a92lPPTXni3ChEU9sR2wxOvK6Hx+5Ou+2m9h1cVffWEgtR6Gzkw==",
|
||||
"dependencies": {
|
||||
"lodash": "^4.17.21",
|
||||
"nodemailer": "^6.6.5"
|
||||
}
|
||||
},
|
||||
"node_modules/got": {
|
||||
"version": "9.6.0",
|
||||
"resolved": "https://registry.npmjs.org/got/-/got-9.6.0.tgz",
|
||||
@@ -1759,10 +1768,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/nodemailer": {
|
||||
"version": "7.0.5",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-7.0.5.tgz",
|
||||
"integrity": "sha512-nsrh2lO3j4GkLLXoeEksAMgAOqxOv6QumNRVQTJwKH4nuiww6iC2y7GyANs9kRAxCexg3+lTWM3PZ91iLlVjfg==",
|
||||
"license": "MIT-0",
|
||||
"version": "6.7.2",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.7.2.tgz",
|
||||
"integrity": "sha512-Dz7zVwlef4k5R71fdmxwR8Q39fiboGbu3xgswkzGwczUfjp873rVxt1O46+Fh0j1ORnAC6L9+heI8uUpO6DT7Q==",
|
||||
"engines": {
|
||||
"node": ">=6.0.0"
|
||||
}
|
||||
@@ -3568,6 +3576,15 @@
|
||||
"ini": "2.0.0"
|
||||
}
|
||||
},
|
||||
"gmail-send": {
|
||||
"version": "1.8.14",
|
||||
"resolved": "https://registry.npmjs.org/gmail-send/-/gmail-send-1.8.14.tgz",
|
||||
"integrity": "sha512-hc+4Ej7ZJtw0G5sync10pmWkpPXIabkQ+p/a92lPPTXni3ChEU9sR2wxOvK6Hx+5Ou+2m9h1cVffWEgtR6Gzkw==",
|
||||
"requires": {
|
||||
"lodash": "^4.17.21",
|
||||
"nodemailer": "^6.6.5"
|
||||
}
|
||||
},
|
||||
"got": {
|
||||
"version": "9.6.0",
|
||||
"resolved": "https://registry.npmjs.org/got/-/got-9.6.0.tgz",
|
||||
@@ -4103,9 +4120,9 @@
|
||||
}
|
||||
},
|
||||
"nodemailer": {
|
||||
"version": "7.0.5",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-7.0.5.tgz",
|
||||
"integrity": "sha512-nsrh2lO3j4GkLLXoeEksAMgAOqxOv6QumNRVQTJwKH4nuiww6iC2y7GyANs9kRAxCexg3+lTWM3PZ91iLlVjfg=="
|
||||
"version": "6.7.2",
|
||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.7.2.tgz",
|
||||
"integrity": "sha512-Dz7zVwlef4k5R71fdmxwR8Q39fiboGbu3xgswkzGwczUfjp873rVxt1O46+Fh0j1ORnAC6L9+heI8uUpO6DT7Q=="
|
||||
},
|
||||
"nodemon": {
|
||||
"version": "2.0.15",
|
||||
|
||||
+1
-1
@@ -27,11 +27,11 @@
|
||||
"dotenv": "^8.2.0",
|
||||
"express": "^4.17.1",
|
||||
"fs": "^0.0.1-security",
|
||||
"gmail-send": "^1.8.14",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"mariadb": "^2.5.3",
|
||||
"moment": "^2.29.1",
|
||||
"multer": "^1.4.4",
|
||||
"nodemailer": "^7.0.5",
|
||||
"sequelize": "^6.6.2",
|
||||
"validator": "^13.6.0"
|
||||
},
|
||||
|
||||
@@ -13,21 +13,6 @@ app.use(
|
||||
})
|
||||
);
|
||||
|
||||
/*
|
||||
const alumnoRoutes = require('./routes/alumno');
|
||||
app.use('/alumnos', alumnoRoutes);
|
||||
*/
|
||||
|
||||
//agregue esto
|
||||
app.use(bodyParser.json()); // esto debe ir antes de app.use('/api', rutaProfesor)
|
||||
app.use(express.json());
|
||||
|
||||
|
||||
//const rutaProfesor = require('./routes/Profesor');
|
||||
//app.use('/api', rutaProfesor);
|
||||
app.use('/api/profesores', require('./routes/Profesor'));
|
||||
|
||||
|
||||
app.use(bodyParser.json());
|
||||
|
||||
app.get('/', (req, res) => res.send('API de Inscripciones a CEDETEC'));
|
||||
|
||||
@@ -9,5 +9,3 @@ try {
|
||||
} catch (err) {
|
||||
console.log('El archivo .env no se cargo.'.underline.bold.red);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,31 +1,24 @@
|
||||
require('./config');
|
||||
const mariadb = require('mariadb');
|
||||
|
||||
const pool1 = mariadb.createPool({
|
||||
host: process.env.SAT_HOST,
|
||||
user: process.env.SAT_USER,
|
||||
password: process.env.SAT_PASSWORD,
|
||||
database: process.env.SATL_DB,
|
||||
});
|
||||
|
||||
const pool2 = mariadb.createPool({
|
||||
const pool = mariadb.createPool({
|
||||
host: process.env.HOST_DB,
|
||||
user: process.env.USER_DB,
|
||||
password: process.env.PASSWORD_DB,
|
||||
database: process.env.SATE_DB,
|
||||
database: process.env.SAT_DB,
|
||||
});
|
||||
|
||||
const obtenerIdCarrera = async (numeroCuenta) => {
|
||||
const conn = await pool1.getConnection().catch((err) => {
|
||||
const obtenerDatosUsr = async (numeroCuenta) => {
|
||||
const conn = await pool.getConnection().catch((err) => {
|
||||
throw new Error('No se pudo conectar con la db. ' + err);
|
||||
});
|
||||
|
||||
return conn
|
||||
.query(`SELECT id_carrera FROM alumno WHERE id_cuenta = ${numeroCuenta}`)
|
||||
.query(
|
||||
`SELECT id_carrera, generacion FROM alumno WHERE id_cuenta = ${numeroCuenta}`
|
||||
)
|
||||
.then((rows) => {
|
||||
conn.end();
|
||||
// console.log(rows[0]);
|
||||
// if (rows[0].length === 0) return null;
|
||||
return rows[0];
|
||||
})
|
||||
.catch((err) => {
|
||||
@@ -35,7 +28,7 @@ const obtenerIdCarrera = async (numeroCuenta) => {
|
||||
};
|
||||
|
||||
const obtenerCarrera = async (idCarrera) => {
|
||||
const conn = await pool1.getConnection().catch((err) => {
|
||||
const conn = await pool.getConnection().catch((err) => {
|
||||
throw new Error('No se pudo conectar con la db. ' + err);
|
||||
});
|
||||
|
||||
@@ -51,14 +44,14 @@ const obtenerCarrera = async (idCarrera) => {
|
||||
});
|
||||
};
|
||||
|
||||
const usuarioInscrito = async (numeroCuenta) => {
|
||||
const conn = await pool2.getConnection().catch((err) => {
|
||||
const usuarioInscrito = async (numeroCuenta, idArea) => {
|
||||
const conn = await pool.getConnection().catch((err) => {
|
||||
throw new Error('No se pudo conectar con la db. ' + err);
|
||||
});
|
||||
|
||||
return conn
|
||||
.query(
|
||||
`INSERT INTO alumno_inscrito(id_cuenta,id_periodo,id_plataforma,realizo_pago,platica) values(${numeroCuenta}, 20, 4, 1, 1)`
|
||||
`INSERT INTO alumno_inscrito(realizo_pago, id_cuenta, id_periodo, id_plataforma) values(1, ${numeroCuenta}, 20, ${idArea})`
|
||||
)
|
||||
.then((rows) => {
|
||||
conn.end();
|
||||
@@ -70,42 +63,106 @@ const usuarioInscrito = async (numeroCuenta) => {
|
||||
});
|
||||
};
|
||||
|
||||
// Agregue para profesores
|
||||
const buscarProfesorPorNumero = async (numeroTrabajador) => {
|
||||
const conn = await pool2.getConnection().catch((err) => {
|
||||
throw new Error('No se pudo conectar con la base de datos. ' + err);
|
||||
const agregarRecibo = async (folio, monto, fechaTicket, numeroCuenta) => {
|
||||
const conn = await pool.getConnection().catch((err) => {
|
||||
throw new Error('No se pudo conectar con la db. ' + err);
|
||||
});
|
||||
|
||||
return conn
|
||||
.query(
|
||||
`SELECT nombre, idUsuario, numeroCuenta FROM usuario WHERE numeroCuenta = ?`,
|
||||
[numeroTrabajador] // NUmero de cuenta
|
||||
`INSERT INTO recibo(folio_recibo, monto, fecha_recibo, fecha_registro, id_cuenta, id_usuario) values(${folio}, ${monto}, STR_TO_DATE('${fechaTicket}', '%m/%d/%Y'), now() ,${numeroCuenta}, 134)`
|
||||
)
|
||||
.then((rows) => {
|
||||
conn.end();
|
||||
if (rows.length === 0) return null;
|
||||
return rows[0]; // { nombre: 'Juan', rfc: 'JUAP123' }
|
||||
return rows[0];
|
||||
})
|
||||
.catch((err) => {
|
||||
conn.end();
|
||||
throw new Error('Error al buscar el profesor: ' + err);
|
||||
throw new Error('Hubo un problema con el querry.' + err);
|
||||
});
|
||||
};
|
||||
|
||||
// Para envios de correos
|
||||
const nodemailer = require('nodemailer');
|
||||
|
||||
const enviarCorreoInscripcion = async (destinatario, nombreProfesor) => {
|
||||
const transporter = nodemailer.createTransport({
|
||||
service: 'gmail', // o smtp host como 'smtp.mailtrap.io'
|
||||
auth: {
|
||||
type: 'OAuth2',
|
||||
user: process.env.CORREO_ORIGEN,
|
||||
clientId: process.env.CLIENT_ID,
|
||||
clientSecret: process.env.CLIENT_SECRET,
|
||||
refreshToken: process.env.REFRESH_TOKEN,
|
||||
},
|
||||
const agregarDetalleServicio = async (monto, numeroCuenta) => {
|
||||
const conn = await pool.getConnection().catch((err) => {
|
||||
throw new Error('No se pudo conectar con la db. ' + err);
|
||||
});
|
||||
|
||||
return conn
|
||||
.query(
|
||||
`INSERT INTO detalle_servicio(monto, numero_hojas, id_cuenta, id_servicio, id_usuario, id_periodo) values(${monto}, 0, ${numeroCuenta}, 4, 134, 20)`
|
||||
)
|
||||
.then((rows) => {
|
||||
conn.end();
|
||||
return rows[0];
|
||||
})
|
||||
.catch((err) => {
|
||||
conn.end();
|
||||
throw new Error('Hubo un problema con el querry.' + err);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = { obtenerIdCarrera, obtenerCarrera, usuarioInscrito, buscarProfesorPorNumero };
|
||||
const borrarInscripcion = async (numeroCuenta) => {
|
||||
const conn = await pool.getConnection().catch((err) => {
|
||||
throw new Error('No se pudo conectar con la db. ' + err);
|
||||
});
|
||||
|
||||
return conn
|
||||
.query(
|
||||
`DELETE FROM alumno_inscrito WHERE id_cuenta = ${numeroCuenta} AND periodo = 20`
|
||||
)
|
||||
.then((rows) => {
|
||||
conn.end();
|
||||
return rows[0];
|
||||
})
|
||||
.catch((err) => {
|
||||
conn.end();
|
||||
throw new Error('Hubo un problema con el querry.' + err);
|
||||
});
|
||||
};
|
||||
|
||||
const borrarRecibo = async (folio) => {
|
||||
const conn = await pool.getConnection().catch((err) => {
|
||||
throw new Error('No se pudo conectar con la db. ' + err);
|
||||
});
|
||||
|
||||
return conn
|
||||
.query(`DELETE FROM recibo WHERE folio_recibo = ${folio}`)
|
||||
.then((rows) => {
|
||||
conn.end();
|
||||
return rows[0];
|
||||
})
|
||||
.catch((err) => {
|
||||
conn.end();
|
||||
throw new Error('Hubo un problema con el querry.' + err);
|
||||
});
|
||||
};
|
||||
|
||||
const borrarDetalleServicio = async (numeroCuenta) => {
|
||||
const conn = await pool.getConnection().catch((err) => {
|
||||
throw new Error('No se pudo conectar con la db. ' + err);
|
||||
});
|
||||
|
||||
return conn
|
||||
.query(
|
||||
`DELETE FROM detalle_servicio WHERE id_Cuenta = ${numeroCuenta} AND id_servicio = 4 AND id_periodo = 20`
|
||||
)
|
||||
.then((rows) => {
|
||||
conn.end();
|
||||
return rows[0];
|
||||
})
|
||||
.catch((err) => {
|
||||
conn.end();
|
||||
throw new Error('Hubo un problema con el querry.' + err);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
obtenerDatosUsr,
|
||||
obtenerCarrera,
|
||||
usuarioInscrito,
|
||||
agregarRecibo,
|
||||
agregarDetalleServicio,
|
||||
borrarInscripcion,
|
||||
borrarRecibo,
|
||||
borrarDetalleServicio,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
const dbPath = '../../db/tablas';
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
const { Op } = require('sequelize');
|
||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||
|
||||
const actualizarTicket = async (body) => {
|
||||
const idInscripcion = validarNumeroEntero(
|
||||
body.idInscripcion,
|
||||
'id Inscripcion',
|
||||
true
|
||||
);
|
||||
const monto = validarNumeroEntero(body.monto, 'monto', true);
|
||||
const folio = validarNumeroEntero(body.folio, 'folio', true);
|
||||
|
||||
return Inscripcion.findOne({
|
||||
where: {
|
||||
idInscripcion,
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No pudimos encontrar este ticket.');
|
||||
return Inscripcion.findOne({
|
||||
where: {
|
||||
folio,
|
||||
cancelacion: 0,
|
||||
idInscripcion: { [Op.ne]: idInscripcion },
|
||||
},
|
||||
});
|
||||
})
|
||||
.then((res) => {
|
||||
if (res)
|
||||
throw new Error('¡ Este folio ya fue utilizado por otra inscripción !');
|
||||
})
|
||||
.then((res) => {
|
||||
return Inscripcion.update(
|
||||
{
|
||||
folio,
|
||||
monto,
|
||||
fechaTicket: body.fechaTicket,
|
||||
},
|
||||
{
|
||||
where: {
|
||||
idInscripcion,
|
||||
},
|
||||
}
|
||||
);
|
||||
})
|
||||
.then((res) => ({
|
||||
message:
|
||||
'¡ Los datos de la inscripción fueron actualizados de forma correcta !',
|
||||
}))
|
||||
.catch((err) => {
|
||||
throw new Error('No fue posible actualizar los datos del ticket. ' + err);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = actualizarTicket;
|
||||
@@ -0,0 +1,36 @@
|
||||
const dbPath = '../../db/tablas';
|
||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
|
||||
const cancelarInscripcion = async (body) => {
|
||||
const idInscripcion = validarNumeroEntero(
|
||||
body.idInscripcion,
|
||||
'id Inscripcion',
|
||||
true
|
||||
);
|
||||
|
||||
return Inscripcion.findOne({
|
||||
where: { idInscripcion },
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('Lo sentimos esta inscripción no existe.');
|
||||
return Inscripcion.update(
|
||||
{
|
||||
cancelacion: 1,
|
||||
},
|
||||
{
|
||||
where: {
|
||||
idInscripcion,
|
||||
},
|
||||
}
|
||||
);
|
||||
})
|
||||
.then((res) => ({
|
||||
message: '¡ Esta inscripción fue cancelada de forma correcta !',
|
||||
}))
|
||||
.catch((err) => {
|
||||
throw new Error('¡ No fue posible validar la inscripción !. ');
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = cancelarInscripcion;
|
||||
@@ -0,0 +1,23 @@
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||
|
||||
const motivo = async (body) => {
|
||||
const folio = validarNumeroEntero(body.folio, 'folio', true);
|
||||
|
||||
return Inscripcion.findOne({
|
||||
where: { folio },
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No pudimos encontrar este ticket.');
|
||||
return Inscripcion.findOne({
|
||||
where: { folio, validacion: 0 },
|
||||
attributes: ['motivo'],
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new Error('No fue posible encontrar el ticket. ' + err);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = motivo;
|
||||
@@ -29,30 +29,17 @@ const reporte = async (body) => {
|
||||
],
|
||||
})
|
||||
.then(async (res) => {
|
||||
if (body.tipo === 'CSV') {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
data.push({
|
||||
numero_cuenta: res[i].Usuario.numeroCuenta,
|
||||
id_area: res[i].idArea,
|
||||
folio: res[i].folio,
|
||||
monto: res[i].monto,
|
||||
hizo_pago: res[i].hizoPago,
|
||||
fecha_inscripcion: moment(res[i].fechaInscripcion).format('L'),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
data.push({
|
||||
numeroCuenta: res[i].Usuario.numeroCuenta,
|
||||
validacion: res[i].validacion,
|
||||
confirmacion: res[i].confirmacion,
|
||||
folio: res[i].folio,
|
||||
monto: res[i].monto,
|
||||
hizoPago: res[i].hizoPago,
|
||||
fechaInscripcion: moment(res[i].fechaInscripcion).format('L'),
|
||||
idArea: res[i].idArea,
|
||||
});
|
||||
}
|
||||
for (let i = 0; i < res.length; i++) {
|
||||
data.push({
|
||||
numeroCuenta: res[i].Usuario.numeroCuenta,
|
||||
idArea: res[i].idArea,
|
||||
folio: res[i].folio,
|
||||
monto: res[i].monto,
|
||||
hizoPago: res[i].hizoPago,
|
||||
fechaInscripcion: moment(res[i].fechaInscripcion).format('L'),
|
||||
validacion: res[i].validacion,
|
||||
motivoDeclinacion: res[i].motivo,
|
||||
});
|
||||
}
|
||||
await helper.eliminarArchivo(path).catch((err) => {});
|
||||
return helper.crearArchivo(path, convertArrayToCSV(data));
|
||||
|
||||
@@ -1,14 +1,25 @@
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||
|
||||
const ticket = async (body) => {
|
||||
const folio = validarNumeroEntero(body.folio, 'folio', true);
|
||||
|
||||
return Inscripcion.findOne({
|
||||
where: { folio: body.folio },
|
||||
attributes: ['rutaTicket', 'extension'],
|
||||
}).then((res) => {
|
||||
return { rutaTicket: res.rutaTicket, extension: res.extension };
|
||||
});
|
||||
attributes: ['rutaTicket', 'extension', 'motivo'],
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('No pudimos encontrar este ticket.');
|
||||
return {
|
||||
rutaTicket: res.rutaTicket,
|
||||
extension: res.extension,
|
||||
motivo: res.motivo,
|
||||
};
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new Error('No fue posible validar el ticket. ' + err);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = ticket;
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const { Op } = require('sequelize');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
|
||||
const todasInscripciones = async (body) => {
|
||||
// const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
|
||||
const validacion = validarNumeroEntero(body.validacion, 'validacion', true);
|
||||
return Inscripcion.findAll({
|
||||
where: { validacion: body.validacion },
|
||||
where: { validacion, cancelacion: 0 },
|
||||
include: [
|
||||
{
|
||||
model: Usuario,
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
const dbPath = '../../db/tablas';
|
||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
|
||||
const validarSinTicket = async (body) => {
|
||||
const idUsuario = validarNumeroEntero(body.idUsuario, 'usuario', true);
|
||||
return Inscripcion.update(
|
||||
{
|
||||
validacion: 1,
|
||||
},
|
||||
{
|
||||
where: {
|
||||
idUsuario,
|
||||
},
|
||||
}
|
||||
)
|
||||
.then((res) => ({
|
||||
message: '¡El ticket a sido validado de forma correcta!',
|
||||
}))
|
||||
.catch((err) => {
|
||||
throw new Error('¡ No fue posible validar la inscripción !. ');
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = validarSinTicket;
|
||||
@@ -1,47 +1,88 @@
|
||||
const {
|
||||
validarNumeroEntero,
|
||||
validarNumeroCuenta,
|
||||
} = require('../../helper/validar');
|
||||
const {
|
||||
borrarInscripcion,
|
||||
borrarRecibo,
|
||||
borrarDetalleServicio,
|
||||
} = require('../../config/mariadb.conf');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
const { usuarioInscrito } = require('../../config/mariadb.conf');
|
||||
const gmail = require('../../helper/gmail');
|
||||
const correoDeclinar = require('../../helper/correoDeclinar');
|
||||
|
||||
const validarTicket = async (body) => {
|
||||
return Inscripcion.findOne({
|
||||
where: { folio: body.folio },
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('Este folio no existe');
|
||||
idUsuario = res.idUsuario;
|
||||
return Inscripcion.update(
|
||||
{
|
||||
validacion: body.validacion,
|
||||
},
|
||||
{
|
||||
where: {
|
||||
folio: body.folio,
|
||||
},
|
||||
const folio = validarNumeroEntero(body.folio, 'folio', true);
|
||||
const numeroCuenta = validarNumeroCuenta(
|
||||
body.numeroCuenta,
|
||||
'número de cuenta',
|
||||
true
|
||||
);
|
||||
|
||||
let correo = {};
|
||||
let email = '';
|
||||
|
||||
return (
|
||||
Inscripcion.findOne({
|
||||
where: { folio },
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) throw new Error('Este folio no existe');
|
||||
idUsuario = res.idUsuario;
|
||||
if (body.validacion == 1) {
|
||||
return Inscripcion.findOne({
|
||||
where: { folio, validacion: 1 },
|
||||
});
|
||||
}
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
if (body.validacion === 0)
|
||||
throw new Error(
|
||||
'El administrador a declinado el ticket, ya que los datos no coinciden.'
|
||||
})
|
||||
.then((res) => {
|
||||
if (res) throw new Error('Este folio ya fue validado');
|
||||
return Inscripcion.update(
|
||||
{
|
||||
validacion: body.validacion,
|
||||
},
|
||||
{
|
||||
where: {
|
||||
folio,
|
||||
cancelacion: 0,
|
||||
},
|
||||
}
|
||||
);
|
||||
})
|
||||
.then((res) => {
|
||||
return Usuario.findOne({
|
||||
where: { idUsuario },
|
||||
attributes: ['numeroCuenta'],
|
||||
}).then((res) => {
|
||||
return usuarioInscrito(res.numeroCuenta).then(async (res) => {
|
||||
})
|
||||
//el ticket ya fue validado
|
||||
.then((res) => {
|
||||
if (body.validacion === 0) {
|
||||
email = `${numeroCuenta}@pcpuma.acatlan.unam.mx`;
|
||||
correoDeclinar = correoInscripciones();
|
||||
borrarInscripcion(numeroCuenta);
|
||||
borrarRecibo(folio);
|
||||
borrarDetalleServicio(numeroCuenta);
|
||||
return Inscripcion.update(
|
||||
{ motivo: body.motivo },
|
||||
{
|
||||
where: {
|
||||
folio,
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
})
|
||||
.then((res) => {
|
||||
if (body.validacion === 1) {
|
||||
//Insertar en AD
|
||||
return {
|
||||
message: '¡ El ticket a sido validado de forma correcta !',
|
||||
message: '¡El ticket a sido validado de forma correcta!',
|
||||
};
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new Error('No fue posible validar el ticket. ' + err);
|
||||
});
|
||||
} else
|
||||
return {
|
||||
message: '¡El ticket a sido declinado',
|
||||
};
|
||||
})
|
||||
.catch((err) => {
|
||||
throw new Error('No fue posible validar el ticket. ' + err);
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
module.exports = validarTicket;
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
const { buscarProfesorPorNumero } = require('../../config/mariadb.conf');
|
||||
const Inscripcion = require('../../db/tablas/Inscripcion');
|
||||
|
||||
async function buscarProfesor(req, res) {
|
||||
const { numeroTrabajador } = req.params;
|
||||
|
||||
try {
|
||||
// Borrar esta linea de codigo
|
||||
//console.log('Buscando profesor con RFC:', numeroTrabajador);
|
||||
|
||||
const profesor = await buscarProfesorPorNumero(numeroTrabajador);
|
||||
|
||||
if (!profesor) {
|
||||
return res.status(404).json({ message: 'Profesor no encontrado' });
|
||||
}
|
||||
|
||||
// Verificar si existe ya en la tabla de incripcion
|
||||
const existeIncripcion = await Inscripcion.findOne({
|
||||
where: {
|
||||
idUsuario: profesor.idUsuario
|
||||
}
|
||||
});
|
||||
|
||||
if (existeIncripcion) {
|
||||
return res.status(409).json({
|
||||
//yaInscrito: true,
|
||||
message: 'El usuario ya está inscrito.',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
res.status(200).json(profesor); // { nombre, correo }
|
||||
} catch (error) {
|
||||
res.status(500).json({ message: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = buscarProfesor;
|
||||
@@ -1,23 +0,0 @@
|
||||
|
||||
/*const { inscripcion } = require('../../db/tablas/Inscripcion')
|
||||
|
||||
const confirmacionInscripcion = async (req, res) => {
|
||||
try {
|
||||
const { idUsuario } = req.body;
|
||||
|
||||
const [update] = await inscripcion.update(
|
||||
{ confirmacion: true},
|
||||
{ where: { idUsuario } }
|
||||
);
|
||||
|
||||
if (update > 0) {
|
||||
return res.status(200).json({ message: 'Inscripción confirmada con éxito.'});
|
||||
} else {
|
||||
return res.status(404).json({ message: 'No se encontro la inscripcion para confirmar'});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error al confirmar inscripcion: ', error);
|
||||
return res.status(500).json({ message: 'Error al confirmar inscripcion.'});
|
||||
}
|
||||
}
|
||||
*/
|
||||
@@ -1,36 +0,0 @@
|
||||
const nodemailer = require('nodemailer');
|
||||
|
||||
async function enviarCorreoInscripcion(correo, nombre) {
|
||||
const transporter = nodemailer.createTransport({
|
||||
service: 'gmail',
|
||||
auth: {
|
||||
type: 'OAuth2',
|
||||
user: process.env.CORREO_ORIGEN,
|
||||
clientId: process.env.CLIENT_ID,
|
||||
clientSecret: process.env.CLIENT_SECRET,
|
||||
refreshToken: process.env.REFRESH_TOKEN,
|
||||
}
|
||||
});
|
||||
|
||||
const mailOptions = {
|
||||
from: '"CEDETEC"',
|
||||
to: correo,
|
||||
subject: 'Confirmación de inscripción CEDETEC',
|
||||
html: `
|
||||
<ol>
|
||||
<p>Estimado profesor(a) ${nombre}</p>
|
||||
<p><strong>Informo que su inscripción fue realizad con éxito.</strong></p>
|
||||
</ol>
|
||||
<strong>¿Cómo puede hacer uso de los servicios?</strong>
|
||||
<p>Es necesario revise los siguientes <a href="https://cedetec.acatlan.unam.mx/DSC/servicios#lineamientos-uso" target="_blank" style="color: blue; text-decoration: underline;">
|
||||
videos
|
||||
</a> para solicitar equipo en el área de profesores.</p>
|
||||
<p><strong>Nota</strong>: Es importante revisar los <a href="https://cedetec.acatlan.unam.mx/DSC/servicios#videos-tutoriales" target="_blank" style="color: blue; text-decoration: underline;">
|
||||
lineamientos</a> de uso para hacer uso de los servicios que ofrece el CEDETEC. </p>
|
||||
`
|
||||
};
|
||||
|
||||
await transporter.sendMail(mailOptions);
|
||||
}
|
||||
|
||||
module.exports = enviarCorreoInscripcion;
|
||||
@@ -1,66 +0,0 @@
|
||||
const Usuario = require('../../db/tablas/Usuario'); // Asegúrate de importar correctamente
|
||||
const inscripcion = require('../../db/tablas/Inscripcion');
|
||||
const enviarCorreoInscripcion = require('../../controller/Profesor/enviarCorreo'); // Ajusta si está en otra ruta
|
||||
const { where } = require('sequelize');
|
||||
|
||||
async function realizarInscripcion(req, res) {
|
||||
const { idUsuario, nombre, numeroCuenta, correo } = req.body;
|
||||
|
||||
try {
|
||||
if (!nombre || !numeroCuenta || !idUsuario) {
|
||||
return res.status(400).json({ message: 'Faltan datos requeridos.' });
|
||||
}
|
||||
|
||||
// 1. Buscar si el usuario existe
|
||||
const usuario = await Usuario.findOne({ where: { numeroCuenta } });
|
||||
|
||||
if (!usuario) {
|
||||
return res.status(404).json({ message: 'Usuario no encontrado en la base de datos.' });
|
||||
}
|
||||
|
||||
// 2. Verificar si ya tiene inscripción
|
||||
const inscripcionExistente = await inscripcion.findOne({
|
||||
where: { idUsuario: usuario.idUsuario }
|
||||
});
|
||||
|
||||
if (inscripcionExistente) {
|
||||
return res.status(200).json({
|
||||
yaInscrito: true,
|
||||
message: 'El usuario ya está inscrito.',
|
||||
});
|
||||
}
|
||||
|
||||
// 3. Crear inscripción
|
||||
await inscripcion.create({
|
||||
idUsuario: usuario.idUsuario,
|
||||
idArea: 1, // Cambiar si se requiere otro valor
|
||||
validacion: 2,
|
||||
confirmacion: false,
|
||||
folio: null,
|
||||
monto: null,
|
||||
hizoPago: null,
|
||||
rutaTicket: null,
|
||||
extension: null,
|
||||
fechaInscripcion: null, // fechaInscripcion: new Date()
|
||||
fechaTicket: null
|
||||
});
|
||||
|
||||
// 4. Realizar confirmacion
|
||||
await inscripcion.update(
|
||||
{ confirmacion: true },
|
||||
{ where: { idUsuario: usuario.idUsuario } }
|
||||
);
|
||||
|
||||
// 5. Enviar correo
|
||||
await enviarCorreoInscripcion(correo, nombre);
|
||||
|
||||
// 6. Respuesta final
|
||||
res.status(200).json({ message: 'Inscripción creada y correo enviado correctamente.' });
|
||||
|
||||
} catch (error) {
|
||||
console.error('Error en realizarInscripcion:', error);
|
||||
res.status(500).json({ message: 'Error al procesar la inscripción o enviar el correo.' });
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { realizarInscripcion };
|
||||
@@ -1,37 +1,35 @@
|
||||
const {
|
||||
obtenerIdCarrera,
|
||||
obtenerCarrera,
|
||||
} = require('../../config/mariadb.conf');
|
||||
const validar = require('../../helper/validar');
|
||||
const { obtenerDatosUsr } = require('../../config/mariadb.conf');
|
||||
const { validarNumeroCuenta } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Usuario = require(`${dbPath}/Usuario`);
|
||||
|
||||
const escolares = async (body) => {
|
||||
// const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
|
||||
|
||||
const numeroCuenta = validarNumeroCuenta(
|
||||
body.numeroCuenta,
|
||||
'numero cuenta',
|
||||
true
|
||||
);
|
||||
return Usuario.findOne({
|
||||
where: { numeroCuenta: body.numeroCuenta },
|
||||
where: { numeroCuenta },
|
||||
}).then((res) => {
|
||||
if (!res) {
|
||||
return obtenerIdCarrera(body.numeroCuenta).then(async (res) => {
|
||||
return Usuario.create({
|
||||
idUsuario: body.idUsuario,
|
||||
numeroCuenta: body.numeroCuenta,
|
||||
return obtenerDatosUsr(numeroCuenta).then(async (res) => {
|
||||
await Usuario.create({
|
||||
numeroCuenta,
|
||||
nombre: body.nombre,
|
||||
semestre: 8,
|
||||
generacion: res.generacion,
|
||||
carrera: body.carrera,
|
||||
idCarrera: res.id_carrera,
|
||||
});
|
||||
});
|
||||
}
|
||||
return Usuario.findOne({
|
||||
where: { numeroCuenta: body.numeroCuenta },
|
||||
where: { numeroCuenta },
|
||||
attributes: [
|
||||
'idUsuario',
|
||||
'numeroCuenta',
|
||||
'nombre',
|
||||
'semestre',
|
||||
'generacion',
|
||||
'idCarrera',
|
||||
'carrera',
|
||||
],
|
||||
|
||||
@@ -1,28 +1,49 @@
|
||||
const moment = require('moment');
|
||||
const fs = require('fs');
|
||||
const { validarNumeroEntero, validarNumero } = require('../../helper/validar');
|
||||
const {
|
||||
usuarioInscrito,
|
||||
agregarRecibo,
|
||||
agregarDetalleServicio,
|
||||
} = require('../../config/mariadb.conf');
|
||||
const {
|
||||
validarNumeroEntero,
|
||||
validarNumero,
|
||||
validarNumeroCuenta,
|
||||
} = require('../../helper/validar');
|
||||
const { eliminarArchivo } = require('../../helper/helper');
|
||||
const gmail = require('../../helper/gmail');
|
||||
const correoInscripciones = require('../../helper/correo');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||
|
||||
const inscripcion = async (body, file) => {
|
||||
const ahora = moment();
|
||||
const idUsuario = validarNumeroEntero(body.idUsuario, 'id Usuario', true);
|
||||
const numeroCuenta = validarNumeroCuenta(
|
||||
body.numeroCuenta,
|
||||
'numero de cuenta',
|
||||
true
|
||||
);
|
||||
const idArea = validarNumeroEntero(body.idArea, 'id Area', true);
|
||||
const monto = validarNumero(body.monto, 'monto', true);
|
||||
const folio = body.folio;
|
||||
const folio = validarNumero(body.folio, 'folio', true, 6);
|
||||
const fechaTicket = body.fechaTicket;
|
||||
|
||||
let correo = {};
|
||||
let email = '';
|
||||
|
||||
return Inscripcion.findOne({
|
||||
where: { folio },
|
||||
where: { folio, cancelacion: 0 },
|
||||
})
|
||||
.then((res) => {
|
||||
if (res) throw new Error('Este folio ya esta registrado');
|
||||
return Inscripcion.findOne({
|
||||
where: { idUsuario, idArea },
|
||||
where: { idUsuario, idArea, cancelacion: 0 },
|
||||
}).then((res) => {
|
||||
if (res) throw new Error('Ya estas registrado en esta área');
|
||||
if (file) {
|
||||
email = `${numeroCuenta}@pcpuma.acatlan.unam.mx`;
|
||||
correo = correoInscripciones();
|
||||
if (file && folio && fechaTicket) {
|
||||
return Inscripcion.create({
|
||||
idUsuario,
|
||||
idArea,
|
||||
@@ -32,7 +53,7 @@ const inscripcion = async (body, file) => {
|
||||
rutaTicket: file.path,
|
||||
extension: file.mimetype.split('/')[1],
|
||||
fechaInscripcion: ahora.format(),
|
||||
fechaTicket: body.fechaTicket,
|
||||
fechaTicket,
|
||||
});
|
||||
} else {
|
||||
return Inscripcion.create({
|
||||
@@ -47,10 +68,19 @@ const inscripcion = async (body, file) => {
|
||||
.then((res) => {
|
||||
if (file)
|
||||
fs.renameSync(file.path, file.path + '.' + file.mimetype.split('/')[1]);
|
||||
usuarioInscrito(numeroCuenta, idArea);
|
||||
agregarRecibo(
|
||||
folio,
|
||||
monto,
|
||||
moment(fechaTicket).format('L'),
|
||||
numeroCuenta
|
||||
);
|
||||
agregarDetalleServicio(monto, numeroCuenta);
|
||||
return gmail(correo.subject, email, correo.msj);
|
||||
})
|
||||
.then((res) => ({
|
||||
message:
|
||||
'¡La inscripción se realizo de manera correcta! Tu inscripción esta sujeta a revisión en caso de no ser correcta se suspende el servicio',
|
||||
'Tu inscripción está sujeta a validación, en caso de no ser correcta o veraz el servicio será suspendido. Por favor revisa tu correo de PCPUMA para confirmar tu registro.',
|
||||
}))
|
||||
.catch((err) => {
|
||||
if (file) eliminarArchivo(file.path);
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
const validar = require('../../helper/validar');
|
||||
const { validarNumeroEntero } = require('../../helper/validar');
|
||||
const dbPath = '../../db/tablas';
|
||||
const Carrera = require(`${dbPath}/Carrera`);
|
||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||
|
||||
const inscripciones = async (body) => {
|
||||
// const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
|
||||
const idUsuario = validarNumeroEntero(body.idUsuario, 'Usuario', true);
|
||||
|
||||
return Inscripcion.findAll({
|
||||
where: { idUsuario: body.idUsuario },
|
||||
where: { idUsuario },
|
||||
}).then((res) => {
|
||||
if (!res) return [];
|
||||
return Inscripcion.findAll({
|
||||
where: { idUsuario: body.idUsuario },
|
||||
where: { idUsuario, cancelacion: 0 },
|
||||
attributes: [
|
||||
'idInscripcion',
|
||||
'validacion',
|
||||
'confirmacion',
|
||||
'folio',
|
||||
'monto',
|
||||
'idUsuario',
|
||||
|
||||
@@ -5,17 +5,16 @@ const { crearToken } = require('../../middleware/autentificacion');
|
||||
const Usuario = require('../../db/tablas/Usuario');
|
||||
|
||||
const login = async (body) => {
|
||||
const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
|
||||
const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta, 'número de cuenta', true);
|
||||
const data = {
|
||||
usuario: 'votacionesUser',
|
||||
password: 'poasfnr*/049_]',
|
||||
numeroCuenta: numeroCuenta,
|
||||
passwordUser: body.passwordUser,
|
||||
};
|
||||
|
||||
console.log(numeroCuenta, body.passwordUser);
|
||||
passwordUser: body.passwordUser
|
||||
}
|
||||
|
||||
return axios
|
||||
.post(
|
||||
.post(
|
||||
`https://venus.acatlan.unam.mx/conexionEscolares_test/ingresarAlumno`,
|
||||
data
|
||||
)
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
const Usuario = require('./tablas/Usuario');
|
||||
const { encriptar } = require('../helper/encriptar');
|
||||
|
||||
const dataUsuarios = async () => {
|
||||
let usuario = ['416313221', '111111111', '222222222'];
|
||||
let nombre = [
|
||||
'Adriana De Luna Ramirez',
|
||||
'Nombre Falso 1',
|
||||
'Nombre Falso 2',
|
||||
];
|
||||
|
||||
for (let i = 0; i < usuario.length; i++) {
|
||||
await Usuario.create({
|
||||
usuario: usuario[i],
|
||||
nombre: nombre[i],
|
||||
password: encriptar('holi'),
|
||||
idTipoUsuario: 2,
|
||||
});
|
||||
console.log(`Se insertó el usuario ${usuario[i]}.`.magenta);
|
||||
}
|
||||
};
|
||||
|
||||
const exec = async () => {
|
||||
await dataUsuarios();
|
||||
console.log(
|
||||
'\nSe ha instalado exitosamente la información falsa en la base de datos.\n'
|
||||
.underline.bold.green
|
||||
);
|
||||
process.exit();
|
||||
};
|
||||
|
||||
exec();
|
||||
+1
-30
@@ -7,8 +7,6 @@ const Area = require('./tablas/Area');
|
||||
const FechaInscripcion = require('./tablas/FechaInscripcion');
|
||||
const Inscripcion = require('./tablas/Inscripcion');
|
||||
const Admin = require('./tablas/Admin');
|
||||
const ProfesorInscrito = require('./tablas/ProfesorInscrito');
|
||||
const Profesor = require('./tablas/Profesor');
|
||||
|
||||
const drop = async () => {
|
||||
console.log('\nPaso 1) Desinstalando la db.'.bold.blue);
|
||||
@@ -30,15 +28,6 @@ const drop = async () => {
|
||||
|
||||
await Carrera.drop();
|
||||
console.log('La tabla Carrera se desinstalo correctamente.'.magenta);
|
||||
/*
|
||||
await ProfesorInscrito.drop();
|
||||
console.log('La tabla ProfesorInscrito se desinstalo correctamente.'.magenta);
|
||||
|
||||
await Profesor.drop();
|
||||
console.log('La tabla Profesor se desinstalo correctamente.'.magenta);
|
||||
*/
|
||||
//await ProfesorInscrito.drop().catch(console.error); // Tiene FK hacia Profesor
|
||||
//await Profesor.drop().catch(console.error);
|
||||
};
|
||||
|
||||
const sync = async () => {
|
||||
@@ -61,18 +50,10 @@ const sync = async () => {
|
||||
|
||||
await Inscripcion.sync();
|
||||
console.log('La tabla Inscripcion se instalo correctamente.'.magenta);
|
||||
|
||||
/*
|
||||
await Profesor.sync();
|
||||
console.log('La tabla Profesor se instalo correctamente.'.magenta);
|
||||
|
||||
await ProfesorInscrito.sync();
|
||||
console.log('La tabla ProfesorInscrito se instalo correctamente.'.magenta);
|
||||
*/
|
||||
};
|
||||
|
||||
const dataArea = async () => {
|
||||
const data = ['Windows', 'Macintosh', 'Linux', 'Mesa para laptop'];
|
||||
const data = ['Windows', 'Macintosh', 'Linux'];
|
||||
|
||||
console.log('\nPaso 3) Instalando catalogo area.'.bold.blue);
|
||||
for (let i = 0; i < data.length; i++) await Area.create({ area: data[i] });
|
||||
@@ -80,16 +61,6 @@ const dataArea = async () => {
|
||||
|
||||
const dataAdmin = async () => {
|
||||
console.log('\nPaso 4) Insertando admin.'.bold.blue);
|
||||
|
||||
/*
|
||||
//Borrar esta linea de codigo
|
||||
console.log('Admin password:', process.env.ADMIN_PASSWORD);
|
||||
|
||||
//Eliminar esta linea de codigo
|
||||
const pwdHasheada = encriptar.encriptar(process.env.ADMIN_PASSWORD);
|
||||
console.log('Password hasheada:', pwdHasheada);
|
||||
*/
|
||||
|
||||
await Admin.create({
|
||||
idTipoUsuario: 1,
|
||||
usuario: 'Araceli',
|
||||
|
||||
@@ -18,16 +18,18 @@ Inscripcion.init(
|
||||
type: DataTypes.INTEGER,
|
||||
defaultValue: 2,
|
||||
},
|
||||
confirmacion: {
|
||||
cancelacion: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: false,
|
||||
defaultValue: 0,
|
||||
},
|
||||
motivo: {
|
||||
type: DataTypes.STRING(100),
|
||||
defaultValue: null,
|
||||
},
|
||||
folio: {
|
||||
type: DataTypes.STRING(5),
|
||||
type: DataTypes.STRING(10),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
unique: true,
|
||||
},
|
||||
monto: {
|
||||
type: DataTypes.INTEGER,
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
const { unique } = require("next/dist/build/utils");
|
||||
const { DataTypes, Model } = require("sequelize");
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
|
||||
class Profesor extends Model{}
|
||||
Profesor.init(
|
||||
{
|
||||
idProfesor: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
nombre: {
|
||||
type: DataTypes.STRING(100),
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
rfc: {
|
||||
type: DataTypes.STRING(10),
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
},
|
||||
homo: {
|
||||
type: DataTypes.STRING(3),
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'Profesor',
|
||||
tableName: 'profesor',
|
||||
timestamps: false,
|
||||
},
|
||||
)
|
||||
|
||||
module.exports = Profesor;
|
||||
@@ -1,42 +0,0 @@
|
||||
const { Model, DataTypes } = require("sequelize");
|
||||
const Profesor = require("./Profesor");
|
||||
const sequelize = require('../../config/sequelize.conf');
|
||||
|
||||
class ProfesorInscrito extends Model {}
|
||||
|
||||
ProfesorInscrito.init(
|
||||
{
|
||||
idProfesorInscrito: {
|
||||
type: DataTypes.INTEGER,
|
||||
primaryKey: true,
|
||||
unique: true,
|
||||
allowNull: false,
|
||||
autoIncrement: true,
|
||||
},
|
||||
fechaRegistro: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW,
|
||||
},
|
||||
},
|
||||
{
|
||||
sequelize,
|
||||
modelName: 'ProfesorInscrito',
|
||||
tableName: 'profesorInscrito',
|
||||
timestamps: false,
|
||||
}
|
||||
);
|
||||
|
||||
// Relación (Sequelize crea automáticamente idProfesor con FK)
|
||||
ProfesorInscrito.belongsTo(Profesor, {
|
||||
foreignKey: {
|
||||
name: 'idProfesor',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
module.exports = ProfesorInscrito;
|
||||
|
||||
|
||||
@@ -22,8 +22,8 @@ Usuario.init(
|
||||
allowNull: true,
|
||||
defaultValue: null,
|
||||
},
|
||||
semestre: {
|
||||
type: DataTypes.STRING(30),
|
||||
generacion: {
|
||||
type: DataTypes.STRING(5),
|
||||
allowNull: false,
|
||||
},
|
||||
idCarrera: {
|
||||
@@ -44,11 +44,11 @@ Usuario.init(
|
||||
);
|
||||
|
||||
Usuario.belongsTo(Carrera, {
|
||||
foreignKey: {
|
||||
name: 'idCarrera',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
foreignKey: {
|
||||
name: 'idCarrera',
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
});
|
||||
|
||||
module.exports = Usuario;
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
const correoInscripciones = () => ({
|
||||
subject: `Inscripción a CEDETEC`,
|
||||
msj: `
|
||||
<p>Estimado Usuario</p>
|
||||
<p>
|
||||
Su inscripción esta sujeta a revisión, es necesario revisar los datos que registro en el sistema.
|
||||
</p>
|
||||
|
||||
<p>Te sugerimos guardar tu ticket para cualquier aclaración</p>
|
||||
|
||||
<p>Por el momento podras hacer tu confirmación en <a href="https://kalinga.acatlan.unam.mx/cedetec/" target="_blanc">KALINGA</a></p>
|
||||
|
||||
<p>En caso de recibir un correo con el asunto Inscripción declinada se cancelara el servicio y no podras hacer uso de los servicios</p>
|
||||
|
||||
<p>Atentamente:</p>
|
||||
<p>Atención Usuarios DSC</p>
|
||||
`,
|
||||
});
|
||||
|
||||
module.exports = correoInscripciones;
|
||||
@@ -0,0 +1,22 @@
|
||||
const correoDeclinar = () => ({
|
||||
subject: `Tu inscripción a CEDETEC a sido declinada`,
|
||||
msj: `
|
||||
<p>Estimado Usuario</p>
|
||||
<p>
|
||||
Su inscripción a sido declinada, favor de pasar a CEDETEC para aclarar la situción.
|
||||
</p>
|
||||
|
||||
<p>Motivos por los cuales tu inscripción a sido declinada:</p>
|
||||
|
||||
<ul>
|
||||
<li>La foto del ticket no es visible.</li>
|
||||
<li>El ticket no pertenece a CEDETEC</li>
|
||||
<li>Encontramos algún otra anomalía en tu ticket.</li>
|
||||
</ul>
|
||||
|
||||
<p>Atentamente:</p>
|
||||
<p>Atención Usuarios DSC</p>
|
||||
`,
|
||||
});
|
||||
|
||||
module.exports = correoDeclinar;
|
||||
@@ -6,22 +6,8 @@ const comparar = (password, dbPassword) => {
|
||||
return true;
|
||||
};
|
||||
|
||||
const encriptar = (password) => {
|
||||
/*
|
||||
bcrypt.hashSync(password, Number(process.env.SALT_ROUNDS));
|
||||
|
||||
const rounds = Number(process.env.SALT_ROUNDS) || 10;
|
||||
console.log('Rounds para hashSync:', rounds);
|
||||
return bcrypt.hashSync(password, rounds);
|
||||
|
||||
const rounds = Number(process.env.SALT_ROUNDS) || 10;
|
||||
console.log('Rounds para hashSync:', rounds);
|
||||
console.log('Password recibido en encriptar:', password); // <-- agrega esto
|
||||
return bcrypt.hashSync(password, rounds);
|
||||
*/
|
||||
const rounds = Number(process.env.SALT_ROUNDS) || 10;
|
||||
return bcrypt.hashSync(password, rounds);
|
||||
}
|
||||
const encriptar = (password) =>
|
||||
bcrypt.hashSync(password, Number(process.env.SALT_ROUNDS));
|
||||
|
||||
const generarPassword = () => {
|
||||
const length = 8;
|
||||
|
||||
@@ -5,11 +5,10 @@ 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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -23,6 +23,7 @@ const caracterEspecial = (char) => {
|
||||
'#',
|
||||
'%',
|
||||
'\n',
|
||||
'@',
|
||||
];
|
||||
|
||||
for (let i = 0; i < charset.length; i++) if (charset[i] === char) return true;
|
||||
|
||||
@@ -37,14 +37,4 @@ const crearTokenAdmin = (data) => {
|
||||
});
|
||||
};
|
||||
|
||||
const crearTokenOperador = (data) => {
|
||||
return jwt.sign({ data }, process.env.KEY, {
|
||||
expiresIn: Number(process.env.CADUCIDAD_TOKEN_OPERADOR),
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = { verificaToken, crearToken, crearTokenAdmin };
|
||||
|
||||
+45
-2
@@ -1,15 +1,18 @@
|
||||
const express = require('express');
|
||||
const app = express();
|
||||
const fs = require('fs');
|
||||
const { validarAlfanumerico } = require('../helper/validar');
|
||||
const { verificaToken } = require('../middleware/autentificacion');
|
||||
const route = '/Admin';
|
||||
const controllerPath = '../controller/Admin';
|
||||
const login = require(`${controllerPath}/login`);
|
||||
const todasInscripciones = require(`${controllerPath}/todasInscripciones`);
|
||||
const ticket = require(`${controllerPath}/ticket`);
|
||||
const actualizarTicket = require(`${controllerPath}/actualizarTicket`);
|
||||
const cancelarInscripcion = require(`${controllerPath}/cancelarInscripcion`);
|
||||
const motivo = require(`${controllerPath}/motivo`);
|
||||
const validarSinTicket = require(`${controllerPath}/validarSinTicket`);
|
||||
const validarTicket = require(`${controllerPath}/validarTicket`);
|
||||
const reporte = require(`${controllerPath}/reporte`);
|
||||
const login = require(`${controllerPath}/login`);
|
||||
|
||||
app.post(`${route}/login`, (req, res) => {
|
||||
return login(req.body)
|
||||
@@ -44,6 +47,36 @@ app.get(`${route}/ticket`, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get(`${route}/motivo`, verificaToken, (req, res) => {
|
||||
return motivo(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.put(`${route}/actualizar_ticket`, verificaToken, (req, res) => {
|
||||
return actualizarTicket(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.put(`${route}/cancelar_inscripcion`, verificaToken, (req, res) => {
|
||||
return cancelarInscripcion(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.put(`${route}/validar`, verificaToken, (req, res) => {
|
||||
return validarTicket(req.body)
|
||||
.then((data) => {
|
||||
@@ -54,6 +87,16 @@ app.put(`${route}/validar`, verificaToken, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.put(`${route}/validar_sin_ticket`, verificaToken, (req, res) => {
|
||||
return validarSinTicket(req.body)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(400).json({ message: err.message });
|
||||
});
|
||||
});
|
||||
|
||||
app.get(`${route}/reporte`, verificaToken, (req, res) => {
|
||||
return reporte(req.query)
|
||||
.then((data) => {
|
||||
|
||||
@@ -1,76 +0,0 @@
|
||||
const express = require('express');
|
||||
const router = express.Router();
|
||||
const buscarProfesor = require('../controller/Profesor/buscarProfesor');
|
||||
const { realizarInscripcion } = require('../controller/Profesor/inscripcionProfesor');
|
||||
|
||||
//const Usuario = require('../controller/Profesor/Usuario');
|
||||
|
||||
|
||||
router.get('/:numeroTrabajador', buscarProfesor);
|
||||
|
||||
// POST: inscribir profesor y enviar correo
|
||||
router.post('/inscripcion', realizarInscripcion);
|
||||
|
||||
|
||||
/*
|
||||
// Ruta POST para inscribir profesor y enviar correo
|
||||
router.post('/inscripcion', async (req, res) => {
|
||||
// Buscar al usuario por correo o nombre, dependiendo de qué campo sea único o útil
|
||||
const usuario = await Usuario.findOne({
|
||||
where: { correo } // o por nombre si es único, pero mejor por correo
|
||||
});
|
||||
|
||||
if (!usuario) {
|
||||
return res.status(404).json({ message: 'Usuario no encontrado en la base de datos.' });
|
||||
}
|
||||
|
||||
// Verificar si ya tiene una inscripción
|
||||
const inscripcionExistente = await Inscripcion.findOne({
|
||||
where: { idUsuario: usuario.idUsuario }
|
||||
});
|
||||
|
||||
if (inscripcionExistente) {
|
||||
return res.status(200).json({ message: 'El usuario ya está inscrito.' });
|
||||
}
|
||||
|
||||
// Crear inscripción con campos opcionales como null
|
||||
await Inscripcion.create({
|
||||
idUsuario: usuario.idUsuario,
|
||||
idArea: 1, // puedes cambiar esto si lo tienes dinámico
|
||||
validacion: 2,
|
||||
confirmacion: false,
|
||||
folio: null,
|
||||
monto: null,
|
||||
hizoPago: null,
|
||||
rutaTicket: null,
|
||||
extension: null,
|
||||
fechaInscripcion: null,
|
||||
fechaTicket: null,
|
||||
});
|
||||
|
||||
try {
|
||||
const { correo, nombre } = req.body;
|
||||
|
||||
//Borrar esta linea de codigo
|
||||
//console.log('Datos recibidos:', correo, nombre); // ← Agrega esto
|
||||
//console.log('Datos recibidos:', req.body); // Agrega esto
|
||||
|
||||
if (!correo || !nombre) {
|
||||
return res.status(400).json({ message: 'Faltan datos requeridos.' });
|
||||
}
|
||||
|
||||
//aqui tengo que aplicar la logica para crear al prodesor inscrito
|
||||
|
||||
|
||||
await enviarCorreoInscripcion(correo, nombre);
|
||||
res.status(200).json({ message: 'Correo enviado correctamente.' });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).json({ message: 'Error al enviar el correo.' });
|
||||
}
|
||||
|
||||
});
|
||||
*/
|
||||
|
||||
|
||||
module.exports = router;
|
||||
@@ -20,7 +20,7 @@ app.post(`${route}/login`, (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get(`${route}/inscripciones`, (req, res) => {
|
||||
app.get(`${route}/inscripciones`, verificaToken, (req, res) => {
|
||||
return inscripciones(req.query)
|
||||
.then((data) => {
|
||||
res.status(200).json(data);
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
numero_cuenta,id_area,folio,monto,hizo_pago,fecha_inscripcion
|
||||
419085500,1,99999,20,true,02/26/2022
|
||||
|
||||
|
Reference in New Issue
Block a user