diff --git a/server.cjs b/server.cjs index c1d7099..df22ca1 100644 --- a/server.cjs +++ b/server.cjs @@ -407,17 +407,9 @@ app.get("/trigger/api/categories", async (req, res) => { }); app.post("/trigger/api/categories", async (req, res) => { - let conn = await pool.getConnection(); - let query = "SELECT * from trigger_database.linkCategories;"; - let categoryIndex; + const conn = await pool.getConnection(); + const query = `INSERT INTO trigger_database.linkCategories (categoryName, categoryIndex, filterName) VALUES ('${sqlEscape(req.body.categoryName)}','${req.body.categoryIndex || 0}','${sqlEscape(req.body.filterName)}')`; conn.query(query).then((rows) => { - categoryIndex = rows.length; - }); - conn.end(); - conn = await pool.getConnection(); - query = `INSERT INTO trigger_database.linkCategories (categoryName, categoryIndex, filterName) VALUES ('${sqlEscape(req.body.categoryName)}','${req.body.categoryIndex || 0}','${sqlEscape(req.body.filterName)}')`; - conn.query(query).then((rows) => { - categoryIndex = rows.length; res.status(200).send({ status: "success" }); }); conn.end(); @@ -455,28 +447,32 @@ app.patch("/trigger/api/categoryOrder", async (req, res) => { const conn = await pool.getConnection(); req.body.map((category) => { conn - .query("UPDATE trigger_database.linkCategories SET categoryIndex = ? where id IN (?)", [category.index, category.id]) - .then((rows) => { - res.status(200); - }); + .query( + "UPDATE trigger_database.linkCategories SET categoryIndex = ? where id IN (?)", + [category.index, category.id], + ) + .then((rows) => { + res.status(200); + }); }); res.send({ status: "success" }); conn.end(); - }); app.patch("/trigger/api/linkOrder", async (req, res) => { const conn = await pool.getConnection(); req.body.map((link) => { conn - .query("UPDATE trigger_database.links SET \`index\` = ? where id IN (?)", [link.index, link.id]) - .then((rows) => { - res.status(200); - }); + .query("UPDATE trigger_database.links SET `index` = ? where id IN (?)", [ + link.index, + link.id, + ]) + .then((rows) => { + res.status(200); + }); }); res.send({ status: "success" }); conn.end(); - }); app.get("/trigger/api/wolClients", async (req, res) => {