Made changes to the host details area to add notes

Reconfigured JWT session timeouts
This commit is contained in:
Muhammad Ibrahim
2025-10-01 08:38:40 +01:00
parent f254b54404
commit 5d8a1e71d6
13 changed files with 1004 additions and 299 deletions

View File

@@ -858,6 +858,7 @@ router.get(
auto_update: true,
created_at: true,
host_group_id: true,
notes: true,
host_groups: {
select: {
id: true,
@@ -1491,4 +1492,78 @@ router.patch(
},
);
// Update host notes (admin only)
router.patch(
"/:hostId/notes",
authenticateToken,
requireManageHosts,
[
body("notes")
.optional()
.isLength({ max: 1000 })
.withMessage("Notes must be less than 1000 characters"),
],
async (req, res) => {
try {
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() });
}
const { hostId } = req.params;
const { notes } = req.body;
// Check if host exists
const existingHost = await prisma.hosts.findUnique({
where: { id: hostId },
});
if (!existingHost) {
return res.status(404).json({ error: "Host not found" });
}
// Update the notes
const updatedHost = await prisma.hosts.update({
where: { id: hostId },
data: {
notes: notes || null,
updated_at: new Date(),
},
select: {
id: true,
friendly_name: true,
hostname: true,
ip: true,
os_type: true,
os_version: true,
architecture: true,
last_update: true,
status: true,
host_group_id: true,
agent_version: true,
auto_update: true,
created_at: true,
updated_at: true,
notes: true,
host_groups: {
select: {
id: true,
name: true,
color: true,
},
},
},
});
res.json({
message: "Notes updated successfully",
host: updatedHost,
});
} catch (error) {
console.error("Update notes error:", error);
res.status(500).json({ error: "Failed to update notes" });
}
},
);
module.exports = router;