Update IP fixed
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
const pool = require("../db");
|
||||
const db = require("../db");
|
||||
|
||||
|
||||
/* LIST IPs for resource */
|
||||
exports.getByResource = async (req, res) => {
|
||||
@@ -31,3 +33,26 @@ exports.remove = async (req, res) => {
|
||||
|
||||
res.json({ message: "IP deleted" });
|
||||
};
|
||||
|
||||
|
||||
exports.update = async (req, res) => {
|
||||
|
||||
try{
|
||||
|
||||
const {ip, type, comment} = req.body;
|
||||
|
||||
await db.query(
|
||||
"UPDATE resource_ips SET ip=?, type=?, comment=? WHERE id=?",
|
||||
[ip, type, comment, req.params.id]
|
||||
);
|
||||
|
||||
res.json({success:true});
|
||||
|
||||
}catch(e){
|
||||
|
||||
console.error("UPDATE IP error:", e);
|
||||
res.status(500).json({error:"DB error"});
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@@ -63,7 +63,6 @@ window.loadResources = async function(){
|
||||
${ips}
|
||||
<br>
|
||||
<button type="button" onclick="openIPManager(${r.id})">IPs</button>
|
||||
<button onclick="openIPManager(${r.id})">IPs</button>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
|
||||
+1
-17
@@ -11,27 +11,11 @@ router.post("/resources/:id/ips", controller.create);
|
||||
/* delete IP */
|
||||
router.delete("/ips/:id", controller.remove);
|
||||
|
||||
router.put("/ips/:id", async (req, res) => {
|
||||
|
||||
try{
|
||||
router.put("/ips/:id", controller.update);
|
||||
|
||||
const {ip, type, comment} = req.body
|
||||
|
||||
await db.query(
|
||||
"UPDATE resource_ips SET ip=?, type=?, comment=? WHERE id=?",
|
||||
[ip, type, comment, req.params.id]
|
||||
)
|
||||
|
||||
res.json({success:true})
|
||||
|
||||
}catch(e){
|
||||
|
||||
console.error("UPDATE IP error:", e)
|
||||
res.status(500).json({error:"DB error"})
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user