Skip to content

Commit

Permalink
Remove /countAllUsers endpoint (#1595)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanugarte authored Feb 24, 2025
1 parent bd40160 commit 52e5beb
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 79 deletions.
32 changes: 0 additions & 32 deletions api/main_endpoints/routes/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,38 +32,6 @@ const crypto = require('crypto');

const ROWS_PER_PAGE = 20;

router.get('/countAllUsers', async (req, res) => {
if (!checkIfTokenSent(req)) {
return res.sendStatus(FORBIDDEN);
} else if (!checkIfTokenValid(req, (
membershipState.OFFICER
))) {
return res.sendStatus(UNAUTHORIZED);
}
const search = req.query.search;
let status = OK;
const count = await User.find({
$or:
[
{ 'firstName': { '$regex': search, '$options': 'i' } },
{ 'lastName': { '$regex': search, '$options': 'i' } },
{ 'email': { '$regex': search, '$options': 'i' } }
]
}, function(error, result) {
if (error) {
status = BAD_REQUEST;
} else if (result == 0) {
status = NOT_FOUND;
}
}).countDocuments();
const response = {
count
};
res.status(status).json(response);
});


// Delete a member
// Delete a member
router.post('/delete', async (req, res) => {
if (!checkIfTokenSent(req)) {
Expand Down
14 changes: 0 additions & 14 deletions src/APIFunctions/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,6 @@ export async function getAllUsers({
return status;
}

export async function getCountAllUsers(query) {
let status = new UserApiResponse();
const url = new URL(`/api/User/countAllUsers/${query}`, BASE_API_URL);
await axios
.get(url.href)
.then(result => {
status.responseData = result.data;
})
.catch(() => {
status.error = true;
});
return status;
}

/**
* Edit an existing users
* @param {Object} userToEdit - The user that is to be updated
Expand Down
33 changes: 0 additions & 33 deletions test/api/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,39 +265,6 @@ describe('User', () => {
});
});

describe('/GET countAllUsers', () => {
it('Should return statusCode 200 if count >= 1', async () => {
setTokenStatus(true);
const query = '?search=a';
const result = await test.sendGetRequestWithToken(
token, `/api/User/countAllUsers${query}`);
expect(result).to.have.status(OK);
result.body.count.should.be.greaterThanOrEqual(1);
});
it('Should return statusCode 404 if count == 0', async () => {
setTokenStatus(true);
const query = '?search=ab%cd%de';
const result = await test.sendGetRequestWithToken(
token, `/api/User/countAllUsers${query}`);
expect(result).to.have.status(NOT_FOUND);
result.body.count.should.be.equal(0);
});
it('Should return statusCode 403 if no token is passed in', async () => {
const query = '?search=a';
const result = await test.sendGetRequest(
`/api/User/countAllUsers${query}`);
expect(result).to.have.status(FORBIDDEN);
});
it('Should return statusCode 401 if an invalid ' +
'token was passed in', async () => {
setTokenStatus(false);
const query = '?search=a';
const result = await test.sendGetRequestWithToken(
token, `/api/User/countAllUsers${query}`);
expect(result).to.have.status(UNAUTHORIZED);
});
});

describe('/POST delete', () => {
let userAdmin;

Expand Down

0 comments on commit 52e5beb

Please sign in to comment.