Skip to content

Commit

Permalink
Merge pull request #46 from chamathpali/dev
Browse files Browse the repository at this point in the history
Added further admin user operations
  • Loading branch information
chamathpali authored Feb 17, 2023
2 parents 2ab7caf + 202037f commit aa76b6c
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,69 @@ module.exports.admin_add_user = async (req, res) => {

}

module.exports.admin_all_usecases = async (req, res) => {
if (req.body.ISEE_ADMIN_KEY == process.env.ISEE_ADMIN_KEY) {
try {
const data = await Usecase.find({});
res.json(data)
}
catch (error) {
res.status(500).json({ message: error.message })
}
} else {
console.log("Unauth access");
res.status(400).json({ message: "unauth" })
}
}

module.exports.admin_change_usecase_ownership = async (req, res) => {
if (req.body.ISEE_ADMIN_KEY == process.env.ISEE_ADMIN_KEY) {
try {
const id = req.body.usecase;
const updatedData = { "company": req.body.company };
const options = { new: false };

const result = await Usecase.findByIdAndUpdate(id, updatedData, options);
if (result) {
res.send(result);
} else {
res.status(404).json({ message: "Usecase not found" });
}
} catch (error) {
console.log(error)
res.status(400).json({ message: error.message })
}
} else {
console.log("Unauth access");
res.status(400).json({ message: "unauth" })
}
}

module.exports.admin_change_user_company = async (req, res) => {
if (req.body.ISEE_ADMIN_KEY == process.env.ISEE_ADMIN_KEY) {
try {
const id = req.body.user;
const updatedData = { "company": req.body.company };
const options = { new: false };

const result = await User.findByIdAndUpdate(id, updatedData, options);
if (result) {
res.send(result);
} else {
res.status(404).json({ message: "User not found" });
}
} catch (error) {
console.log(error)
res.status(400).json({ message: error.message })
}
} else {
console.log("Unauth access");
res.status(400).json({ message: "unauth" })
}
}




module.exports.login = async (req, res) => {
try {
Expand Down
9 changes: 9 additions & 0 deletions src/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ router.post('/admin_companies', auth.admin_companies);
router.post('/admin_add_user', auth.admin_add_user);
router.post('/admin_all_users', auth.admin_all_users);

// List all users
router.post('/admin_all_usecases', auth.admin_all_usecases);

// Change Usecase ownership
router.post('/admin_change_usecase_ownership', auth.admin_change_usecase_ownership);

// Change User company
router.post('/admin_change_user_company', auth.admin_change_user_company);

module.exports = router;

0 comments on commit aa76b6c

Please sign in to comment.