Pushing search history

This commit is contained in:
Sean Edmunds
2025-02-20 15:47:39 -06:00
parent b890877c9f
commit 78d9b0ec7f

View File

@@ -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", () => {});