Scaffoled Users Management Screen

This commit is contained in:
2024-07-27 02:04:26 +08:00
parent 4f806b56f6
commit a6a2c5834f
4 changed files with 296 additions and 2 deletions

View File

@@ -79,6 +79,7 @@ router.get("/all", async (req, res) => {
let list = await User.findAll({
where: condition,
order: [["createdAt", "DESC"]],
attributes: { exclude: ["password", "profilePicture"] },
});
res.json(list);
});
@@ -97,6 +98,8 @@ router.get("/individual/:id", validateToken, async (req, res) => {
message: `ERR_ACC_IS_ARCHIVED`,
});
} else {
user.password = undefined;
user.profilePicture = undefined;
res.json(user);
}
});
@@ -223,6 +226,30 @@ router.put("/archive/:id", validateToken, async (req, res) => {
}
});
router.put("/unarchive/:id", validateToken, async (req, res) => {
let id = req.params.id;
let user = await User.findByPk(id);
if (!user) {
res.sendStatus(404);
return;
}
try {
await User.update(
{ isArchived: false },
{
where: { id: id },
}
);
res.json({
message: "User archived successfully.",
});
} catch (err) {
res.status(400).json({ errors: err.errors });
}
});
router.get("/profile-image/:id", async (req, res) => {
let id = req.params.id;
let user = await User.findByPk(id);