Compare commits
90 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| b1465cfdb4 | |||
| a4a714616e | |||
| 4e3452afed | |||
| 83260468b5 | |||
| 27464e62a9 | |||
| 3e60138e15 | |||
| e8a7a50613 | |||
| 2e4bb9781e | |||
| c93a0e33c4 | |||
| 0d6329a787 | |||
| 6f16111ebb | |||
| d194d31683 | |||
| 1b809a3105 | |||
| a9a0acde5f | |||
| c0fc6484b0 | |||
| d7582f2dbf | |||
| 9a1b3131e8 | |||
| c700a8adda | |||
| a8e68e2fa9 | |||
| 0f04af9237 | |||
| 31f2add1c0 | |||
| 58368a6929 | |||
| f92ed5d411 | |||
| a553e92f0f | |||
| ce6dc0405d | |||
| 1e3f49a1ab | |||
| b3bf9a9226 | |||
| 8ac18269d8 | |||
| e675eb643b | |||
| 61106560ff | |||
| 0d585f094f | |||
| e0667c3ae4 | |||
| ea356e9f7d | |||
| dae9234325 | |||
| 36377b21b3 | |||
| 8a4a53ee20 | |||
| 03b3dbc516 | |||
| d26259585f | |||
| e8142266f7 | |||
| 26ac4ec0d2 | |||
| cf4562fb13 | |||
| 28fd26a5e4 | |||
| 4ecf6ac89a | |||
| 79c726e96b | |||
| c5c06a571a | |||
| 6a79f57102 | |||
| 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 |
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
|
images/
|
||||||
.env
|
.env
|
||||||
Generated
+50
@@ -19,10 +19,12 @@
|
|||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"fs": "^0.0.1-security",
|
"fs": "^0.0.1-security",
|
||||||
|
"gmail-send": "^1.8.14",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"mariadb": "^2.5.3",
|
"mariadb": "^2.5.3",
|
||||||
"moment": "^2.29.1",
|
"moment": "^2.29.1",
|
||||||
"multer": "^1.4.4",
|
"multer": "^1.4.4",
|
||||||
|
"nodemailer": "^7.0.5",
|
||||||
"sequelize": "^6.6.2",
|
"sequelize": "^6.6.2",
|
||||||
"validator": "^13.6.0"
|
"validator": "^13.6.0"
|
||||||
},
|
},
|
||||||
@@ -1071,6 +1073,24 @@
|
|||||||
"url": "https://github.com/sponsors/sindresorhus"
|
"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/gmail-send/node_modules/nodemailer": {
|
||||||
|
"version": "6.10.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.10.1.tgz",
|
||||||
|
"integrity": "sha512-Z+iLaBGVaSjbIzQ4pX6XV41HrooLsQ10ZWPUehGmuantvzWoDVBnmsdUcOIDM1t+yPor5pDhVlDESgOMEGxhHA==",
|
||||||
|
"license": "MIT-0",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/got": {
|
"node_modules/got": {
|
||||||
"version": "9.6.0",
|
"version": "9.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/got/-/got-9.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/got/-/got-9.6.0.tgz",
|
||||||
@@ -1757,6 +1777,15 @@
|
|||||||
"node": "4.x || >=6.0.0"
|
"node": "4.x || >=6.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"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",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/nodemon": {
|
"node_modules/nodemon": {
|
||||||
"version": "2.0.15",
|
"version": "2.0.15",
|
||||||
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.15.tgz",
|
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.15.tgz",
|
||||||
@@ -3558,6 +3587,22 @@
|
|||||||
"ini": "2.0.0"
|
"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"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"nodemailer": {
|
||||||
|
"version": "6.10.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.10.1.tgz",
|
||||||
|
"integrity": "sha512-Z+iLaBGVaSjbIzQ4pX6XV41HrooLsQ10ZWPUehGmuantvzWoDVBnmsdUcOIDM1t+yPor5pDhVlDESgOMEGxhHA=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"got": {
|
"got": {
|
||||||
"version": "9.6.0",
|
"version": "9.6.0",
|
||||||
"resolved": "https://registry.npmjs.org/got/-/got-9.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/got/-/got-9.6.0.tgz",
|
||||||
@@ -4092,6 +4137,11 @@
|
|||||||
"whatwg-url": "^5.0.0"
|
"whatwg-url": "^5.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"nodemailer": {
|
||||||
|
"version": "7.0.5",
|
||||||
|
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-7.0.5.tgz",
|
||||||
|
"integrity": "sha512-nsrh2lO3j4GkLLXoeEksAMgAOqxOv6QumNRVQTJwKH4nuiww6iC2y7GyANs9kRAxCexg3+lTWM3PZ91iLlVjfg=="
|
||||||
|
},
|
||||||
"nodemon": {
|
"nodemon": {
|
||||||
"version": "2.0.15",
|
"version": "2.0.15",
|
||||||
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.15.tgz",
|
"resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.15.tgz",
|
||||||
|
|||||||
+3
-1
@@ -8,7 +8,7 @@
|
|||||||
"db:install": "node ./server/db/install",
|
"db:install": "node ./server/db/install",
|
||||||
"db:data-fake": "node ./server/db/data-fake",
|
"db:data-fake": "node ./server/db/data-fake",
|
||||||
"dev": "nodemon ./server/app",
|
"dev": "nodemon ./server/app",
|
||||||
"start": "node ./server/app"
|
"start": "source ~/.nvm/nvm.sh && nvm use 16.15.1 && npm install && node ./server/app"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
@@ -27,10 +27,12 @@
|
|||||||
"dotenv": "^8.2.0",
|
"dotenv": "^8.2.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"fs": "^0.0.1-security",
|
"fs": "^0.0.1-security",
|
||||||
|
"gmail-send": "^1.8.14",
|
||||||
"jsonwebtoken": "^8.5.1",
|
"jsonwebtoken": "^8.5.1",
|
||||||
"mariadb": "^2.5.3",
|
"mariadb": "^2.5.3",
|
||||||
"moment": "^2.29.1",
|
"moment": "^2.29.1",
|
||||||
"multer": "^1.4.4",
|
"multer": "^1.4.4",
|
||||||
|
"nodemailer": "^7.0.5",
|
||||||
"sequelize": "^6.6.2",
|
"sequelize": "^6.6.2",
|
||||||
"validator": "^13.6.0"
|
"validator": "^13.6.0"
|
||||||
},
|
},
|
||||||
|
|||||||
+28
-2
@@ -13,14 +13,40 @@ 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.use(bodyParser.json());
|
||||||
|
|
||||||
app.get('/', (req, res) => res.send('API de Inscripciones a CEDETEC'));
|
app.get('/', (req, res) => res.send('API de Inscripciones a CEDETEC'));
|
||||||
|
|
||||||
app.use(require('./routes/index'));
|
app.use(require('./routes/index'));
|
||||||
|
|
||||||
app.listen(Number(process.env.PORT), () =>
|
const port = Number(process.env.PORT) || 3000;
|
||||||
|
const server = app.listen(port, () =>
|
||||||
console.log(
|
console.log(
|
||||||
`API Inscripciones corriendo en el puerto: ${process.env.PORT}`.rainbow
|
`API Inscripciones corriendo en el puerto: ${port}`.rainbow
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
server.on('error', (error) => {
|
||||||
|
if (error.code === 'EADDRINUSE') {
|
||||||
|
console.error(
|
||||||
|
`Error: el puerto ${port} ya está en uso. Usa otra variable PORT en .env o detén el proceso que lo está ocupando.`
|
||||||
|
);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
|
|||||||
@@ -9,3 +9,5 @@ try {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log('El archivo .env no se cargo.'.underline.bold.red);
|
console.log('El archivo .env no se cargo.'.underline.bold.red);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+126
-49
@@ -1,73 +1,150 @@
|
|||||||
require('./config');
|
require('./config');
|
||||||
const mariadb = require('mariadb');
|
const mariadb = require('mariadb');
|
||||||
|
|
||||||
const pool1 = mariadb.createPool({
|
const pool = 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({
|
|
||||||
host: process.env.HOST_DB,
|
host: process.env.HOST_DB,
|
||||||
user: process.env.USER_DB,
|
user: process.env.USER_DB,
|
||||||
password: process.env.PASSWORD_DB,
|
password: process.env.PASSWORD_DB,
|
||||||
database: process.env.SATE_DB,
|
database: process.env.SAT_DB,
|
||||||
|
connectionLimit: 5, // Limitar a 5 conexiones para evitar sobrecarga
|
||||||
|
acquireTimeout: 60000, // Timeout de 60 segundos para adquirir conexión
|
||||||
|
timeout: 60000, // Timeout general
|
||||||
});
|
});
|
||||||
|
|
||||||
const obtenerIdCarrera = async (numeroCuenta) => {
|
const obtenerDatosUsr = async (numeroCuenta) => {
|
||||||
const conn = await pool1.getConnection().catch((err) => {
|
let conn;
|
||||||
throw new Error('No se pudo conectar con la db. ' + err);
|
try {
|
||||||
});
|
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}`)
|
|
||||||
.then((rows) => {
|
|
||||||
conn.end();
|
|
||||||
// console.log(rows[0]);
|
|
||||||
// if (rows[0].length === 0) return null;
|
|
||||||
return rows[0];
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
conn.end();
|
|
||||||
throw new Error('Hubo un problema con el querry.' + err);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const rows = await conn.query(
|
||||||
|
`SELECT id_carrera, generacion FROM alumno WHERE id_cuenta = ${numeroCuenta}`
|
||||||
|
);
|
||||||
|
|
||||||
|
return rows[0];
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error('Hubo un problema con el querry.' + err);
|
||||||
|
} finally {
|
||||||
|
if (conn) conn.end();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const obtenerCarrera = async (idCarrera) => {
|
// Agregue para profesores
|
||||||
const conn = await pool1.getConnection().catch((err) => {
|
const buscarProfesorPorNumero = async (numeroTrabajador) => {
|
||||||
throw new Error('No se pudo conectar con la db. ' + err);
|
//console.log("Buscando profesor con numeroCuenta:", numeroTrabajador);
|
||||||
});
|
|
||||||
|
|
||||||
return conn
|
let conn;
|
||||||
.query(`SELECT id_carrera FROM carrera WHERE id_carrera = ${idCarrera}`)
|
try {
|
||||||
.then((rows) => {
|
conn = await pool.getConnection().catch((err) => {
|
||||||
conn.end();
|
throw new Error('No se pudo conectar con la base de datos. ' + err);
|
||||||
return rows[0];
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
conn.end();
|
|
||||||
throw new Error('Hubo un problema con el querry.' + err);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const rows = await conn.query(
|
||||||
|
`SELECT nombre, id_cuenta FROM alumno WHERE id_cuenta = ?`,
|
||||||
|
[numeroTrabajador] // NUmero de cuenta
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(numeroTrabajador);
|
||||||
|
if (rows.length === 0) return null;
|
||||||
|
//console.log('Resultado de la consulta:', rows); // <--- Aquí
|
||||||
|
return rows[0]; // { nombre: 'Juan', rfc: 'JUAP123' }
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error('Error al buscar el profesor: ' + err);
|
||||||
|
} finally {
|
||||||
|
if (conn) conn.end();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const usuarioInscrito = async (numeroCuenta) => {
|
const validarPeriodoActivo = async (conn) => {
|
||||||
const conn = await pool2.getConnection().catch((err) => {
|
|
||||||
throw new Error('No se pudo conectar con la db. ' + err);
|
|
||||||
});
|
|
||||||
|
|
||||||
return conn
|
return conn
|
||||||
.query(
|
.query(
|
||||||
`INSERT INTO alumno_inscrito(id_cuenta,id_periodo,id_plataforma,realizo_pago,platica) values(${numeroCuenta}, 20, 4, 1, 1)`
|
`SELECT id_periodo FROM periodo WHERE activo = b'1' LIMIT 1`
|
||||||
)
|
)
|
||||||
.then((rows) => {
|
.then((rows) => {
|
||||||
conn.end();
|
if (!rows || rows.length === 0) {
|
||||||
return rows[0];
|
console.log('No existe');
|
||||||
|
throw new Error('No existe un periodo activo en el sistema');
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
conn.end();
|
throw new Error('Error al validar periodo activo: ' + err);
|
||||||
throw new Error('Hubo un problema con el querry.' + err);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// console.log('Este es el periodo: ', rows[0])
|
||||||
|
// console.log('Este es el id del periodo: ', rows[0].id_periodo)
|
||||||
|
// return rows[0].id_periodo;
|
||||||
|
}
|
||||||
|
|
||||||
|
const validarAlumnoInscrito = async (idCuenta) => {
|
||||||
|
console.log("Validando alumno inscrito con id_cuenta:", idCuenta);
|
||||||
|
|
||||||
|
// Convertimos a número para quitar ceros a la izquierda
|
||||||
|
const idLimpio = parseInt(idCuenta, 10);
|
||||||
|
|
||||||
|
// Si después de limpiar tiene más de 6 dígitos, no es profesor
|
||||||
|
if (idLimpio.toString().length > 6) {
|
||||||
|
throw new Error('Error: el número de trabajador no existe');
|
||||||
|
}
|
||||||
|
|
||||||
|
let conn;
|
||||||
|
try {
|
||||||
|
conn = await pool.getConnection().catch((err) => {
|
||||||
|
throw new Error('No se pudo conectar con la base de datos. ' + err);
|
||||||
|
});
|
||||||
|
|
||||||
|
const idPeriodoActivo = await validarPeriodoActivo(conn);
|
||||||
|
|
||||||
|
console.log("id del periodo: " + idPeriodoActivo)
|
||||||
|
|
||||||
|
const rows = await conn.query(
|
||||||
|
`SELECT * FROM alumno_inscrito WHERE id_cuenta = ? AND id_periodo = ?`,
|
||||||
|
[idCuenta, idPeriodoActivo]
|
||||||
|
)
|
||||||
|
|
||||||
|
if (rows.length === 0) return null;
|
||||||
|
|
||||||
|
return rows[0];
|
||||||
|
} catch (error) {
|
||||||
|
throw new Error('Error al validar alumno inscrito: ' + error);
|
||||||
|
} finally {
|
||||||
|
if (conn) conn.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
// return conn
|
||||||
|
// .query(
|
||||||
|
// `SELECT * FROM alumno_inscrito WHERE id_cuenta = ? AND id_periodo = 27`,
|
||||||
|
// [idCuenta]
|
||||||
|
// )
|
||||||
|
// .then((rows) => {
|
||||||
|
// //console.log('Resultado de la consulta alumno_inscrito:', rows);
|
||||||
|
|
||||||
|
// conn.end();
|
||||||
|
// if (rows.length === 0) return null;
|
||||||
|
// return rows[0]; // Devuelve el primer registro encontrado
|
||||||
|
// })
|
||||||
|
// .catch((err) => {
|
||||||
|
// conn.end();
|
||||||
|
// throw new Error('Error al validar alumno inscrito: ' + err);
|
||||||
|
// });
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = { obtenerIdCarrera, obtenerCarrera, usuarioInscrito };
|
|
||||||
|
// 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,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = { buscarProfesorPorNumero, validarAlumnoInscrito };
|
||||||
|
|||||||
@@ -7,12 +7,18 @@ const sequelize = new Sequelize(
|
|||||||
process.env.PASSWORD_DB,
|
process.env.PASSWORD_DB,
|
||||||
{
|
{
|
||||||
host: process.env.HOST_DB,
|
host: process.env.HOST_DB,
|
||||||
dialect: process.env.TYPEDB,
|
dialect: process.env.TYPEDB || 'mariadb',
|
||||||
logging: false,
|
logging: false,
|
||||||
dialectOptions: {
|
dialectOptions: {
|
||||||
useUTC: false,
|
useUTC: false,
|
||||||
},
|
},
|
||||||
timezone: '-06:00',
|
timezone: '-06:00',
|
||||||
|
pool: {
|
||||||
|
max: 5, // Máximo 5 conexiones
|
||||||
|
min: 0, // Mínimo 0
|
||||||
|
acquire: 30000, // Tiempo para adquirir conexión (30s)
|
||||||
|
idle: 10000, // Tiempo idle antes de cerrar (10s)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
const dbPath = '../../db/tablas';
|
||||||
|
const { validarNumeroEntero, validarNumero } = 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 = validarNumero(body.monto, 'monto', true, null, false);
|
||||||
|
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) => {
|
.then(async (res) => {
|
||||||
if (body.tipo === 'CSV') {
|
for (let i = 0; i < res.length; i++) {
|
||||||
for (let i = 0; i < res.length; i++) {
|
data.push({
|
||||||
data.push({
|
numeroCuenta: res[i].Usuario.numeroCuenta,
|
||||||
numero_cuenta: res[i].Usuario.numeroCuenta,
|
idArea: res[i].idArea,
|
||||||
id_area: res[i].idArea,
|
folio: res[i].folio,
|
||||||
folio: res[i].folio,
|
monto: res[i].monto,
|
||||||
monto: res[i].monto,
|
hizoPago: res[i].hizoPago,
|
||||||
hizo_pago: res[i].hizoPago,
|
fechaInscripcion: moment(res[i].fechaInscripcion).format('L'),
|
||||||
fecha_inscripcion: moment(res[i].fechaInscripcion).format('L'),
|
validacion: res[i].validacion,
|
||||||
});
|
motivoDeclinacion: res[i].motivo,
|
||||||
}
|
});
|
||||||
} 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,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
await helper.eliminarArchivo(path).catch((err) => {});
|
await helper.eliminarArchivo(path).catch((err) => {});
|
||||||
return helper.crearArchivo(path, convertArrayToCSV(data));
|
return helper.crearArchivo(path, convertArrayToCSV(data));
|
||||||
|
|||||||
@@ -1,14 +1,25 @@
|
|||||||
|
const { validarNumeroEntero } = require('../../helper/validar');
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Usuario = require(`${dbPath}/Usuario`);
|
|
||||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||||
|
|
||||||
const ticket = async (body) => {
|
const ticket = async (body) => {
|
||||||
|
const folio = validarNumeroEntero(body.folio, 'folio', true);
|
||||||
|
|
||||||
return Inscripcion.findOne({
|
return Inscripcion.findOne({
|
||||||
where: { folio: body.folio },
|
where: { folio: body.folio },
|
||||||
attributes: ['rutaTicket', 'extension'],
|
attributes: ['rutaTicket', 'extension', 'motivo'],
|
||||||
}).then((res) => {
|
})
|
||||||
return { rutaTicket: res.rutaTicket, extension: res.extension };
|
.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;
|
module.exports = ticket;
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
const validar = require('../../helper/validar');
|
|
||||||
const { Op } = require('sequelize');
|
const { Op } = require('sequelize');
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Usuario = require(`${dbPath}/Usuario`);
|
const Usuario = require(`${dbPath}/Usuario`);
|
||||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||||
|
const { validarNumeroEntero } = require('../../helper/validar');
|
||||||
|
|
||||||
const todasInscripciones = async (body) => {
|
const todasInscripciones = async (body) => {
|
||||||
// const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
|
const validacion = validarNumeroEntero(body.validacion, 'validacion', true);
|
||||||
|
const order = validacion === 2 ? [['idInscripcion', 'ASC']] : [['idInscripcion', 'DESC']];
|
||||||
|
console.log(order)
|
||||||
return Inscripcion.findAll({
|
return Inscripcion.findAll({
|
||||||
where: { validacion: body.validacion },
|
where: {
|
||||||
|
validacion,
|
||||||
|
cancelacion: 0,
|
||||||
|
idPeriodo: Number(process.env.PERIODO),
|
||||||
|
},
|
||||||
|
order: order,
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: Usuario,
|
model: Usuario,
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
const dbPath = '../../db/tablas';
|
||||||
|
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||||
|
const {
|
||||||
|
validarNumeroEntero,
|
||||||
|
validarNumeroCuenta,
|
||||||
|
} = require('../../helper/validar');
|
||||||
|
const correoInscripcion = require('../../helper/correo');
|
||||||
|
|
||||||
|
const validarSinTicket = async (body) => {
|
||||||
|
const numeroCuenta = validarNumeroCuenta(
|
||||||
|
body.numeroCuenta,
|
||||||
|
'número de cuenta',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
const idUsuario = validarNumeroEntero(body.idUsuario, 'usuario', true);
|
||||||
|
const idArea = validarNumeroEntero(body.idArea, 'IDAREA', true);
|
||||||
|
|
||||||
|
let correo = {};
|
||||||
|
let email = '';
|
||||||
|
|
||||||
|
return Inscripcion.update(
|
||||||
|
{
|
||||||
|
validacion: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
idUsuario,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.then((res) => {
|
||||||
|
email = `${numeroCuenta}@pcpuma.acatlan.unam.mx`;
|
||||||
|
usuarioInscrito(numeroCuenta, idArea);
|
||||||
|
correo = correoInscripcion();
|
||||||
|
gmail(correo.subject, email, correo.msj);
|
||||||
|
})
|
||||||
|
.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,43 +1,85 @@
|
|||||||
|
const {
|
||||||
|
validarNumeroEntero,
|
||||||
|
validarNumeroCuenta,
|
||||||
|
} = require('../../helper/validar');
|
||||||
|
const {
|
||||||
|
usuarioInscrito,
|
||||||
|
borrarRecibo,
|
||||||
|
borrarDetalleServicio,
|
||||||
|
} = require('../../config/mariadb.conf');
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||||
const Usuario = require(`${dbPath}/Usuario`);
|
const gmail = require('../../helper/gmail');
|
||||||
const { usuarioInscrito } = require('../../config/mariadb.conf');
|
const correoDeclinar = require('../../helper/correoDeclinar');
|
||||||
|
const correoInscripcion = require('../../helper/correo');
|
||||||
|
|
||||||
const validarTicket = async (body) => {
|
const validarTicket = async (body) => {
|
||||||
|
const numeroCuenta = validarNumeroCuenta(
|
||||||
|
body.numeroCuenta,
|
||||||
|
'número de cuenta',
|
||||||
|
true
|
||||||
|
);
|
||||||
|
const folio = validarNumeroEntero(body.folio, 'folio', true);
|
||||||
|
const idArea = validarNumeroEntero(body.idArea, 'IDAREA', true);
|
||||||
|
|
||||||
|
let correo = {};
|
||||||
|
let email = '';
|
||||||
|
|
||||||
return Inscripcion.findOne({
|
return Inscripcion.findOne({
|
||||||
where: { folio: body.folio },
|
where: { folio },
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (!res) throw new Error('Este folio no existe');
|
if (!res) throw new Error('Este folio no existe');
|
||||||
idUsuario = res.idUsuario;
|
idUsuario = res.idUsuario;
|
||||||
|
if (body.validacion == 1) {
|
||||||
|
return Inscripcion.findOne({
|
||||||
|
where: { folio, validacion: 1 },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
if (res) throw new Error('Este folio ya fue validado');
|
||||||
return Inscripcion.update(
|
return Inscripcion.update(
|
||||||
{
|
{
|
||||||
validacion: body.validacion,
|
validacion: body.validacion,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
where: {
|
where: {
|
||||||
folio: body.folio,
|
folio,
|
||||||
|
cancelacion: 0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (body.validacion === 0)
|
email = `${numeroCuenta}@pcpuma.acatlan.unam.mx`;
|
||||||
throw new Error(
|
if (body.validacion === 1) {
|
||||||
'El administrador a declinado el ticket, ya que los datos no coinciden.'
|
usuarioInscrito(numeroCuenta, idArea);
|
||||||
|
correo = correoInscripcion();
|
||||||
|
} else {
|
||||||
|
borrarRecibo(folio, numeroCuenta);
|
||||||
|
borrarDetalleServicio(numeroCuenta);
|
||||||
|
correo = correoDeclinar();
|
||||||
|
return Inscripcion.update(
|
||||||
|
{ motivo: body.motivo },
|
||||||
|
{
|
||||||
|
where: {
|
||||||
|
folio,
|
||||||
|
},
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
return Usuario.findOne({
|
gmail(correo.subject, email, correo.msj);
|
||||||
where: { idUsuario },
|
if (body.validacion === 1) {
|
||||||
attributes: ['numeroCuenta'],
|
return {
|
||||||
}).then((res) => {
|
message: '¡El ticket a sido validado de forma correcta!',
|
||||||
return usuarioInscrito(res.numeroCuenta).then(async (res) => {
|
};
|
||||||
return {
|
} else
|
||||||
message: '¡ El ticket a sido validado de forma correcta !',
|
return {
|
||||||
};
|
message: '¡El ticket a sido declinado',
|
||||||
});
|
};
|
||||||
});
|
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw new Error('No fue posible validar el ticket. ' + err);
|
throw new Error('No fue posible validar el ticket. ' + err);
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
const { buscarProfesorPorNumero, validarAlumnoInscrito } = require('../../config/mariadb.conf');
|
||||||
|
|
||||||
|
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 existeInscripcion = await validarAlumnoInscrito(profesor.id_cuenta);
|
||||||
|
if (existeInscripcion) {
|
||||||
|
return res.status(409).json({
|
||||||
|
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;
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
/*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.'});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
const nodemailer = require('nodemailer');
|
||||||
|
|
||||||
|
async function enviarCorreoInscripcion(correo, nombre) {
|
||||||
|
console.log('Enviando correo de confirmación de inscripción...');
|
||||||
|
if (!correo || !nombre) {
|
||||||
|
console.log('Correo y nombre son requeridos para enviar el correo de inscripción.')
|
||||||
|
throw new Error('Correo y nombre son requeridos para enviar el correo de inscripción.');
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
const enviarCorreoInscripcion = require('../../controller/Profesor/enviarCorreo'); // Ajusta si está en otra ruta
|
||||||
|
const Alumno = require('../../db/tablas/Alumno');
|
||||||
|
const AlumnoInscrito = require('../../db/tablas/AlumnoInscrito');
|
||||||
|
|
||||||
|
async function realizarInscripcion(req, res) {
|
||||||
|
const { id_cuenta, nombre, correo } = req.body;
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (!nombre || !id_cuenta) {
|
||||||
|
return res.status(400).json({ message: 'Faltan datos requeridos.' });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// 1. Buscar si el usuario existe
|
||||||
|
const usuario = await Alumno.findOne({ where: { id_cuenta } });
|
||||||
|
|
||||||
|
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 AlumnoInscrito.findOne({
|
||||||
|
where: {
|
||||||
|
id_cuenta: usuario.id_cuenta,
|
||||||
|
id_periodo: 28
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('Inscripcion:', inscripcionExistente)
|
||||||
|
|
||||||
|
if (inscripcionExistente) {
|
||||||
|
return res.status(200).json({
|
||||||
|
message: 'El usuario ya está inscrito.',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Crear inscripción
|
||||||
|
await AlumnoInscrito.create({
|
||||||
|
id_cuenta: usuario.id_cuenta,
|
||||||
|
id_periodo: 28,
|
||||||
|
id_plataforma: 5,
|
||||||
|
fecha_inscripcion: new Date(),
|
||||||
|
tiempo_disponible: 3600,
|
||||||
|
realizo_pago: 0,
|
||||||
|
platica: 1,
|
||||||
|
ad: 0
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// 4. Realizar confirmacion
|
||||||
|
await AlumnoInscrito.update(
|
||||||
|
{ platica: 1 },
|
||||||
|
{ where: { id_cuenta: usuario.id_cuenta } }
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
console.log(correo)
|
||||||
|
console.log(nombre)
|
||||||
|
// 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);
|
||||||
|
//console.log('Datos recibidos para inscripción:', req.body);
|
||||||
|
|
||||||
|
res.status(500).json({ message: 'Error al procesar la inscripción o enviar el correo.' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = { realizarInscripcion };
|
||||||
@@ -1,37 +1,45 @@
|
|||||||
const {
|
const { obtenerDatosUsr } = require('../../config/mariadb.conf');
|
||||||
obtenerIdCarrera,
|
const { validarNumeroCuenta } = require('../../helper/validar');
|
||||||
obtenerCarrera,
|
|
||||||
} = require('../../config/mariadb.conf');
|
|
||||||
const validar = require('../../helper/validar');
|
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Carrera = require(`${dbPath}/Carrera`);
|
|
||||||
const Usuario = require(`${dbPath}/Usuario`);
|
const Usuario = require(`${dbPath}/Usuario`);
|
||||||
|
const Carrera = require(`${dbPath}/Carrera`);
|
||||||
|
|
||||||
const escolares = async (body) => {
|
const escolares = async (body) => {
|
||||||
// const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
|
const numeroCuenta = validarNumeroCuenta(
|
||||||
|
body.numeroCuenta,
|
||||||
|
'numero cuenta',
|
||||||
|
true
|
||||||
|
);
|
||||||
return Usuario.findOne({
|
return Usuario.findOne({
|
||||||
where: { numeroCuenta: body.numeroCuenta },
|
where: { numeroCuenta },
|
||||||
}).then((res) => {
|
}).then(async (res) => {
|
||||||
if (!res) {
|
if (!res) {
|
||||||
return obtenerIdCarrera(body.numeroCuenta).then(async (res) => {
|
const datosUsuario = await obtenerDatosUsr(numeroCuenta);
|
||||||
|
return Carrera.findOne({
|
||||||
|
where: { idCarrera: datosUsuario.id_carrera },
|
||||||
|
}).then(async (res) => {
|
||||||
|
if (!res) {
|
||||||
|
await Carrera.create({
|
||||||
|
idCarrera: datosUsuario.id_carrera,
|
||||||
|
carrera: body.carrera,
|
||||||
|
});
|
||||||
|
}
|
||||||
return Usuario.create({
|
return Usuario.create({
|
||||||
idUsuario: body.idUsuario,
|
numeroCuenta,
|
||||||
numeroCuenta: body.numeroCuenta,
|
|
||||||
nombre: body.nombre,
|
nombre: body.nombre,
|
||||||
semestre: 8,
|
generacion: datosUsuario.generacion,
|
||||||
carrera: body.carrera,
|
carrera: body.carrera,
|
||||||
idCarrera: res.id_carrera,
|
idCarrera: datosUsuario.id_carrera,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return Usuario.findOne({
|
return Usuario.findOne({
|
||||||
where: { numeroCuenta: body.numeroCuenta },
|
where: { numeroCuenta },
|
||||||
attributes: [
|
attributes: [
|
||||||
'idUsuario',
|
'idUsuario',
|
||||||
'numeroCuenta',
|
'numeroCuenta',
|
||||||
'nombre',
|
'nombre',
|
||||||
'semestre',
|
'generacion',
|
||||||
'idCarrera',
|
'idCarrera',
|
||||||
'carrera',
|
'carrera',
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,28 +1,47 @@
|
|||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { validarNumeroEntero, validarNumero } = require('../../helper/validar');
|
const {
|
||||||
|
validarNumeroEntero,
|
||||||
|
validarNumero,
|
||||||
|
validarNumeroCuenta,
|
||||||
|
} = require('../../helper/validar');
|
||||||
|
const {
|
||||||
|
agregarRecibo,
|
||||||
|
agregarDetalleServicio,
|
||||||
|
} = require('../../config/mariadb.conf');
|
||||||
const { eliminarArchivo } = require('../../helper/helper');
|
const { eliminarArchivo } = require('../../helper/helper');
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Carrera = require(`${dbPath}/Carrera`);
|
|
||||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||||
|
|
||||||
const inscripcion = async (body, file) => {
|
const inscripcion = async (body, file) => {
|
||||||
const ahora = moment();
|
const ahora = moment();
|
||||||
const idUsuario = validarNumeroEntero(body.idUsuario, 'id Usuario', true);
|
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 idArea = validarNumeroEntero(body.idArea, 'id Area', true);
|
||||||
const monto = validarNumero(body.monto, 'monto', true);
|
const monto = validarNumero(body.monto, 'monto', true);
|
||||||
const folio = body.folio;
|
const folio = body.folio ? validarNumero(body.folio, 'folio', true, 6) : '';
|
||||||
|
const fechaTicket = body.fechaTicket;
|
||||||
|
|
||||||
return Inscripcion.findOne({
|
return Inscripcion.findOne({
|
||||||
where: { folio },
|
where: { folio, cancelacion: 0 },
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (res) throw new Error('Este folio ya esta registrado');
|
if (res) throw new Error('Este folio ya esta registrado');
|
||||||
return Inscripcion.findOne({
|
return Inscripcion.findOne({
|
||||||
where: { idUsuario, idArea },
|
where: {
|
||||||
|
idUsuario,
|
||||||
|
idArea,
|
||||||
|
cancelacion: 0,
|
||||||
|
idPeriodo: Number(process.env.PERIODO),
|
||||||
|
},
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (res) throw new Error('Ya estas registrado en esta área');
|
if (res) throw new Error('Ya estas registrado en esta área');
|
||||||
if (file) {
|
|
||||||
|
if (file && folio && monto && fechaTicket) {
|
||||||
return Inscripcion.create({
|
return Inscripcion.create({
|
||||||
idUsuario,
|
idUsuario,
|
||||||
idArea,
|
idArea,
|
||||||
@@ -32,7 +51,8 @@ const inscripcion = async (body, file) => {
|
|||||||
rutaTicket: file.path,
|
rutaTicket: file.path,
|
||||||
extension: file.mimetype.split('/')[1],
|
extension: file.mimetype.split('/')[1],
|
||||||
fechaInscripcion: ahora.format(),
|
fechaInscripcion: ahora.format(),
|
||||||
fechaTicket: body.fechaTicket,
|
fechaTicket,
|
||||||
|
idPeriodo: Number(process.env.PERIODO),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return Inscripcion.create({
|
return Inscripcion.create({
|
||||||
@@ -45,12 +65,20 @@ const inscripcion = async (body, file) => {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (file)
|
if (file && folio && monto && fechaTicket) {
|
||||||
fs.renameSync(file.path, file.path + '.' + file.mimetype.split('/')[1]);
|
fs.renameSync(file.path, file.path + '.' + file.mimetype.split('/')[1]);
|
||||||
|
|
||||||
|
agregarRecibo(
|
||||||
|
folio,
|
||||||
|
monto,
|
||||||
|
moment(new Date(fechaTicket)).format('YYYY-MM-DD'),
|
||||||
|
numeroCuenta
|
||||||
|
);
|
||||||
|
agregarDetalleServicio(monto, numeroCuenta);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then((res) => ({
|
.then((res) => ({
|
||||||
message:
|
message: `Tu inscripción está sujeta a validación por parte de un operador de CEDETEC, espera mas información en tu correo de Pc-puma.`,
|
||||||
'¡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',
|
|
||||||
}))
|
}))
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
if (file) eliminarArchivo(file.path);
|
if (file) eliminarArchivo(file.path);
|
||||||
|
|||||||
@@ -1,20 +1,24 @@
|
|||||||
const validar = require('../../helper/validar');
|
const { NUMBER } = require('sequelize');
|
||||||
|
const { validarNumeroEntero } = require('../../helper/validar');
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Carrera = require(`${dbPath}/Carrera`);
|
|
||||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||||
|
|
||||||
const inscripciones = async (body) => {
|
const inscripciones = async (body) => {
|
||||||
// const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
|
const idUsuario = validarNumeroEntero(body.idUsuario, 'Usuario', true);
|
||||||
|
|
||||||
return Inscripcion.findAll({
|
return Inscripcion.findAll({
|
||||||
where: { idUsuario: body.idUsuario },
|
where: { idUsuario },
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (!res) return [];
|
if (!res) return [];
|
||||||
return Inscripcion.findAll({
|
return Inscripcion.findAll({
|
||||||
where: { idUsuario: body.idUsuario },
|
where: {
|
||||||
|
idUsuario,
|
||||||
|
cancelacion: 0,
|
||||||
|
idPeriodo: Number(process.env.PERIODO),
|
||||||
|
},
|
||||||
attributes: [
|
attributes: [
|
||||||
'idInscripcion',
|
'idInscripcion',
|
||||||
'validacion',
|
'validacion',
|
||||||
'confirmacion',
|
|
||||||
'folio',
|
'folio',
|
||||||
'monto',
|
'monto',
|
||||||
'idUsuario',
|
'idUsuario',
|
||||||
|
|||||||
@@ -2,18 +2,20 @@ const validar = require('../../helper/validar');
|
|||||||
const escolares = require('./escolares');
|
const escolares = require('./escolares');
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
const { crearToken } = require('../../middleware/autentificacion');
|
const { crearToken } = require('../../middleware/autentificacion');
|
||||||
const Usuario = require('../../db/tablas/Usuario');
|
|
||||||
|
|
||||||
const login = async (body) => {
|
const login = async (body) => {
|
||||||
const numeroCuenta = validar.validarNumeroCuenta(body.numeroCuenta);
|
const numeroCuenta = validar.validarNumeroCuenta(
|
||||||
const data = {
|
body.numeroCuenta,
|
||||||
usuario: 'votacionesUser',
|
'número de cuenta',
|
||||||
password: 'poasfnr*/049_]',
|
true
|
||||||
numeroCuenta: numeroCuenta,
|
);
|
||||||
passwordUser: body.passwordUser,
|
const data = {
|
||||||
};
|
usuario: 'votacionesUser',
|
||||||
|
password: 'poasfnr*/049_]',
|
||||||
|
numeroCuenta: numeroCuenta,
|
||||||
|
passwordUser: body.passwordUser,
|
||||||
|
};
|
||||||
|
|
||||||
console.log(numeroCuenta, body.passwordUser);
|
|
||||||
return axios
|
return axios
|
||||||
.post(
|
.post(
|
||||||
`https://venus.acatlan.unam.mx/conexionEscolares_test/ingresarAlumno`,
|
`https://venus.acatlan.unam.mx/conexionEscolares_test/ingresarAlumno`,
|
||||||
|
|||||||
@@ -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();
|
|
||||||
+30
-1
@@ -7,6 +7,8 @@ const Area = require('./tablas/Area');
|
|||||||
const FechaInscripcion = require('./tablas/FechaInscripcion');
|
const FechaInscripcion = require('./tablas/FechaInscripcion');
|
||||||
const Inscripcion = require('./tablas/Inscripcion');
|
const Inscripcion = require('./tablas/Inscripcion');
|
||||||
const Admin = require('./tablas/Admin');
|
const Admin = require('./tablas/Admin');
|
||||||
|
const ProfesorInscrito = require('./tablas/ProfesorInscrito');
|
||||||
|
const Profesor = require('./tablas/Profesor');
|
||||||
|
|
||||||
const drop = async () => {
|
const drop = async () => {
|
||||||
console.log('\nPaso 1) Desinstalando la db.'.bold.blue);
|
console.log('\nPaso 1) Desinstalando la db.'.bold.blue);
|
||||||
@@ -28,6 +30,15 @@ const drop = async () => {
|
|||||||
|
|
||||||
await Carrera.drop();
|
await Carrera.drop();
|
||||||
console.log('La tabla Carrera se desinstalo correctamente.'.magenta);
|
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 () => {
|
const sync = async () => {
|
||||||
@@ -50,10 +61,18 @@ const sync = async () => {
|
|||||||
|
|
||||||
await Inscripcion.sync();
|
await Inscripcion.sync();
|
||||||
console.log('La tabla Inscripcion se instalo correctamente.'.magenta);
|
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 dataArea = async () => {
|
||||||
const data = ['Windows', 'Macintosh', 'Linux', 'Mesa para laptop'];
|
const data = ['Windows', 'Macintosh', 'Linux'];
|
||||||
|
|
||||||
console.log('\nPaso 3) Instalando catalogo area.'.bold.blue);
|
console.log('\nPaso 3) Instalando catalogo area.'.bold.blue);
|
||||||
for (let i = 0; i < data.length; i++) await Area.create({ area: data[i] });
|
for (let i = 0; i < data.length; i++) await Area.create({ area: data[i] });
|
||||||
@@ -61,6 +80,16 @@ const dataArea = async () => {
|
|||||||
|
|
||||||
const dataAdmin = async () => {
|
const dataAdmin = async () => {
|
||||||
console.log('\nPaso 4) Insertando admin.'.bold.blue);
|
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({
|
await Admin.create({
|
||||||
idTipoUsuario: 1,
|
idTipoUsuario: 1,
|
||||||
usuario: 'Araceli',
|
usuario: 'Araceli',
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
// db/tablas/Alumno.js
|
||||||
|
const { DataTypes } = require('sequelize');
|
||||||
|
const sequelize = require('../../config/sequelize.conf');
|
||||||
|
|
||||||
|
const Alumno = sequelize.define('Alumno', {
|
||||||
|
id_cuenta: {
|
||||||
|
type: DataTypes.STRING(9), // Aunque en DB es int(9) zerofill, mejor manejarlo como string con ceros a la izquierda
|
||||||
|
primaryKey: true,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
nombre: {
|
||||||
|
type: DataTypes.STRING(300),
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
fecha_nacimiento: {
|
||||||
|
type: DataTypes.STRING(8), // Si quieres, puedes parsear fechas después
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
|
correo: {
|
||||||
|
type: DataTypes.STRING(100),
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
|
credito: {
|
||||||
|
type: DataTypes.DECIMAL(10, 2),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 0.00,
|
||||||
|
},
|
||||||
|
fecha_actualizacion_credito: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: DataTypes.NOW,
|
||||||
|
},
|
||||||
|
vigente: {
|
||||||
|
type: DataTypes.ENUM('si', 'no'),
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 'si',
|
||||||
|
},
|
||||||
|
id_periodo: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
|
fecha_registro: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
id_carrera: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
generacion: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: true,
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
tableName: 'alumno',
|
||||||
|
timestamps: false, // porque no hay campos createdAt/updatedAt explícitos
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = Alumno;
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
// db/tablas/AlumnoInscrito.js
|
||||||
|
const { DataTypes } = require('sequelize');
|
||||||
|
const sequelize = require('../../config/sequelize.conf');
|
||||||
|
|
||||||
|
const AlumnoInscrito = sequelize.define('AlumnoInscrito', {
|
||||||
|
id_alumno_inscrito: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
primaryKey: true,
|
||||||
|
autoIncrement: true,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
fecha_inscripcion: {
|
||||||
|
type: DataTypes.DATE,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: DataTypes.NOW,
|
||||||
|
},
|
||||||
|
tiempo_disponible: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: 3600,
|
||||||
|
},
|
||||||
|
realizo_pago: {
|
||||||
|
type: DataTypes.BOOLEAN, // tinyint(1) mapea a booleano
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: false,
|
||||||
|
},
|
||||||
|
platica: {
|
||||||
|
type: DataTypes.BOOLEAN, // bit(1)
|
||||||
|
allowNull: false,
|
||||||
|
defaultValue: false,
|
||||||
|
},
|
||||||
|
id_cuenta: {
|
||||||
|
type: DataTypes.STRING(9), // int(9) zerofill → string para mantener ceros a la izquierda
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
id_periodo: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
id_plataforma: {
|
||||||
|
type: DataTypes.INTEGER,
|
||||||
|
allowNull: false,
|
||||||
|
},
|
||||||
|
ad: {
|
||||||
|
type: DataTypes.BOOLEAN, // bit(1)
|
||||||
|
allowNull: true,
|
||||||
|
defaultValue: false,
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
tableName: 'alumno_inscrito',
|
||||||
|
timestamps: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = AlumnoInscrito;
|
||||||
@@ -18,16 +18,18 @@ Inscripcion.init(
|
|||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
defaultValue: 2,
|
defaultValue: 2,
|
||||||
},
|
},
|
||||||
confirmacion: {
|
cancelacion: {
|
||||||
type: DataTypes.BOOLEAN,
|
type: DataTypes.BOOLEAN,
|
||||||
allowNull: false,
|
defaultValue: 0,
|
||||||
defaultValue: false,
|
},
|
||||||
|
motivo: {
|
||||||
|
type: DataTypes.STRING(100),
|
||||||
|
defaultValue: null,
|
||||||
},
|
},
|
||||||
folio: {
|
folio: {
|
||||||
type: DataTypes.STRING(5),
|
type: DataTypes.STRING(10),
|
||||||
allowNull: true,
|
allowNull: true,
|
||||||
defaultValue: null,
|
defaultValue: null,
|
||||||
unique: true,
|
|
||||||
},
|
},
|
||||||
monto: {
|
monto: {
|
||||||
type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
@@ -59,6 +61,11 @@ Inscripcion.init(
|
|||||||
allowNull: true,
|
allowNull: true,
|
||||||
defaultValue: null,
|
defaultValue: null,
|
||||||
},
|
},
|
||||||
|
idPeriodo: {
|
||||||
|
type: DataTypes.INTEGER(8),
|
||||||
|
allowNull: true,
|
||||||
|
defaultValue: null,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
sequelize,
|
sequelize,
|
||||||
|
|||||||
@@ -0,0 +1,39 @@
|
|||||||
|
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;
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
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,
|
allowNull: true,
|
||||||
defaultValue: null,
|
defaultValue: null,
|
||||||
},
|
},
|
||||||
semestre: {
|
generacion: {
|
||||||
type: DataTypes.STRING(30),
|
type: DataTypes.STRING(5),
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
},
|
},
|
||||||
idCarrera: {
|
idCarrera: {
|
||||||
@@ -43,12 +43,12 @@ Usuario.init(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
// Usuario.belongsTo(Carrera, {
|
Usuario.belongsTo(Carrera, {
|
||||||
// foreignKey: {
|
foreignKey: {
|
||||||
// name: 'idCarrera',
|
name: 'idCarrera',
|
||||||
// type: DataTypes.INTEGER,
|
type: DataTypes.INTEGER,
|
||||||
// allowNull: false,
|
allowNull: false,
|
||||||
// },
|
},
|
||||||
// });
|
});
|
||||||
|
|
||||||
module.exports = Usuario;
|
module.exports = Usuario;
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
const correoInscripciones = () => ({
|
||||||
|
subject: `Inscripción a CEDETEC`,
|
||||||
|
msj: `
|
||||||
|
<p>Estimado Usuario</p>
|
||||||
|
<p>
|
||||||
|
Su inscripción ha sido validada por un operador de CEDETEC, en un lapso de 10 min su cuenta será activa y tendrá acceso a las máquinas.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
Por favor ingresa a <a href="https://kalinga.acatlan.unam.mx/cedetec/">Kalinga</a> para confirmar tu inscripcón.
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>Te sugerimos guardar tu ticket para cualquier aclaración.</p>
|
||||||
|
|
||||||
|
<p>En caso de recibir un correo con el asunto Inscripción declinada, se cancelará el servicio y no podrás hacer uso de los servicios, en este caso acercate con un operador de CEDETEC para que te apoye.</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 pudo ser 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,8 +6,22 @@ const comparar = (password, dbPassword) => {
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
const encriptar = (password) =>
|
const encriptar = (password) => {
|
||||||
bcrypt.hashSync(password, Number(process.env.SALT_ROUNDS));
|
/*
|
||||||
|
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 generarPassword = () => {
|
const generarPassword = () => {
|
||||||
const length = 8;
|
const length = 8;
|
||||||
|
|||||||
@@ -5,11 +5,10 @@ const send = require('gmail-send')({
|
|||||||
pass: process.env.GMAILPASSWORD,
|
pass: process.env.GMAILPASSWORD,
|
||||||
});
|
});
|
||||||
|
|
||||||
const gmail = (subject, to, text) => {
|
const gmail = (subject, to, html) => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
send({ subject, to, text }, (error, result, fullResult) => {
|
send({ subject, to, html }, (error, result, fullResult) => {
|
||||||
if (error) reject(error);
|
if (error) reject(error);
|
||||||
console.log(fullResult);
|
|
||||||
resolve(result);
|
resolve(result);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ const caracterEspecial = (char) => {
|
|||||||
'#',
|
'#',
|
||||||
'%',
|
'%',
|
||||||
'\n',
|
'\n',
|
||||||
|
'@',
|
||||||
];
|
];
|
||||||
|
|
||||||
for (let i = 0; i < charset.length; i++) if (charset[i] === char) return true;
|
for (let i = 0; i < charset.length; i++) if (charset[i] === char) return true;
|
||||||
|
|||||||
@@ -43,4 +43,8 @@ const crearTokenOperador = (data) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = { verificaToken, crearToken, crearTokenAdmin };
|
module.exports = { verificaToken, crearToken, crearTokenAdmin };
|
||||||
|
|||||||
+45
-2
@@ -1,15 +1,18 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const app = express();
|
const app = express();
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { validarAlfanumerico } = require('../helper/validar');
|
|
||||||
const { verificaToken } = require('../middleware/autentificacion');
|
const { verificaToken } = require('../middleware/autentificacion');
|
||||||
const route = '/Admin';
|
const route = '/Admin';
|
||||||
const controllerPath = '../controller/Admin';
|
const controllerPath = '../controller/Admin';
|
||||||
|
const login = require(`${controllerPath}/login`);
|
||||||
const todasInscripciones = require(`${controllerPath}/todasInscripciones`);
|
const todasInscripciones = require(`${controllerPath}/todasInscripciones`);
|
||||||
const ticket = require(`${controllerPath}/ticket`);
|
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 validarTicket = require(`${controllerPath}/validarTicket`);
|
||||||
const reporte = require(`${controllerPath}/reporte`);
|
const reporte = require(`${controllerPath}/reporte`);
|
||||||
const login = require(`${controllerPath}/login`);
|
|
||||||
|
|
||||||
app.post(`${route}/login`, (req, res) => {
|
app.post(`${route}/login`, (req, res) => {
|
||||||
return login(req.body)
|
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) => {
|
app.put(`${route}/validar`, verificaToken, (req, res) => {
|
||||||
return validarTicket(req.body)
|
return validarTicket(req.body)
|
||||||
.then((data) => {
|
.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) => {
|
app.get(`${route}/reporte`, verificaToken, (req, res) => {
|
||||||
return reporte(req.query)
|
return reporte(req.query)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
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)
|
return inscripciones(req.query)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
res.status(200).json(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