-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
304 additions
and
453 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const mysql = require("mysql2/promise"); | ||
require("dotenv").config(); | ||
|
||
// Configuración de la conexión a la base de datos MySQL utilizando un pool | ||
const pool = mysql.createPool({ | ||
host: process.env.MYSQL_HOST, | ||
user: process.env.MYSQL_USER, | ||
password: process.env.MYSQL_PASSWORD, | ||
database: process.env.MYSQL_DATABASE, | ||
connectionLimit: 20, // Número máximo de conexiones en el db | ||
waitForConnections: true, | ||
queueLimit: 0, | ||
}); | ||
|
||
const getAgendasForToday = async () => { | ||
try { | ||
// Obtenemos la fecha actual en formato MySQL (YYYY-MM-DD) | ||
const currentDate = new Date().toISOString().split("T")[0]; | ||
const query = `SELECT * FROM AgendaPeriodica WHERE DATE(Fechaini) = ?`; | ||
const [rows] = await pool.execute(query, [currentDate]); | ||
|
||
return rows; | ||
} catch (error) { | ||
console.error(`Error al realizar la consulta y es el siguiente ${error}`); | ||
throw new Error("Error al obtener los datos de la agenda"); | ||
} | ||
}; | ||
|
||
module.exports = getAgendasForToday; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const getAgendasForToday = require("../database/db"); | ||
|
||
const testHandler = async (req, res) => { | ||
try { | ||
const todayAgendas = await getAgendasForToday(); | ||
console.log("Agendas para el día actual:"); | ||
console.log(todayAgendas); | ||
res.send("Probando a ver si trae las agendas"); | ||
} catch (error) { | ||
console.error("Error al obtener las agendas para el día actual:", error); | ||
} | ||
}; | ||
|
||
module.exports = testHandler; |
Oops, something went wrong.