Skip to content

Commit

Permalink
update user endpoint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinovpankaj committed Nov 6, 2024
1 parent 8127ef0 commit 47f9d0c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 33 deletions.
2 changes: 1 addition & 1 deletion model/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ var updateUser = async function (user, callback) {
};

var getAllUser = async function (callback) {
var result = await mongo.Users.find({}).limit(50).toArray();
var result = await mongo.Users.find({}).limit(500).toArray();
if (result === null) {
var error = new Error(
"getAllUser(). \nMessage: No Users Found. All Requested."
Expand Down
73 changes: 41 additions & 32 deletions routes/user-endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,39 +288,48 @@ router.route("/update").post(async function (req, res) {
const companyIdentifier = req.user.company;
//check if the count is exceeding the limit
var tenant = Tenants.getTenantByCompanyIdentifier(companyIdentifier);
var users = result.users.filter(
(user) =>
user.companyIdentifier && user.companyIdentifier === companyIdentifier
);
//res.status(result.status).json(result.users);
switch (access_type) {
case "both":
if (tenant.bothUserCount < users.filter((user) => user.bothUserCount)) {
res
.status(409)
.send("Cannot update, limit reached. Please contact system admin");
return;
}
break;
case "mobile":
if (
tenant.mobileUserCount < users.filter((user) => user.mobileUserCount)
) {
res
.status(409)
.send("Cannot update, limit reached. Please contact system admin");
return;
}
break;
case "web":
if (tenant.webUserCount < users.filter((user) => user.webUserCount)) {
res
.status(409)
.send("Cannot update, limit reached. Please contact system admin");
return;

users.getAllUser(function (err, result) {
if (err) {
res.status(err.status).send(err.message);
} else {
// console.debug(result);
var users = result.users.filter(
(user) => user.companyIdentifier === companyIdentifier
);
switch (access_type) {
case "both":
if (tenant.bothUserCount < users.filter((user) => user.bothUserCount)) {
res
.status(409)
.send("Cannot update, limit reached. Please contact system admin");
return;
}
break;
case "mobile":
if (
tenant.mobileUserCount < users.filter((user) => user.mobileUserCount)
) {
res
.status(409)
.send("Cannot update, limit reached. Please contact system admin");
return;
}
break;
case "web":
if (tenant.webUserCount < users.filter((user) => user.webUserCount)) {
res
.status(409)
.send("Cannot update, limit reached. Please contact system admin");
return;
}
break;
}
break;
}
}
});



if ("password" in user)
user.password = await bcrypt.hash(user.password, 10);
users.updateUser(user, function (err, result) {
Expand Down

0 comments on commit 47f9d0c

Please sign in to comment.