File tree Expand file tree Collapse file tree 2 files changed +30
-10
lines changed Expand file tree Collapse file tree 2 files changed +30
-10
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,8 @@ const fetchPaginatedUsers = async (query) => {
143
143
const size = parseInt ( query . size ) || 100 ;
144
144
const doc = ( query . next || query . prev ) && ( await userModel . doc ( query . next || query . prev ) . get ( ) ) ;
145
145
let dbQuery = ( query . prev ? userModel . limitToLast ( size ) : userModel . limit ( size ) ) . orderBy ( "username" ) ;
146
+ dbQuery = dbQuery . where ( "roles.archived" , "==" , false ) ;
147
+
146
148
if ( Object . keys ( query ) . length ) {
147
149
if ( query . search ) {
148
150
dbQuery = dbQuery
@@ -166,16 +168,14 @@ const fetchPaginatedUsers = async (query) => {
166
168
167
169
snapshot . forEach ( ( doc ) => {
168
170
const userData = doc . data ( ) ;
169
- if ( ! userData . roles . archived ) {
170
- allUsers . push ( {
171
- id : doc . id ,
172
- ...doc . data ( ) ,
173
- phone : undefined ,
174
- email : undefined ,
175
- tokens : undefined ,
176
- chaincode : undefined ,
177
- } ) ;
178
- }
171
+ allUsers . push ( {
172
+ id : doc . id ,
173
+ ...userData ,
174
+ phone : undefined ,
175
+ email : undefined ,
176
+ tokens : undefined ,
177
+ chaincode : undefined ,
178
+ } ) ;
179
179
} ) ;
180
180
return {
181
181
allUsers,
Original file line number Diff line number Diff line change @@ -139,6 +139,26 @@ describe("Users", function () {
139
139
return done ( ) ;
140
140
} ) ;
141
141
} ) ;
142
+ it ( "Should get all the users with archived false" , function ( done ) {
143
+ chai
144
+ . request ( app )
145
+ . get ( "/users" )
146
+ . end ( ( err , res ) => {
147
+ if ( err ) {
148
+ return done ( err ) ;
149
+ }
150
+
151
+ expect ( res ) . to . have . status ( 200 ) ;
152
+ expect ( res . body ) . to . be . a ( "object" ) ;
153
+ expect ( res . body . message ) . to . equal ( "Users returned successfully!" ) ;
154
+ expect ( res . body . users ) . to . be . a ( "array" ) ;
155
+ const userData = res . body . users ;
156
+ userData . forEach ( ( user ) => {
157
+ expect ( user . roles . archived ) . to . equal ( false ) ;
158
+ } ) ;
159
+ return done ( ) ;
160
+ } ) ;
161
+ } ) ;
142
162
143
163
it ( "Should get all the users in system when query params are valid" , function ( done ) {
144
164
chai
You can’t perform that action at this time.
0 commit comments