feature: add multi IP API
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
const pool = require("../db");
|
||||
|
||||
/* LIST IPs for resource */
|
||||
exports.getByResource = async (req, res) => {
|
||||
const [rows] = await pool.query(
|
||||
"SELECT * FROM resource_ips WHERE resource_id = ?",
|
||||
[req.params.id]
|
||||
);
|
||||
|
||||
res.json(rows);
|
||||
};
|
||||
|
||||
/* ADD IP */
|
||||
exports.create = async (req, res) => {
|
||||
const { ip, type, comment } = req.body;
|
||||
|
||||
await pool.query(
|
||||
"INSERT INTO resource_ips (resource_id, ip, type, comment) VALUES (?, ?, ?, ?)",
|
||||
[req.params.id, ip, type, comment]
|
||||
);
|
||||
|
||||
res.json({ message: "IP added" });
|
||||
};
|
||||
|
||||
/* DELETE IP */
|
||||
exports.remove = async (req, res) => {
|
||||
await pool.query(
|
||||
"DELETE FROM resource_ips WHERE id = ?",
|
||||
[req.params.id]
|
||||
);
|
||||
|
||||
res.json({ message: "IP deleted" });
|
||||
};
|
||||
Reference in New Issue
Block a user