Compare commits
46 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 |
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
|
images/
|
||||||
.env
|
.env
|
||||||
Generated
+24
-6
@@ -24,6 +24,7 @@
|
|||||||
"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"
|
||||||
},
|
},
|
||||||
@@ -1081,6 +1082,15 @@
|
|||||||
"nodemailer": "^6.6.5"
|
"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",
|
||||||
@@ -1768,9 +1778,10 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/nodemailer": {
|
"node_modules/nodemailer": {
|
||||||
"version": "6.7.2",
|
"version": "7.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.7.2.tgz",
|
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-7.0.5.tgz",
|
||||||
"integrity": "sha512-Dz7zVwlef4k5R71fdmxwR8Q39fiboGbu3xgswkzGwczUfjp873rVxt1O46+Fh0j1ORnAC6L9+heI8uUpO6DT7Q==",
|
"integrity": "sha512-nsrh2lO3j4GkLLXoeEksAMgAOqxOv6QumNRVQTJwKH4nuiww6iC2y7GyANs9kRAxCexg3+lTWM3PZ91iLlVjfg==",
|
||||||
|
"license": "MIT-0",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=6.0.0"
|
"node": ">=6.0.0"
|
||||||
}
|
}
|
||||||
@@ -3583,6 +3594,13 @@
|
|||||||
"requires": {
|
"requires": {
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
"nodemailer": "^6.6.5"
|
"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": {
|
||||||
@@ -4120,9 +4138,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nodemailer": {
|
"nodemailer": {
|
||||||
"version": "6.7.2",
|
"version": "7.0.5",
|
||||||
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.7.2.tgz",
|
"resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-7.0.5.tgz",
|
||||||
"integrity": "sha512-Dz7zVwlef4k5R71fdmxwR8Q39fiboGbu3xgswkzGwczUfjp873rVxt1O46+Fh0j1ORnAC6L9+heI8uUpO6DT7Q=="
|
"integrity": "sha512-nsrh2lO3j4GkLLXoeEksAMgAOqxOv6QumNRVQTJwKH4nuiww6iC2y7GyANs9kRAxCexg3+lTWM3PZ91iLlVjfg=="
|
||||||
},
|
},
|
||||||
"nodemon": {
|
"nodemon": {
|
||||||
"version": "2.0.15",
|
"version": "2.0.15",
|
||||||
|
|||||||
+2
-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",
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
"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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+117
-135
@@ -6,163 +6,145 @@ const pool = mariadb.createPool({
|
|||||||
user: process.env.USER_DB,
|
user: process.env.USER_DB,
|
||||||
password: process.env.PASSWORD_DB,
|
password: process.env.PASSWORD_DB,
|
||||||
database: process.env.SAT_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 obtenerDatosUsr = async (numeroCuenta) => {
|
const obtenerDatosUsr = async (numeroCuenta) => {
|
||||||
const conn = await pool.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
|
const rows = await conn.query(
|
||||||
.query(
|
|
||||||
`SELECT id_carrera, generacion FROM alumno WHERE id_cuenta = ${numeroCuenta}`
|
`SELECT id_carrera, generacion FROM alumno WHERE id_cuenta = ${numeroCuenta}`
|
||||||
)
|
);
|
||||||
.then((rows) => {
|
|
||||||
conn.end();
|
return rows[0];
|
||||||
return rows[0];
|
} catch (err) {
|
||||||
})
|
throw new Error('Hubo un problema con el querry.' + err);
|
||||||
.catch((err) => {
|
} finally {
|
||||||
conn.end();
|
if (conn) conn.end();
|
||||||
throw new Error('Hubo un problema con el querry.' + err);
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const obtenerCarrera = async (idCarrera) => {
|
// Agregue para profesores
|
||||||
const conn = await pool.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, idArea) => {
|
const validarPeriodoActivo = async (conn) => {
|
||||||
const conn = await pool.getConnection().catch((err) => {
|
return conn
|
||||||
throw new Error('No se pudo conectar con la db. ' + err);
|
|
||||||
});
|
|
||||||
|
|
||||||
return conn
|
|
||||||
.query(
|
.query(
|
||||||
`INSERT INTO alumno_inscrito(realizo_pago, id_cuenta, id_periodo, id_plataforma) values(1, ${numeroCuenta}, 20, ${idArea})`
|
`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);
|
|
||||||
});
|
});
|
||||||
};
|
|
||||||
|
|
||||||
const agregarRecibo = async (folio, monto, fechaTicket, numeroCuenta) => {
|
// console.log('Este es el periodo: ', rows[0])
|
||||||
const conn = await pool.getConnection().catch((err) => {
|
// console.log('Este es el id del periodo: ', rows[0].id_periodo)
|
||||||
throw new Error('No se pudo conectar con la db. ' + err);
|
// return rows[0].id_periodo;
|
||||||
});
|
}
|
||||||
|
|
||||||
return conn
|
const validarAlumnoInscrito = async (idCuenta) => {
|
||||||
.query(
|
console.log("Validando alumno inscrito con id_cuenta:", idCuenta);
|
||||||
`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)`
|
|
||||||
|
// 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]
|
||||||
)
|
)
|
||||||
.then((rows) => {
|
|
||||||
conn.end();
|
if (rows.length === 0) return null;
|
||||||
return rows[0];
|
|
||||||
})
|
return rows[0];
|
||||||
.catch((err) => {
|
} catch (error) {
|
||||||
conn.end();
|
throw new Error('Error al validar alumno inscrito: ' + error);
|
||||||
throw new Error('Hubo un problema con el querry.' + err);
|
} 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);
|
||||||
|
// });
|
||||||
};
|
};
|
||||||
|
|
||||||
const agregarDetalleServicio = async (monto, numeroCuenta) => {
|
|
||||||
const conn = await pool.getConnection().catch((err) => {
|
// Para envios de correos
|
||||||
throw new Error('No se pudo conectar con la db. ' + err);
|
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,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
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);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const borrarInscripcion = async (numeroCuenta) => {
|
module.exports = { buscarProfesorPorNumero, validarAlumnoInscrito };
|
||||||
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,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -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)
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const { validarNumeroEntero } = require('../../helper/validar');
|
const { validarNumeroEntero, validarNumero } = require('../../helper/validar');
|
||||||
const { Op } = require('sequelize');
|
const { Op } = require('sequelize');
|
||||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||||
|
|
||||||
@@ -9,7 +9,7 @@ const actualizarTicket = async (body) => {
|
|||||||
'id Inscripcion',
|
'id Inscripcion',
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
const monto = validarNumeroEntero(body.monto, 'monto', true);
|
const monto = validarNumero(body.monto, 'monto', true, null, false);
|
||||||
const folio = validarNumeroEntero(body.folio, 'folio', true);
|
const folio = validarNumeroEntero(body.folio, 'folio', true);
|
||||||
|
|
||||||
return Inscripcion.findOne({
|
return Inscripcion.findOne({
|
||||||
|
|||||||
@@ -6,8 +6,15 @@ const { validarNumeroEntero } = require('../../helper/validar');
|
|||||||
|
|
||||||
const todasInscripciones = async (body) => {
|
const todasInscripciones = async (body) => {
|
||||||
const validacion = validarNumeroEntero(body.validacion, 'validacion', true);
|
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, cancelacion: 0 },
|
where: {
|
||||||
|
validacion,
|
||||||
|
cancelacion: 0,
|
||||||
|
idPeriodo: Number(process.env.PERIODO),
|
||||||
|
},
|
||||||
|
order: order,
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: Usuario,
|
model: Usuario,
|
||||||
|
|||||||
@@ -1,9 +1,23 @@
|
|||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||||
const { validarNumeroEntero } = require('../../helper/validar');
|
const {
|
||||||
|
validarNumeroEntero,
|
||||||
|
validarNumeroCuenta,
|
||||||
|
} = require('../../helper/validar');
|
||||||
|
const correoInscripcion = require('../../helper/correo');
|
||||||
|
|
||||||
const validarSinTicket = async (body) => {
|
const validarSinTicket = async (body) => {
|
||||||
|
const numeroCuenta = validarNumeroCuenta(
|
||||||
|
body.numeroCuenta,
|
||||||
|
'número de cuenta',
|
||||||
|
true
|
||||||
|
);
|
||||||
const idUsuario = validarNumeroEntero(body.idUsuario, 'usuario', true);
|
const idUsuario = validarNumeroEntero(body.idUsuario, 'usuario', true);
|
||||||
|
const idArea = validarNumeroEntero(body.idArea, 'IDAREA', true);
|
||||||
|
|
||||||
|
let correo = {};
|
||||||
|
let email = '';
|
||||||
|
|
||||||
return Inscripcion.update(
|
return Inscripcion.update(
|
||||||
{
|
{
|
||||||
validacion: 1,
|
validacion: 1,
|
||||||
@@ -14,11 +28,17 @@ const validarSinTicket = async (body) => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
.then((res) => {
|
||||||
|
email = `${numeroCuenta}@pcpuma.acatlan.unam.mx`;
|
||||||
|
usuarioInscrito(numeroCuenta, idArea);
|
||||||
|
correo = correoInscripcion();
|
||||||
|
gmail(correo.subject, email, correo.msj);
|
||||||
|
})
|
||||||
.then((res) => ({
|
.then((res) => ({
|
||||||
message: '¡El ticket a sido validado de forma correcta!',
|
message: '¡El ticket a sido validado de forma correcta!',
|
||||||
}))
|
}))
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
throw new Error('¡ No fue posible validar la inscripción !. ');
|
throw new Error('¡No fue posible validar la inscripción!');
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ const {
|
|||||||
validarNumeroCuenta,
|
validarNumeroCuenta,
|
||||||
} = require('../../helper/validar');
|
} = require('../../helper/validar');
|
||||||
const {
|
const {
|
||||||
borrarInscripcion,
|
usuarioInscrito,
|
||||||
borrarRecibo,
|
borrarRecibo,
|
||||||
borrarDetalleServicio,
|
borrarDetalleServicio,
|
||||||
} = require('../../config/mariadb.conf');
|
} = require('../../config/mariadb.conf');
|
||||||
@@ -11,78 +11,79 @@ const dbPath = '../../db/tablas';
|
|||||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||||
const gmail = require('../../helper/gmail');
|
const gmail = require('../../helper/gmail');
|
||||||
const correoDeclinar = require('../../helper/correoDeclinar');
|
const correoDeclinar = require('../../helper/correoDeclinar');
|
||||||
|
const correoInscripcion = require('../../helper/correo');
|
||||||
|
|
||||||
const validarTicket = async (body) => {
|
const validarTicket = async (body) => {
|
||||||
const folio = validarNumeroEntero(body.folio, 'folio', true);
|
|
||||||
const numeroCuenta = validarNumeroCuenta(
|
const numeroCuenta = validarNumeroCuenta(
|
||||||
body.numeroCuenta,
|
body.numeroCuenta,
|
||||||
'número de cuenta',
|
'número de cuenta',
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
const folio = validarNumeroEntero(body.folio, 'folio', true);
|
||||||
|
const idArea = validarNumeroEntero(body.idArea, 'IDAREA', true);
|
||||||
|
|
||||||
let correo = {};
|
let correo = {};
|
||||||
let email = '';
|
let email = '';
|
||||||
|
|
||||||
return (
|
return Inscripcion.findOne({
|
||||||
Inscripcion.findOne({
|
where: { folio },
|
||||||
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) => {
|
.then((res) => {
|
||||||
if (!res) throw new Error('Este folio no existe');
|
if (res) throw new Error('Este folio ya fue validado');
|
||||||
idUsuario = res.idUsuario;
|
return Inscripcion.update(
|
||||||
if (body.validacion == 1) {
|
{
|
||||||
return Inscripcion.findOne({
|
validacion: body.validacion,
|
||||||
where: { folio, validacion: 1 },
|
},
|
||||||
});
|
{
|
||||||
}
|
where: {
|
||||||
})
|
folio,
|
||||||
.then((res) => {
|
cancelacion: 0,
|
||||||
if (res) throw new Error('Este folio ya fue validado');
|
|
||||||
return Inscripcion.update(
|
|
||||||
{
|
|
||||||
validacion: body.validacion,
|
|
||||||
},
|
},
|
||||||
|
}
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
email = `${numeroCuenta}@pcpuma.acatlan.unam.mx`;
|
||||||
|
if (body.validacion === 1) {
|
||||||
|
usuarioInscrito(numeroCuenta, idArea);
|
||||||
|
correo = correoInscripcion();
|
||||||
|
} else {
|
||||||
|
borrarRecibo(folio, numeroCuenta);
|
||||||
|
borrarDetalleServicio(numeroCuenta);
|
||||||
|
correo = correoDeclinar();
|
||||||
|
return Inscripcion.update(
|
||||||
|
{ motivo: body.motivo },
|
||||||
{
|
{
|
||||||
where: {
|
where: {
|
||||||
folio,
|
folio,
|
||||||
cancelacion: 0,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
})
|
}
|
||||||
//el ticket ya fue validado
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
if (body.validacion === 0) {
|
gmail(correo.subject, email, correo.msj);
|
||||||
email = `${numeroCuenta}@pcpuma.acatlan.unam.mx`;
|
if (body.validacion === 1) {
|
||||||
correoDeclinar = correoInscripciones();
|
return {
|
||||||
borrarInscripcion(numeroCuenta);
|
message: '¡El ticket a sido validado de forma correcta!',
|
||||||
borrarRecibo(folio);
|
};
|
||||||
borrarDetalleServicio(numeroCuenta);
|
} else
|
||||||
return Inscripcion.update(
|
return {
|
||||||
{ motivo: body.motivo },
|
message: '¡El ticket a sido declinado',
|
||||||
{
|
};
|
||||||
where: {
|
})
|
||||||
folio,
|
.catch((err) => {
|
||||||
},
|
throw new Error('No fue posible validar el ticket. ' + err);
|
||||||
}
|
});
|
||||||
);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then((res) => {
|
|
||||||
if (body.validacion === 1) {
|
|
||||||
//Insertar en AD
|
|
||||||
return {
|
|
||||||
message: '¡El ticket a sido validado de forma correcta!',
|
|
||||||
};
|
|
||||||
} else
|
|
||||||
return {
|
|
||||||
message: '¡El ticket a sido declinado',
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
throw new Error('No fue posible validar el ticket. ' + err);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = validarTicket;
|
module.exports = validarTicket;
|
||||||
|
|||||||
@@ -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 };
|
||||||
@@ -2,6 +2,7 @@ const { obtenerDatosUsr } = require('../../config/mariadb.conf');
|
|||||||
const { validarNumeroCuenta } = require('../../helper/validar');
|
const { validarNumeroCuenta } = require('../../helper/validar');
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
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 = validarNumeroCuenta(
|
const numeroCuenta = validarNumeroCuenta(
|
||||||
@@ -11,15 +12,24 @@ const escolares = async (body) => {
|
|||||||
);
|
);
|
||||||
return Usuario.findOne({
|
return Usuario.findOne({
|
||||||
where: { numeroCuenta },
|
where: { numeroCuenta },
|
||||||
}).then((res) => {
|
}).then(async (res) => {
|
||||||
if (!res) {
|
if (!res) {
|
||||||
return obtenerDatosUsr(numeroCuenta).then(async (res) => {
|
const datosUsuario = await obtenerDatosUsr(numeroCuenta);
|
||||||
await Usuario.create({
|
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({
|
||||||
numeroCuenta,
|
numeroCuenta,
|
||||||
nombre: body.nombre,
|
nombre: body.nombre,
|
||||||
generacion: res.generacion,
|
generacion: datosUsuario.generacion,
|
||||||
carrera: body.carrera,
|
carrera: body.carrera,
|
||||||
idCarrera: res.id_carrera,
|
idCarrera: datosUsuario.id_carrera,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,15 @@
|
|||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const {
|
|
||||||
usuarioInscrito,
|
|
||||||
agregarRecibo,
|
|
||||||
agregarDetalleServicio,
|
|
||||||
} = require('../../config/mariadb.conf');
|
|
||||||
const {
|
const {
|
||||||
validarNumeroEntero,
|
validarNumeroEntero,
|
||||||
validarNumero,
|
validarNumero,
|
||||||
validarNumeroCuenta,
|
validarNumeroCuenta,
|
||||||
} = require('../../helper/validar');
|
} = require('../../helper/validar');
|
||||||
|
const {
|
||||||
|
agregarRecibo,
|
||||||
|
agregarDetalleServicio,
|
||||||
|
} = require('../../config/mariadb.conf');
|
||||||
const { eliminarArchivo } = require('../../helper/helper');
|
const { eliminarArchivo } = require('../../helper/helper');
|
||||||
const gmail = require('../../helper/gmail');
|
|
||||||
const correoInscripciones = require('../../helper/correo');
|
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||||
|
|
||||||
@@ -26,24 +23,25 @@ const inscripcion = async (body, file) => {
|
|||||||
);
|
);
|
||||||
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 = validarNumero(body.folio, 'folio', true, 6);
|
const folio = body.folio ? validarNumero(body.folio, 'folio', true, 6) : '';
|
||||||
const fechaTicket = body.fechaTicket;
|
const fechaTicket = body.fechaTicket;
|
||||||
|
|
||||||
let correo = {};
|
|
||||||
let email = '';
|
|
||||||
|
|
||||||
return Inscripcion.findOne({
|
return Inscripcion.findOne({
|
||||||
where: { folio, cancelacion: 0 },
|
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, cancelacion: 0 },
|
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');
|
||||||
email = `${numeroCuenta}@pcpuma.acatlan.unam.mx`;
|
|
||||||
correo = correoInscripciones();
|
if (file && folio && monto && fechaTicket) {
|
||||||
if (file && folio && fechaTicket) {
|
|
||||||
return Inscripcion.create({
|
return Inscripcion.create({
|
||||||
idUsuario,
|
idUsuario,
|
||||||
idArea,
|
idArea,
|
||||||
@@ -54,6 +52,7 @@ const inscripcion = async (body, file) => {
|
|||||||
extension: file.mimetype.split('/')[1],
|
extension: file.mimetype.split('/')[1],
|
||||||
fechaInscripcion: ahora.format(),
|
fechaInscripcion: ahora.format(),
|
||||||
fechaTicket,
|
fechaTicket,
|
||||||
|
idPeriodo: Number(process.env.PERIODO),
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return Inscripcion.create({
|
return Inscripcion.create({
|
||||||
@@ -66,21 +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]);
|
||||||
usuarioInscrito(numeroCuenta, idArea);
|
|
||||||
agregarRecibo(
|
agregarRecibo(
|
||||||
folio,
|
folio,
|
||||||
monto,
|
monto,
|
||||||
moment(fechaTicket).format('L'),
|
moment(new Date(fechaTicket)).format('YYYY-MM-DD'),
|
||||||
numeroCuenta
|
numeroCuenta
|
||||||
);
|
);
|
||||||
agregarDetalleServicio(monto, numeroCuenta);
|
agregarDetalleServicio(monto, numeroCuenta);
|
||||||
return gmail(correo.subject, email, correo.msj);
|
}
|
||||||
})
|
})
|
||||||
.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.`,
|
||||||
'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) => {
|
.catch((err) => {
|
||||||
if (file) eliminarArchivo(file.path);
|
if (file) eliminarArchivo(file.path);
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
const { NUMBER } = require('sequelize');
|
||||||
const { validarNumeroEntero } = require('../../helper/validar');
|
const { validarNumeroEntero } = require('../../helper/validar');
|
||||||
const dbPath = '../../db/tablas';
|
const dbPath = '../../db/tablas';
|
||||||
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
const Inscripcion = require(`${dbPath}/Inscripcion`);
|
||||||
@@ -10,7 +11,11 @@ const inscripciones = async (body) => {
|
|||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
if (!res) return [];
|
if (!res) return [];
|
||||||
return Inscripcion.findAll({
|
return Inscripcion.findAll({
|
||||||
where: { idUsuario, cancelacion: 0 },
|
where: {
|
||||||
|
idUsuario,
|
||||||
|
cancelacion: 0,
|
||||||
|
idPeriodo: Number(process.env.PERIODO),
|
||||||
|
},
|
||||||
attributes: [
|
attributes: [
|
||||||
'idInscripcion',
|
'idInscripcion',
|
||||||
'validacion',
|
'validacion',
|
||||||
|
|||||||
@@ -2,19 +2,22 @@ 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, 'número de cuenta', true);
|
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,
|
||||||
|
};
|
||||||
|
|
||||||
return axios
|
return axios
|
||||||
.post(
|
.post(
|
||||||
`https://venus.acatlan.unam.mx/conexionEscolares_test/ingresarAlumno`,
|
`https://venus.acatlan.unam.mx/conexionEscolares_test/ingresarAlumno`,
|
||||||
data
|
data
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -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,6 +61,14 @@ 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 () => {
|
||||||
@@ -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;
|
||||||
@@ -61,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;
|
||||||
|
|
||||||
|
|
||||||
@@ -44,11 +44,11 @@ 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;
|
||||||
|
|||||||
@@ -3,14 +3,16 @@ const correoInscripciones = () => ({
|
|||||||
msj: `
|
msj: `
|
||||||
<p>Estimado Usuario</p>
|
<p>Estimado Usuario</p>
|
||||||
<p>
|
<p>
|
||||||
Su inscripción esta sujeta a revisión, es necesario revisar los datos que registro en el sistema.
|
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>
|
||||||
|
|
||||||
<p>Te sugerimos guardar tu ticket para cualquier aclaración</p>
|
<p>
|
||||||
|
Por favor ingresa a <a href="https://kalinga.acatlan.unam.mx/cedetec/">Kalinga</a> para confirmar tu inscripcó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>Te sugerimos guardar tu ticket para cualquier aclaración.</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>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>Atentamente:</p>
|
||||||
<p>Atención Usuarios DSC</p>
|
<p>Atención Usuarios DSC</p>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const correoDeclinar = () => ({
|
|||||||
Su inscripción a sido declinada, favor de pasar a CEDETEC para aclarar la situción.
|
Su inscripción a sido declinada, favor de pasar a CEDETEC para aclarar la situción.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>Motivos por los cuales tu inscripción a sido declinada:</p>
|
<p>Motivos por los cuales tu inscripción pudo ser declinada:</p>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li>La foto del ticket no es visible.</li>
|
<li>La foto del ticket no es visible.</li>
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -37,4 +37,14 @@ 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 };
|
module.exports = { verificaToken, crearToken, crearTokenAdmin };
|
||||||
|
|||||||
@@ -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;
|
||||||
Reference in New Issue
Block a user