From 78d9b0ec7f116e83de143afe50a33d466e65df3d Mon Sep 17 00:00:00 2001 From: Sean Edmunds Date: Thu, 20 Feb 2025 15:47:39 -0600 Subject: [PATCH] Pushing search history --- server.cjs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/server.cjs b/server.cjs index bd9ce8d..85921b5 100644 --- a/server.cjs +++ b/server.cjs @@ -460,5 +460,29 @@ app.post("/trigger/api/wakeClient", async (req, res) => { }); }); +app.get("/trigger/api/searchHistory", async (req, res) => { + const conn = await pool.getConnection(); + const query = + "SELECT * FROM trigger_database.searchHistory ORDER BY dateTimeStamp DESC;"; + conn.query(query).then((rows) => { + res.status(200).send(rows); + }); + conn.end(); +}); + +app.post("/trigger/api/searchHistory", async (req, res) => { + const conn = await pool.getConnection(); + const query = `INSERT INTO trigger_database.searchHistory (prefix, provider, searchTerm) VALUES ('${sqlEscape(req.body.prefix)}', '${sqlEscape(req.body.provider)}', '${sqlEscape(req.body.searchTerm)}')`; + conn + .query(query) + .then((rows) => { + res.status(200).send({ status: "success" }); + }) + .catch((err) => { + res.status(500).send({ error: err }); + }); + conn.end(); +}); + // app is listening on port 5000 app.listen(5000, "0.0.0.0", () => {});