2022-01-24 14:33:16 -06:00
|
|
|
require('./config');
|
|
|
|
|
const mariadb = require('mariadb');
|
|
|
|
|
|
2022-03-04 12:53:47 -06:00
|
|
|
const pool = mariadb.createPool({
|
2022-03-03 23:09:14 -06:00
|
|
|
host: process.env.HOST_DB,
|
|
|
|
|
user: process.env.USER_DB,
|
|
|
|
|
password: process.env.PASSWORD_DB,
|
2022-03-04 12:53:47 -06:00
|
|
|
database: process.env.SAT_DB,
|
2022-01-24 14:33:16 -06:00
|
|
|
});
|
|
|
|
|
|
2022-03-15 00:23:09 -06:00
|
|
|
const obtenerDatosUsr = async (numeroCuenta) => {
|
2022-03-04 12:53:47 -06:00
|
|
|
const conn = await pool.getConnection().catch((err) => {
|
2022-01-24 14:33:16 -06:00
|
|
|
throw new Error('No se pudo conectar con la db. ' + err);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return conn
|
2022-03-15 00:23:09 -06:00
|
|
|
.query(
|
|
|
|
|
`SELECT id_carrera, generacion FROM alumno WHERE id_cuenta = ${numeroCuenta}`
|
|
|
|
|
)
|
2022-01-24 14:33:16 -06:00
|
|
|
.then((rows) => {
|
|
|
|
|
conn.end();
|
2022-01-26 00:21:54 -06:00
|
|
|
return rows[0];
|
2022-01-24 14:33:16 -06:00
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
conn.end();
|
|
|
|
|
throw new Error('Hubo un problema con el querry.' + err);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-26 00:21:54 -06:00
|
|
|
const obtenerCarrera = async (idCarrera) => {
|
2022-03-04 12:53:47 -06:00
|
|
|
const conn = await pool.getConnection().catch((err) => {
|
2022-01-24 14:33:16 -06:00
|
|
|
throw new Error('No se pudo conectar con la db. ' + err);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return conn
|
2022-01-30 23:50:17 -06:00
|
|
|
.query(`SELECT id_carrera FROM carrera WHERE id_carrera = ${idCarrera}`)
|
2022-01-24 14:33:16 -06:00
|
|
|
.then((rows) => {
|
|
|
|
|
conn.end();
|
|
|
|
|
return rows[0];
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
conn.end();
|
|
|
|
|
throw new Error('Hubo un problema con el querry.' + err);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-06 20:02:42 -06:00
|
|
|
const usuarioInscrito = async (numeroCuenta, realizoPago) => {
|
2022-03-04 12:53:47 -06:00
|
|
|
const conn = await pool.getConnection().catch((err) => {
|
2022-03-03 23:09:14 -06:00
|
|
|
throw new Error('No se pudo conectar con la db. ' + err);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return conn
|
|
|
|
|
.query(
|
2022-03-06 20:02:42 -06:00
|
|
|
`INSERT INTO alumno_inscrito(id_cuenta,id_periodo,id_plataforma,realizo_pago,platica) values(${numeroCuenta}, 20, 4, ${realizoPago}, 1)`
|
2022-03-03 23:09:14 -06:00
|
|
|
)
|
|
|
|
|
.then((rows) => {
|
|
|
|
|
conn.end();
|
|
|
|
|
return rows[0];
|
|
|
|
|
})
|
|
|
|
|
.catch((err) => {
|
|
|
|
|
conn.end();
|
|
|
|
|
throw new Error('Hubo un problema con el querry.' + err);
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2022-03-15 00:23:09 -06:00
|
|
|
module.exports = { obtenerDatosUsr, obtenerCarrera, usuarioInscrito };
|