Skip to content

Commit 07c0bb0

Browse files
committed
feat: search in_discord and verified
1 parent 23e594c commit 07c0bb0

File tree

2 files changed

+26
-38
lines changed

2 files changed

+26
-38
lines changed

middlewares/validators/user.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,7 @@ async function validateUserQueryParams(req, res, next) {
172172
joi.array().items(joi.string().valid("IDLE", "OOO", "ACTIVE"))
173173
)
174174
.optional(),
175-
role: joi
176-
.alternatives()
177-
.try(joi.string().valid("in_discord", "member"), joi.array().items(joi.string().valid("in_discord", "member")))
178-
.optional(),
175+
role: joi.string().valid("in_discord", "member").optional(),
179176
verified: joi.string().optional(),
180177
})
181178
.messages({

models/users.js

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,8 @@ const getRdsUserInfoByGitHubUsername = async (githubUsername) => {
360360
* @param {Array} query.levelNumber - Array of levelNumbers to filter the users on
361361
* @param {Array} query.tagId - Array of tagIds to filter the users on
362362
* @param {Array} query.state - Array of states to filter the users on
363+
* @param {String} query.role - filter the users on
364+
* @param {String} query.verified - filter the users on
363365
* @return {Promise<Array>} - Array of user documents that match the filter criteria
364366
*/
365367

@@ -429,46 +431,35 @@ const fetchUsersWithRole = async (role) => {
429431
const snapshot = await userModel.where(`roles.${role}`, "==", true).get();
430432
const onlyMembers = [];
431433

432-
if (!snapshot.empty) {
433-
snapshot.forEach((doc) => {
434-
onlyMembers.push({
435-
id: doc.id,
436-
...doc.data(),
437-
phone: undefined,
438-
email: undefined,
439-
tokens: undefined,
440-
});
434+
const roleQuery = query.role;
435+
const verifiedQuery = query.verified;
436+
437+
if (roleQuery) {
438+
const filteredUsers = [];
439+
const snapshot = await userModel.where(`roles.${roleQuery}`, "==", true).get();
440+
snapshot.forEach((doc) => {
441+
filteredUsers.push({
442+
id: doc.id,
443+
...doc.data(),
441444
});
442-
}
445+
});
443446

444-
return onlyMembers;
445-
} catch (err) {
446-
logger.error("Error retrieving users data with roles of inDiscord", err);
447-
throw err;
447+
return filteredUsers;
448448
}
449-
};
450-
const fetchUsersWhereFieldNotNull = async (field) => {
451-
try {
452-
const snapshot = await userModel.where(field, "!=", null).get();
453-
const users = [];
454-
455-
if (!snapshot.empty) {
456-
snapshot.forEach((doc) => {
457-
users.push({
458-
id: doc.id,
459-
...doc.data(),
460-
phone: undefined,
461-
email: undefined,
462-
tokens: undefined,
463-
});
449+
if (verifiedQuery) {
450+
console.log(typeof verifiedQuery);
451+
const filteredUsers = [];
452+
const snapshot = await userModel.orderBy("discordId").get();
453+
snapshot.forEach((doc) => {
454+
filteredUsers.push({
455+
id: doc.id,
456+
...doc.data(),
464457
});
465-
}
458+
});
466459

467-
return users;
468-
} catch (err) {
469-
logger.error("Error retrieving users data with roles of inDiscord", err);
470-
throw err;
460+
return filteredUsers;
471461
}
462+
return [];
472463
};
473464

474465
module.exports = {

0 commit comments

Comments
 (0)