1
1
import { Prisma } from '@prisma/client' ;
2
+
2
3
import { IFilterFormProps } from './types' ;
4
+ import { PrismaService } from '../prisma/prisma.service' ;
3
5
4
6
class ShelterSearch {
5
7
private data : IFilterFormProps ;
8
+ private prismaService : PrismaService ;
6
9
7
- constructor ( props : IFilterFormProps ) {
10
+ constructor ( prismaService : PrismaService , props : IFilterFormProps ) {
8
11
this . data = props ;
12
+ this . prismaService = prismaService ;
9
13
}
10
14
11
15
get priority ( ) : Prisma . ShelterWhereInput [ ] {
@@ -31,16 +35,83 @@ class ShelterSearch {
31
35
return {
32
36
capacity : null ,
33
37
} ;
34
- else if ( status === 'available' ) return { } ;
38
+ else if ( status === 'available' )
39
+ return {
40
+ capacity : {
41
+ gt : this . prismaService . shelter . fields . shelteredPeople ,
42
+ } ,
43
+ } ;
35
44
else
36
45
return {
37
- // capacity: {
38
- // lte: Prisma.ShelterScalarFieldEnum .shelteredPeople,
39
- // },
46
+ capacity : {
47
+ lte : this . prismaService . shelter . fields . shelteredPeople ,
48
+ } ,
40
49
} ;
41
50
} ) ;
42
51
}
43
52
}
53
+
54
+ get supplyCategoryIds ( ) : Prisma . ShelterWhereInput {
55
+ if ( ! this . data . supplyCategoryIds ) return { } ;
56
+ return {
57
+ shelterSupplies : {
58
+ some : {
59
+ supply : {
60
+ supplyCategoryId : {
61
+ in : this . data . supplyCategoryIds ,
62
+ } ,
63
+ } ,
64
+ } ,
65
+ } ,
66
+ } ;
67
+ }
68
+
69
+ get supplyIds ( ) : Prisma . ShelterWhereInput {
70
+ if ( ! this . data . supplyIds ) return { } ;
71
+ return {
72
+ shelterSupplies : {
73
+ some : {
74
+ supply : {
75
+ id : {
76
+ in : this . data . supplyIds ,
77
+ } ,
78
+ } ,
79
+ } ,
80
+ } ,
81
+ } ;
82
+ }
83
+
84
+ get search ( ) : Prisma . ShelterWhereInput [ ] {
85
+ if ( ! this . data . search ) return [ ] ;
86
+ else
87
+ return [
88
+ {
89
+ address : {
90
+ contains : this . data . search ,
91
+ mode : 'insensitive' ,
92
+ } ,
93
+ } ,
94
+ {
95
+ name : {
96
+ contains : this . data . search ,
97
+ mode : 'insensitive' ,
98
+ } ,
99
+ } ,
100
+ ] ;
101
+ }
102
+
103
+ get query ( ) : Prisma . ShelterWhereInput {
104
+ if ( Object . keys ( this . data ) . length === 0 ) return { } ;
105
+ return {
106
+ OR : [
107
+ ...this . search ,
108
+ ...this . shelterStatus ,
109
+ this . supplyCategoryIds ,
110
+ this . supplyIds ,
111
+ ...this . search ,
112
+ ] ,
113
+ } ;
114
+ }
44
115
}
45
116
46
117
export { ShelterSearch } ;
0 commit comments