File tree 3 files changed +21
-7
lines changed 3 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -31,12 +31,14 @@ class ShelterSearch {
31
31
}
32
32
33
33
priority ( supplyIds : string [ ] = [ ] ) : Prisma . ShelterWhereInput {
34
- if ( ! this . formProps . priority ) return { } ;
34
+ if ( ! this . formProps . priority ?. length ) return { } ;
35
35
36
36
return {
37
37
shelterSupplies : {
38
38
some : {
39
- priority : + this . formProps . priority ,
39
+ priority : {
40
+ in : this . formProps . priority ,
41
+ } ,
40
42
supplyId :
41
43
supplyIds . length > 0
42
44
? {
@@ -71,13 +73,18 @@ class ShelterSearch {
71
73
}
72
74
73
75
supplyCategoryIds (
74
- priority ?: SupplyPriority | null ,
76
+ priority ?: SupplyPriority [ ] | null ,
75
77
) : Prisma . ShelterWhereInput {
76
78
if ( ! this . formProps . supplyCategoryIds ) return { } ;
79
+
80
+ const inPriority : Prisma . IntFilter < 'ShelterSupply' > = {
81
+ in : priority ?. length ? priority : [ ] ,
82
+ } ;
83
+
77
84
return {
78
85
shelterSupplies : {
79
86
some : {
80
- priority : priority ? + priority : undefined ,
87
+ priority : priority ?. length ? inPriority : undefined ,
81
88
supply : {
82
89
supplyCategoryId : {
83
90
in : this . formProps . supplyCategoryIds ,
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ import * as qs from 'qs';
6
6
import { z } from 'zod' ;
7
7
8
8
import { PrismaService } from '../prisma/prisma.service' ;
9
- import { SupplyPriority } from '.. /supply/types' ;
9
+ import { SupplyPriority } from 'src /supply/types' ;
10
10
import { SearchSchema } from '../types' ;
11
11
import { ShelterSearch , parseTagResponse } from './ShelterSearch' ;
12
12
import { ShelterSearchPropsSchema } from './types/search.types' ;
@@ -127,6 +127,7 @@ export class ShelterService implements OnModuleInit {
127
127
search : searchQuery ,
128
128
} = SearchSchema . parse ( query ) ;
129
129
const queryData = ShelterSearchPropsSchema . parse ( qs . parse ( searchQuery ) ) ;
130
+
130
131
const { getQuery } = new ShelterSearch ( this . prismaService , queryData ) ;
131
132
const where = await getQuery ( ) ;
132
133
Original file line number Diff line number Diff line change @@ -32,8 +32,14 @@ export type GeolocationFilter = z.infer<typeof GeolocationFilterSchema>;
32
32
export const ShelterSearchPropsSchema = z . object ( {
33
33
search : z . string ( ) . optional ( ) ,
34
34
priority : z . preprocess (
35
- ( value ) => Number ( value ) || undefined ,
36
- z . nativeEnum ( SupplyPriority ) . optional ( ) ,
35
+ ( value ) =>
36
+ typeof value === 'string'
37
+ ? value
38
+ . split ( ',' )
39
+ . map ( ( v ) => Number ( v ) )
40
+ . filter ( ( v ) => ! isNaN ( v ) )
41
+ : [ ] ,
42
+ z . array ( z . nativeEnum ( SupplyPriority ) ) . optional ( ) ,
37
43
) ,
38
44
supplyCategoryIds : z . array ( z . string ( ) ) . optional ( ) ,
39
45
supplyIds : z . array ( z . string ( ) ) . optional ( ) ,
You can’t perform that action at this time.
0 commit comments