1
1
import { IContext , IModels } from "../../../connectionResolver" ;
2
2
import {
3
3
checkPermission ,
4
- requireLogin
4
+ requireLogin ,
5
5
} from "@erxes/api-utils/src/permissions" ;
6
6
import { escapeRegExp , getConfig , paginate } from "../../utils" ;
7
7
@@ -84,7 +84,7 @@ export class Builder {
84
84
// filter by segment
85
85
if ( this . params . segment ) {
86
86
const segment = await this . models . Segments . findOne ( {
87
- _id : this . params . segment
87
+ _id : this . params . segment ,
88
88
} ) ;
89
89
90
90
await this . segmentFilter ( segment ) ;
@@ -96,9 +96,9 @@ export class Builder {
96
96
query : {
97
97
bool : {
98
98
must : this . positiveList ,
99
- must_not : this . negativeList
100
- }
101
- }
99
+ must_not : this . negativeList ,
100
+ } ,
101
+ } ,
102
102
} ;
103
103
104
104
let totalCount = 0 ;
@@ -108,7 +108,7 @@ export class Builder {
108
108
action : "count" ,
109
109
index : this . contentType ,
110
110
body : queryOptions ,
111
- defaultValue : 0
111
+ defaultValue : 0 ,
112
112
} ) ;
113
113
114
114
totalCount = totalCountResponse . count ;
@@ -117,19 +117,19 @@ export class Builder {
117
117
subdomain : this . subdomain ,
118
118
action,
119
119
index : this . contentType ,
120
- body : queryOptions
120
+ body : queryOptions ,
121
121
} ) ;
122
122
123
- const list = response . hits . hits . map ( hit => {
123
+ const list = response . hits . hits . map ( ( hit ) => {
124
124
return {
125
125
_id : hit . _id ,
126
- ...hit . _source
126
+ ...hit . _source ,
127
127
} ;
128
128
} ) ;
129
129
130
130
return {
131
131
list,
132
- totalCount
132
+ totalCount,
133
133
} ;
134
134
}
135
135
}
@@ -164,14 +164,14 @@ const getChildIds = async (model, ids) => {
164
164
const orderQry : any [ ] = [ ] ;
165
165
for ( const item of items ) {
166
166
orderQry . push ( {
167
- order : { $regex : new RegExp ( `^${ escapeRegExp ( item . order ) } ` ) }
167
+ order : { $regex : new RegExp ( `^${ escapeRegExp ( item . order ) } ` ) } ,
168
168
} ) ;
169
169
}
170
170
171
171
const allItems = await model . find ( {
172
- $or : orderQry
172
+ $or : orderQry ,
173
173
} ) ;
174
- return allItems . map ( i => i . _id ) ;
174
+ return allItems . map ( ( i ) => i . _id ) ;
175
175
} ;
176
176
177
177
const queryBuilder = async (
@@ -195,11 +195,11 @@ const queryBuilder = async (
195
195
departmentIds,
196
196
branchIds,
197
197
segment,
198
- segmentData
198
+ segmentData,
199
199
} = params ;
200
200
201
201
const selector : any = {
202
- isActive
202
+ isActive,
203
203
} ;
204
204
205
205
let andCondition : any [ ] = [ ] ;
@@ -210,7 +210,7 @@ const queryBuilder = async (
210
210
{ employeeId : new RegExp ( `.*${ params . searchValue } .*` , "i" ) } ,
211
211
{ username : new RegExp ( `.*${ params . searchValue } .*` , "i" ) } ,
212
212
{ "details.fullName" : new RegExp ( `.*${ params . searchValue } .*` , "i" ) } ,
213
- { "details.position" : new RegExp ( `.*${ params . searchValue } .*` , "i" ) }
213
+ { "details.position" : new RegExp ( `.*${ params . searchValue } .*` , "i" ) } ,
214
214
] ;
215
215
216
216
selector . $or = fields ;
@@ -281,7 +281,7 @@ const queryBuilder = async (
281
281
! branchUserIds . includes ( user . _id )
282
282
) {
283
283
customCond . push ( {
284
- branchIds : { $in : await getChildIds ( models . Branches , branchIds ) }
284
+ branchIds : { $in : await getChildIds ( models . Branches , branchIds ) } ,
285
285
} ) ;
286
286
}
287
287
@@ -292,27 +292,25 @@ const queryBuilder = async (
292
292
) {
293
293
customCond . push ( {
294
294
departmentIds : {
295
- $in : await getChildIds ( models . Departments , departmentIds )
296
- }
295
+ $in : await getChildIds ( models . Departments , departmentIds ) ,
296
+ } ,
297
297
} ) ;
298
298
}
299
299
300
300
andCondition = customCond . length ? [ { $or : customCond } ] : [ ] ;
301
301
}
302
- } else {
303
- if ( branchIds && branchIds . length ) {
304
- selector . branchIds = {
305
- $in : await getChildIds ( models . Branches , branchIds )
306
- } ;
307
- }
308
-
309
- if ( departmentIds && departmentIds . length ) {
310
- selector . departmentIds = {
311
- $in : await getChildIds ( models . Departments , departmentIds )
312
- } ;
313
- }
314
302
}
315
303
304
+ if ( branchIds && branchIds . length ) {
305
+ selector . branchIds = {
306
+ $in : await getChildIds ( models . Branches , branchIds ) ,
307
+ } ;
308
+ }
309
+ if ( departmentIds && departmentIds . length ) {
310
+ selector . departmentIds = {
311
+ $in : await getChildIds ( models . Departments , departmentIds ) ,
312
+ } ;
313
+ }
316
314
if ( unitId ) {
317
315
const unit = await models . Units . getUnit ( { _id : unitId } ) ;
318
316
@@ -330,7 +328,7 @@ const queryBuilder = async (
330
328
331
329
const { list } = await qb . runQueries ( ) ;
332
330
333
- selector . _id = { $in : list . map ( l => l . _id ) } ;
331
+ selector . _id = { $in : list . map ( ( l ) => l . _id ) } ;
334
332
}
335
333
336
334
if ( andCondition . length ) {
@@ -352,7 +350,7 @@ const userQueries = {
352
350
const selector = {
353
351
...userBrandIdsSelector ,
354
352
...( await queryBuilder ( models , args , subdomain , user ) ) ,
355
- ...NORMAL_USER_SELECTOR
353
+ ...NORMAL_USER_SELECTOR ,
356
354
} ;
357
355
358
356
const { sortField, sortDirection } = args ;
@@ -373,7 +371,7 @@ const userQueries = {
373
371
{
374
372
isActive,
375
373
ids,
376
- assignedToMe
374
+ assignedToMe,
377
375
} : { isActive : boolean ; ids : string [ ] ; assignedToMe : string } ,
378
376
{ userBrandIdsSelector, user, models } : IContext
379
377
) {
@@ -390,7 +388,7 @@ const userQueries = {
390
388
}
391
389
392
390
return models . Users . find ( { ...selector , ...NORMAL_USER_SELECTOR } ) . sort ( {
393
- username : 1
391
+ username : 1 ,
394
392
} ) ;
395
393
} ,
396
394
@@ -412,7 +410,7 @@ const userQueries = {
412
410
const selector = {
413
411
...userBrandIdsSelector ,
414
412
...( await queryBuilder ( models , args , subdomain , user ) ) ,
415
- ...NORMAL_USER_SELECTOR
413
+ ...NORMAL_USER_SELECTOR ,
416
414
} ;
417
415
418
416
return models . Users . find ( selector ) . countDocuments ( ) ;
@@ -438,7 +436,7 @@ const userQueries = {
438
436
*/
439
437
async userMovements ( _root , args , { models } : IContext ) {
440
438
return await models . UserMovements . find ( args ) . sort ( { createdAt : - 1 } ) ;
441
- }
439
+ } ,
442
440
} ;
443
441
444
442
requireLogin ( userQueries , "usersTotalCount" ) ;
0 commit comments