Correciones para el boton de inscripcion
This commit is contained in:
@@ -65,7 +65,7 @@ const validarAlumnoInscrito = async (idCuenta) => {
|
||||
[idCuenta]
|
||||
)
|
||||
.then((rows) => {
|
||||
console.log('Resultado de la consulta alumno_inscrito:', rows);
|
||||
//console.log('Resultado de la consulta alumno_inscrito:', rows);
|
||||
|
||||
conn.end();
|
||||
if (rows.length === 0) return null;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
const Usuario = require('../../db/tablas/Usuario'); // Asegúrate de importar correctamente
|
||||
const inscripcion = require('../../db/tablas/Inscripcion');
|
||||
const enviarCorreoInscripcion = require('../../controller/Profesor/enviarCorreo'); // Ajusta si está en otra ruta
|
||||
const { where } = require('sequelize');
|
||||
const Alumno = require('../../db/tablas/Alumno');
|
||||
const AlumnoInscrito = require('../../db/tablas/AlumnoInscrito');
|
||||
|
||||
async function realizarInscripcion(req, res) {
|
||||
const { idUsuario, nombre, numeroCuenta, correo } = req.body;
|
||||
const { id_cuenta, nombre, correo } = req.body;
|
||||
|
||||
try {
|
||||
if (!nombre || !id_cuenta ) {
|
||||
@@ -12,14 +11,14 @@ async function realizarInscripcion(req, res) {
|
||||
}
|
||||
|
||||
// 1. Buscar si el usuario existe
|
||||
const usuario = await alumno.findOne({ where: { id_cuenta } });
|
||||
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 alumno_inscrito.findOne({
|
||||
const inscripcionExistente = await AlumnoInscrito.findOne({
|
||||
where: { id_cuenta: usuario.id_cuenta }
|
||||
});
|
||||
|
||||
@@ -30,10 +29,10 @@ async function realizarInscripcion(req, res) {
|
||||
}
|
||||
|
||||
// 3. Crear inscripción
|
||||
await alumno_inscrito.create({
|
||||
id_cuenta: usuario.idUsuario,
|
||||
id_periodo: 1,
|
||||
id_plataforma: 1,
|
||||
await AlumnoInscrito.create({
|
||||
id_cuenta: usuario.id_cuenta,
|
||||
id_periodo: 26,
|
||||
id_plataforma: 5,
|
||||
fecha_inscripcion: new Date(),
|
||||
tiempo_disponible: 3600,
|
||||
realizo_pago: 0,
|
||||
@@ -43,7 +42,7 @@ async function realizarInscripcion(req, res) {
|
||||
|
||||
|
||||
// 4. Realizar confirmacion
|
||||
await alumno_inscrito.update(
|
||||
await AlumnoInscrito.update(
|
||||
{ platica: 1 },
|
||||
{ where: { id_cuenta: usuario.id_cuenta } }
|
||||
);
|
||||
@@ -56,6 +55,8 @@ async function realizarInscripcion(req, res) {
|
||||
|
||||
} 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.' });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
Reference in New Issue
Block a user