Skip to content

Commit

Permalink
Merge pull request #1142 from Real-Dev-Squad/return-archived-role-fal…
Browse files Browse the repository at this point in the history
…se-user-only

Return un-archived user only
  • Loading branch information
RitikJaiswal75 authored Jun 7, 2023
2 parents 3e38daa + 2ff6e27 commit 0d28a20
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
10 changes: 9 additions & 1 deletion models/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,15 @@ const fetchPaginatedUsers = async (query) => {
// INFO: https://github.com/Real-Dev-Squad/website-backend/pull/873#discussion_r1064229932
const size = parseInt(query.size) || 100;
const doc = (query.next || query.prev) && (await userModel.doc(query.next || query.prev).get());
let dbQuery = (query.prev ? userModel.limitToLast(size) : userModel.limit(size)).orderBy("username");

let dbQuery = userModel.where("roles.archived", "==", false).orderBy("username");

if (query.prev) {
dbQuery = dbQuery.limitToLast(size);
} else {
dbQuery = dbQuery.limit(size);
}

if (Object.keys(query).length) {
if (query.search) {
dbQuery = dbQuery
Expand Down
20 changes: 20 additions & 0 deletions test/integration/users.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ describe("Users", function () {
return done();
});
});
it("Should get all the users with archived false", function (done) {
chai
.request(app)
.get("/users")
.end((err, res) => {
if (err) {
return done(err);
}

expect(res).to.have.status(200);
expect(res.body).to.be.a("object");
expect(res.body.message).to.equal("Users returned successfully!");
expect(res.body.users).to.be.a("array");
const userData = res.body.users;
userData.forEach((user) => {
expect(user.roles.archived).to.equal(false);
});
return done();
});
});

it("Should get all the users in system when query params are valid", function (done) {
chai
Expand Down

0 comments on commit 0d28a20

Please sign in to comment.