@@ -75,71 +75,6 @@ function deepMerge(target: Record<string, any>, source: Record<string, any>) {
75
75
}
76
76
}
77
77
78
- function parseStringToObject ( path : string , value : any ) {
79
- const keys = path . split ( '.' ) ;
80
- const currentObj = { } ;
81
- let temp = currentObj ;
82
-
83
- keys . forEach ( ( key , index ) => {
84
- if ( index === keys . length - 1 ) {
85
- temp [ key ] = value ;
86
- } else {
87
- temp [ key ] = { } ;
88
- temp = temp [ key ] ;
89
- }
90
- } ) ;
91
-
92
- return currentObj ;
93
- }
94
-
95
- function getSearchWhere ( search : string , or ?: boolean ) {
96
- const where = { } ;
97
- if ( search !== '' ) {
98
- const terms = search . split ( ',' ) ;
99
- const groups : Record < string , { condition : string ; mode ?: string } [ ] > =
100
- terms . reduce ( ( prev , current ) => {
101
- const [ key , condition , value ] = current . split ( ':' ) ;
102
- const isBoolean = [ 'true' , 'false' ] . includes ( value ) ;
103
- const mode =
104
- isBoolean || [ 'in' , 'notIn' ] . includes ( condition )
105
- ? undefined
106
- : 'insensitive' ;
107
- const parsedValue = isBoolean ? value === 'true' : value ;
108
-
109
- return {
110
- ...prev ,
111
- [ key ] : [
112
- ...( prev [ key ] ?? [ ] ) ,
113
- {
114
- [ condition ] : [ 'in' , 'notIn' ] . includes ( condition )
115
- ? [ parsedValue ]
116
- : parsedValue ,
117
- mode,
118
- } ,
119
- ] ,
120
- } ;
121
- } , { } ) ;
122
-
123
- const parsed = Object . entries ( groups ) . reduce ( ( prev , [ key , current ] ) => {
124
- if ( current . length > 1 ) {
125
- return {
126
- ...prev ,
127
- AND : current . map ( ( c ) => parseStringToObject ( key , c ) ) ,
128
- } ;
129
- } else return deepMerge ( prev , parseStringToObject ( key , current [ 0 ] ) ) ;
130
- } , { } ) ;
131
- Object . assign ( where , parsed ) ;
132
- }
133
- if ( or ) {
134
- return {
135
- OR : Object . entries ( where ) . reduce (
136
- ( prev , [ key , value ] ) => [ ...prev , { [ key ] : value } ] ,
137
- [ ] as any [ ] ,
138
- ) ,
139
- } ;
140
- } else return where ;
141
- }
142
-
143
78
function addHours ( date : Date , hours : number ) {
144
79
const result = new Date ( ) ;
145
80
result . setTime ( date . getTime ( ) + hours * 60 * 60 * 1000 ) ;
0 commit comments