1
1
import { FieldResolveInput } from 'stucco-js' ;
2
2
import { resolverFor } from '../zeus/index.js' ;
3
3
import { convertDateObjToStringForArray , errMiddleware , sourceContainUserIdOrThrow } from '../utils/middleware.js' ;
4
- import { MongoOrb , preparePageOptions } from '../utils/db/orm.js' ;
4
+ import { MongoOrb , inputServiceFiltersSet , preparePageOptions } from '../utils/db/orm.js' ;
5
5
import { ServicesCollection } from '../utils/db/collections.js' ;
6
6
import { isScalarDate } from '../PublicQuery/listServices.js' ;
7
7
import { ServiceModel } from '../models/ServiceModel.js' ;
@@ -12,25 +12,12 @@ export const getSelfServices = async (input: FieldResolveInput) =>
12
12
errMiddleware ( async ( ) => {
13
13
sourceContainUserIdOrThrow ( src ) ;
14
14
const po = preparePageOptions ( args ?. input ?. page ) ;
15
- const pa =
16
- args ?. input ?. filters &&
17
- Object . fromEntries ( Object . entries ( args ?. input ?. filters ) . filter ( ( v ) => v !== null && v !== undefined && v [ 0 ] !== 'fromDate' && v [ 0 ] !== 'toDate' ) ) ;
18
- const fromDate = isScalarDate ( args ?. input ?. filters ?. fromDate )
19
- ? isScalarDate ( args ?. input ?. filters ?. fromDate )
20
- : undefined ;
21
-
22
- const toDate = isScalarDate ( args ?. input ?. filters ?. toDate )
23
- ? isScalarDate ( args ?. input ?. filters ?. toDate )
24
- : undefined ;
15
+
16
+ const inputFilters = inputServiceFiltersSet ( args . input ?. filters )
17
+
25
18
const selfServices = await MongoOrb ( ServicesCollection )
26
19
. collection . find ( {
27
- ...pa ,
28
- ...( fromDate && { startDate : { $gte : new Date ( args ?. input ?. filters ?. fromDate as string ) } } ) ,
29
- ...( toDate && { startDate : { $lte : new Date ( args ?. input ?. filters ?. toDate as string ) } } ) ,
30
- ...( args ?. input ?. filters ?. name && { name : { $regex : args ?. input . filters . name , $options : 'i' } } ) ,
31
- ...( args ?. input ?. filters ?. description && {
32
- description : { $regex : args ?. input . filters . description , $options : 'i' } ,
33
- } ) ,
20
+ ...inputFilters ,
34
21
ownerId : src . userId || src . _id ,
35
22
} )
36
23
. limit ( po . limit )
@@ -41,3 +28,6 @@ export const getSelfServices = async (input: FieldResolveInput) =>
41
28
} ) ,
42
29
) ( input . arguments , input . source ) ;
43
30
export default getSelfServices ;
31
+
32
+
33
+
0 commit comments