refactor: split routes and controllers
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
const pool = require("../db");
|
||||
|
||||
exports.getActive = async (req, res) => {
|
||||
const [rows] = await pool.query(
|
||||
"SELECT * FROM resources WHERE status != 'gekündigt'"
|
||||
);
|
||||
res.json(rows);
|
||||
};
|
||||
|
||||
exports.getCancelled = async (req, res) => {
|
||||
const [rows] = await pool.query(
|
||||
"SELECT * FROM resources WHERE status = 'gekündigt'"
|
||||
);
|
||||
res.json(rows);
|
||||
};
|
||||
|
||||
exports.create = async (req, res) => {
|
||||
await pool.query("INSERT INTO resources SET ?", req.body);
|
||||
res.json({ message: "Inserted" });
|
||||
};
|
||||
|
||||
exports.update = async (req, res) => {
|
||||
await pool.query(
|
||||
"UPDATE resources SET ? WHERE id = ?",
|
||||
[req.body, req.params.id]
|
||||
);
|
||||
res.json({ message: "Updated" });
|
||||
};
|
||||
|
||||
exports.remove = async (req, res) => {
|
||||
await pool.query(
|
||||
"DELETE FROM resources WHERE id = ?",
|
||||
[req.params.id]
|
||||
);
|
||||
res.json({ message: "Deleted" });
|
||||
};
|
||||
Reference in New Issue
Block a user