Added themePlaylist endpoints
This commit is contained in:
53
server.cjs
53
server.cjs
@@ -347,6 +347,57 @@ app.get("/trigger/api/backgrounds", async (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/trigger/api/themePlaylists", async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = "SELECT * FROM trigger_database.themePlaylists;";
|
||||
conn.query(query).then((rows) => {
|
||||
res.status(200).send(rows);
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.post("/trigger/api/themePlaylists", async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `INSERT INTO trigger_database.themePlaylists (name, themeList) VALUES ('${sqlEscape(req.body.name)}','${sqlEscape(req.body.themeList)}');`;
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.patch("/trigger/api/themePlaylists", async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `UPDATE trigger_database.themePlaylists SET name = '${sqlEscape(req.body.name)}', themeList = '${req.body.themeList}' WHERE id = '${req.body.id}';`;
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.delete("/trigger/api/themePlaylists", async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = `DELETE FROM trigger_database.themePlaylists WHERE id = '${req.body.id}'`;
|
||||
conn
|
||||
.query(query)
|
||||
.then((rows) => {
|
||||
res.status(200).send({ status: "success" });
|
||||
})
|
||||
.catch((err) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
});
|
||||
|
||||
app.get("/trigger/api/categories", async (req, res) => {
|
||||
const conn = await pool.getConnection();
|
||||
const query = "SELECT * from trigger_database.linkCategories;";
|
||||
@@ -496,7 +547,7 @@ app.delete("/trigger/api/searchHistory", async (req, res) => {
|
||||
res.status(500).send({ error: err });
|
||||
});
|
||||
conn.end();
|
||||
})
|
||||
});
|
||||
|
||||
// app is listening on port 5000
|
||||
app.listen(5000, "0.0.0.0", () => {});
|
||||
|
||||
Reference in New Issue
Block a user