From f1dab50dae12a650f3043d171c714050ab0ebaf1 Mon Sep 17 00:00:00 2001
From: grgml <grigormalo@gmail.com>
Date: Mon, 13 Jun 2022 16:37:26 +0200
Subject: [PATCH] feat(models): enable query users by their data

---
 src/models/user/user.controller.js | 4 ++--
 src/models/user/user.graphql       | 6 +++++-
 src/models/user/user.resolvers.js  | 4 ++--
 3 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/src/models/user/user.controller.js b/src/models/user/user.controller.js
index 37bb781..e64460c 100644
--- a/src/models/user/user.controller.js
+++ b/src/models/user/user.controller.js
@@ -83,7 +83,7 @@ const getUser = async (id, options = {}) => {
 
 const getDisplayName = async user => user.getDisplayName()
 
-const getUsers = async (options = {}) => {
+const getUsers = async (data = {}, options = {}) => {
   try {
     const { trx, ...restOptions } = options
     return useTransaction(
@@ -91,7 +91,7 @@ const getUsers = async (options = {}) => {
         logger.info(
           `${USER_CONTROLLER} getUsers: fetching all users based on provided options ${restOptions}`,
         )
-        return User.find({}, { trx: tr, ...restOptions })
+        return User.find(data, { trx: tr, ...restOptions })
       },
       { trx, passedTrxOnly: true },
     )
diff --git a/src/models/user/user.graphql b/src/models/user/user.graphql
index 1a9ba20..78b9a69 100644
--- a/src/models/user/user.graphql
+++ b/src/models/user/user.graphql
@@ -68,9 +68,13 @@ input UpdatePasswordInput {
   newPassword: String!
 }
 
+input UsersQueryOptions {
+  isActive: Boolean
+}
+
 extend type Query {
   user(id: ID): User
-  users(options: PageInput): Users!
+  users(data: UsersQueryOptions, options: PageInput): Users!
   currentUser: User!
 }
 
diff --git a/src/models/user/user.resolvers.js b/src/models/user/user.resolvers.js
index 8e0e282..27680f7 100644
--- a/src/models/user/user.resolvers.js
+++ b/src/models/user/user.resolvers.js
@@ -38,10 +38,10 @@ const userResolver = async (_, { id }, ctx) => {
   }
 }
 
-const usersResolver = async (_, { options }, ctx) => {
+const usersResolver = async (_, { data, options }, ctx) => {
   try {
     logger.error(`${USER_RESOLVER} users`)
-    return getUsers(options)
+    return getUsers(data, options)
   } catch (e) {
     logger.error(`${USER_RESOLVER} users: ${e.message}`)
     throw new Error(e)
-- 
GitLab