@mixd-id/web-scaffold 0.1.230406316 → 0.1.230406317
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/utils/preset-selector.js +339 -0
package/package.json
CHANGED
|
@@ -4,6 +4,345 @@ const {Op, literal, fn, col, where, DataTypes} = require("sequelize");
|
|
|
4
4
|
const {ftWildcard} = require("./helpers");
|
|
5
5
|
const util = require("util");
|
|
6
6
|
|
|
7
|
+
const getValue = (filter, opt) => {
|
|
8
|
+
|
|
9
|
+
const { columns, withoutKey = false } = opt
|
|
10
|
+
const { key, operator } = filter
|
|
11
|
+
const keyColumns = groupBy(columns, 'key')
|
|
12
|
+
const type = ((keyColumns[key] ?? [])[0] ?? {}).type
|
|
13
|
+
|
|
14
|
+
let whereObj = {}
|
|
15
|
+
|
|
16
|
+
switch(type){
|
|
17
|
+
|
|
18
|
+
case 'boolean':
|
|
19
|
+
withoutKey ? whereObj = { [Op.eq]:filter.value } : whereObj[key] = filter.value
|
|
20
|
+
break
|
|
21
|
+
|
|
22
|
+
case 'number':
|
|
23
|
+
switch(operator) {
|
|
24
|
+
case '=':
|
|
25
|
+
withoutKey ? whereObj = { [Op.eq]:filter.value } : whereObj[key] = filter.value
|
|
26
|
+
break
|
|
27
|
+
|
|
28
|
+
case '>':
|
|
29
|
+
case '>=':
|
|
30
|
+
case '<':
|
|
31
|
+
case '<=':
|
|
32
|
+
withoutKey ?
|
|
33
|
+
whereObj = { [Op[operator]]:filter.value } :
|
|
34
|
+
whereObj[key] = {
|
|
35
|
+
[Op[operator]]: filter.value
|
|
36
|
+
}
|
|
37
|
+
break
|
|
38
|
+
|
|
39
|
+
case 'in':
|
|
40
|
+
withoutKey ?
|
|
41
|
+
whereObj = { [Op.in]: filter.value.split(',')
|
|
42
|
+
.map(_ => parseInt(_))
|
|
43
|
+
.filter(_ => !isNaN(_)) } :
|
|
44
|
+
whereObj[key] = {
|
|
45
|
+
[Op.in]: filter.value.split(',')
|
|
46
|
+
.map(_ => parseInt(_))
|
|
47
|
+
.filter(_ => !isNaN(_))
|
|
48
|
+
}
|
|
49
|
+
break
|
|
50
|
+
|
|
51
|
+
case 'notIn':
|
|
52
|
+
withoutKey ?
|
|
53
|
+
whereObj = { [Op.notIn]: filter.value.split(',')
|
|
54
|
+
.map(_ => parseInt(_))
|
|
55
|
+
.filter(_ => !isNaN(_)) } :
|
|
56
|
+
whereObj[key] = {
|
|
57
|
+
[Op.notIn]: filter.value.split(',')
|
|
58
|
+
.map(_ => parseInt(_))
|
|
59
|
+
.filter(_ => !isNaN(_))
|
|
60
|
+
}
|
|
61
|
+
break
|
|
62
|
+
}
|
|
63
|
+
break
|
|
64
|
+
|
|
65
|
+
case 'date':
|
|
66
|
+
switch(operator) {
|
|
67
|
+
|
|
68
|
+
case 'thisWeek':
|
|
69
|
+
withoutKey ?
|
|
70
|
+
whereObj = {
|
|
71
|
+
[Op.between]: [
|
|
72
|
+
dayjs().startOf('week').format('YYYY-MM-DD 00:00:00'),
|
|
73
|
+
dayjs().endOf('week').format('YYYY-MM-DD 23:59:59'),
|
|
74
|
+
]
|
|
75
|
+
} :
|
|
76
|
+
whereObj[key] = {
|
|
77
|
+
[Op.between]: [
|
|
78
|
+
dayjs().startOf('week').format('YYYY-MM-DD 00:00:00'),
|
|
79
|
+
dayjs().endOf('week').format('YYYY-MM-DD 23:59:59'),
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
break
|
|
83
|
+
|
|
84
|
+
case 'thisMonth':
|
|
85
|
+
withoutKey ?
|
|
86
|
+
whereObj = {
|
|
87
|
+
[Op.between]: [
|
|
88
|
+
dayjs().startOf('month').format('YYYY-MM-DD 00:00:00'),
|
|
89
|
+
dayjs().endOf('month').format('YYYY-MM-DD 23:59:59'),
|
|
90
|
+
]
|
|
91
|
+
} :
|
|
92
|
+
whereObj[key] = {
|
|
93
|
+
[Op.between]: [
|
|
94
|
+
dayjs().startOf('month').format('YYYY-MM-DD 00:00:00'),
|
|
95
|
+
dayjs().endOf('month').format('YYYY-MM-DD 23:59:59'),
|
|
96
|
+
]
|
|
97
|
+
}
|
|
98
|
+
break
|
|
99
|
+
|
|
100
|
+
case 'thisYear':
|
|
101
|
+
withoutKey ?
|
|
102
|
+
whereObj = {
|
|
103
|
+
[Op.between]: [
|
|
104
|
+
dayjs().startOf('year').format('YYYY-MM-DD 00:00:00'),
|
|
105
|
+
dayjs().endOf('year').format('YYYY-MM-DD 23:59:59'),
|
|
106
|
+
]
|
|
107
|
+
} :
|
|
108
|
+
whereObj[key] = {
|
|
109
|
+
[Op.between]: [
|
|
110
|
+
dayjs().startOf('year').format('YYYY-MM-DD 00:00:00'),
|
|
111
|
+
dayjs().endOf('year').format('YYYY-MM-DD 23:59:59'),
|
|
112
|
+
]
|
|
113
|
+
}
|
|
114
|
+
break
|
|
115
|
+
|
|
116
|
+
case 'between':
|
|
117
|
+
withoutKey ?
|
|
118
|
+
whereObj = {
|
|
119
|
+
[Op.between]: [
|
|
120
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
121
|
+
dayjs(filter.value2).format('YYYY-MM-DD 23:59:59'),
|
|
122
|
+
]
|
|
123
|
+
} :
|
|
124
|
+
whereObj[key] = {
|
|
125
|
+
[Op.between]: [
|
|
126
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
127
|
+
dayjs(filter.value2).format('YYYY-MM-DD 23:59:59'),
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
break
|
|
131
|
+
|
|
132
|
+
case 'yesterday':
|
|
133
|
+
withoutKey ?
|
|
134
|
+
whereObj = {
|
|
135
|
+
[Op.between]: [
|
|
136
|
+
dayjs().subtract(1, 'day').startOf('day').format('YYYY-MM-DD 00:00:00'),
|
|
137
|
+
dayjs().subtract(1, 'day').endOf('day').format('YYYY-MM-DD 23:59:59'),
|
|
138
|
+
]
|
|
139
|
+
} :
|
|
140
|
+
whereObj[key] = {
|
|
141
|
+
[Op.between]: [
|
|
142
|
+
dayjs().subtract(1, 'day').startOf('day').format('YYYY-MM-DD 00:00:00'),
|
|
143
|
+
dayjs().subtract(1, 'day').endOf('day').format('YYYY-MM-DD 23:59:59'),
|
|
144
|
+
]
|
|
145
|
+
}
|
|
146
|
+
break
|
|
147
|
+
|
|
148
|
+
case 'today':
|
|
149
|
+
withoutKey ?
|
|
150
|
+
whereObj = {
|
|
151
|
+
[Op.between]: [
|
|
152
|
+
dayjs().startOf('day').format('YYYY-MM-DD 00:00:00'),
|
|
153
|
+
dayjs().endOf('day').format('YYYY-MM-DD 23:59:59'),
|
|
154
|
+
]
|
|
155
|
+
} :
|
|
156
|
+
whereObj[key] = {
|
|
157
|
+
[Op.between]: [
|
|
158
|
+
dayjs().startOf('day').format('YYYY-MM-DD 00:00:00'),
|
|
159
|
+
dayjs().endOf('day').format('YYYY-MM-DD 23:59:59'),
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
break
|
|
163
|
+
|
|
164
|
+
case '<':
|
|
165
|
+
withoutKey ?
|
|
166
|
+
whereObj = {
|
|
167
|
+
[Op.lt]: [
|
|
168
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
169
|
+
]
|
|
170
|
+
} :
|
|
171
|
+
whereObj[key] = {
|
|
172
|
+
[Op.lt]: [
|
|
173
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
174
|
+
]
|
|
175
|
+
}
|
|
176
|
+
break
|
|
177
|
+
|
|
178
|
+
case '<=':
|
|
179
|
+
withoutKey ?
|
|
180
|
+
whereObj = {
|
|
181
|
+
[Op.lte]: [
|
|
182
|
+
dayjs(filter.value).format('YYYY-MM-DD 23:59:59'),
|
|
183
|
+
]
|
|
184
|
+
} :
|
|
185
|
+
whereObj[key] = {
|
|
186
|
+
[Op.lte]: [
|
|
187
|
+
dayjs(filter.value).format('YYYY-MM-DD 23:59:59'),
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
break
|
|
191
|
+
|
|
192
|
+
case '=':
|
|
193
|
+
withoutKey ?
|
|
194
|
+
whereObj = {
|
|
195
|
+
[Op.between]: [
|
|
196
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
197
|
+
dayjs(filter.value).format('YYYY-MM-DD 23:59:59'),
|
|
198
|
+
]
|
|
199
|
+
} :
|
|
200
|
+
whereObj[key] = {
|
|
201
|
+
[Op.between]: [
|
|
202
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
203
|
+
dayjs(filter.value).format('YYYY-MM-DD 23:59:59'),
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
break
|
|
207
|
+
|
|
208
|
+
case '>':
|
|
209
|
+
withoutKey ?
|
|
210
|
+
whereObj = {
|
|
211
|
+
[Op.gt]: [
|
|
212
|
+
dayjs(filter.value).format('YYYY-MM-DD 23:59:59'),
|
|
213
|
+
]
|
|
214
|
+
} :
|
|
215
|
+
whereObj[key] = {
|
|
216
|
+
[Op.gt]: [
|
|
217
|
+
dayjs(filter.value).format('YYYY-MM-DD 23:59:59'),
|
|
218
|
+
]
|
|
219
|
+
}
|
|
220
|
+
break
|
|
221
|
+
|
|
222
|
+
case '>=':
|
|
223
|
+
withoutKey ?
|
|
224
|
+
whereObj = {
|
|
225
|
+
[Op.gte]: [
|
|
226
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
227
|
+
]
|
|
228
|
+
} :
|
|
229
|
+
whereObj[key] = {
|
|
230
|
+
[Op.gte]: [
|
|
231
|
+
dayjs(filter.value).format('YYYY-MM-DD 00:00:00'),
|
|
232
|
+
]
|
|
233
|
+
}
|
|
234
|
+
break
|
|
235
|
+
|
|
236
|
+
}
|
|
237
|
+
break
|
|
238
|
+
|
|
239
|
+
default:
|
|
240
|
+
switch(operator) {
|
|
241
|
+
case '=':
|
|
242
|
+
withoutKey ?
|
|
243
|
+
whereObj = {
|
|
244
|
+
[Op.eq]: filter.value
|
|
245
|
+
} :
|
|
246
|
+
whereObj[key] = {
|
|
247
|
+
[Op.eq]: filter.value
|
|
248
|
+
}
|
|
249
|
+
break
|
|
250
|
+
|
|
251
|
+
case 'eq':
|
|
252
|
+
case 'not':
|
|
253
|
+
withoutKey ?
|
|
254
|
+
whereObj = {
|
|
255
|
+
[Op[operator]]: filter.value
|
|
256
|
+
} :
|
|
257
|
+
whereObj[key] = {
|
|
258
|
+
[Op[operator]]: filter.value
|
|
259
|
+
}
|
|
260
|
+
break
|
|
261
|
+
|
|
262
|
+
case 'startsWith':
|
|
263
|
+
withoutKey ?
|
|
264
|
+
whereObj = {
|
|
265
|
+
[Op.like]: `${filter.value}%`
|
|
266
|
+
} :
|
|
267
|
+
whereObj[key] = {
|
|
268
|
+
[Op.like]: `${filter.value}%`
|
|
269
|
+
}
|
|
270
|
+
break
|
|
271
|
+
|
|
272
|
+
case 'endsWith':
|
|
273
|
+
withoutKey ?
|
|
274
|
+
whereObj = {
|
|
275
|
+
[Op.like]: `%${filter.value}`
|
|
276
|
+
} :
|
|
277
|
+
whereObj[key] = {
|
|
278
|
+
[Op.like]: `%${filter.value}`
|
|
279
|
+
}
|
|
280
|
+
break
|
|
281
|
+
|
|
282
|
+
case 'contains':
|
|
283
|
+
withoutKey ?
|
|
284
|
+
whereObj = {
|
|
285
|
+
[Op.like]: `%${filter.value}%`
|
|
286
|
+
} :
|
|
287
|
+
whereObj[key] = {
|
|
288
|
+
[Op.like]: `%${filter.value}%`
|
|
289
|
+
}
|
|
290
|
+
break
|
|
291
|
+
|
|
292
|
+
case 'notContains':
|
|
293
|
+
withoutKey ?
|
|
294
|
+
whereObj = {
|
|
295
|
+
[Op.notLike]: `%${filter.value}%`
|
|
296
|
+
} :
|
|
297
|
+
whereObj[key] = {
|
|
298
|
+
[Op.notLike]: `%${filter.value}%`
|
|
299
|
+
}
|
|
300
|
+
break
|
|
301
|
+
|
|
302
|
+
case 'in':
|
|
303
|
+
withoutKey ?
|
|
304
|
+
whereObj = {
|
|
305
|
+
[Op.in]: (!Array.isArray(filter.value) ? filter.value.split(',') : filter.value)
|
|
306
|
+
.map(_ => parseInt(_))
|
|
307
|
+
.filter(_ => !isNaN(_))
|
|
308
|
+
} :
|
|
309
|
+
whereObj[key] = {
|
|
310
|
+
[Op.in]: (!Array.isArray(filter.value) ? filter.value.split(',') : filter.value)
|
|
311
|
+
.map(_ => parseInt(_))
|
|
312
|
+
.filter(_ => !isNaN(_))
|
|
313
|
+
}
|
|
314
|
+
break
|
|
315
|
+
|
|
316
|
+
case 'notIn':
|
|
317
|
+
withoutKey ?
|
|
318
|
+
whereObj = {
|
|
319
|
+
[Op.notIn]: filter.value.split(',')
|
|
320
|
+
.map(_ => parseInt(_))
|
|
321
|
+
.filter(_ => !isNaN(_))
|
|
322
|
+
} :
|
|
323
|
+
whereObj[key] = {
|
|
324
|
+
[Op.notIn]: filter.value.split(',')
|
|
325
|
+
.map(_ => parseInt(_))
|
|
326
|
+
.filter(_ => !isNaN(_))
|
|
327
|
+
}
|
|
328
|
+
break
|
|
329
|
+
|
|
330
|
+
case 'regex':
|
|
331
|
+
withoutKey ?
|
|
332
|
+
whereObj = {
|
|
333
|
+
[Op.regexp]: filter.value
|
|
334
|
+
} :
|
|
335
|
+
whereObj[key] = {
|
|
336
|
+
[Op.regexp]: filter.value
|
|
337
|
+
}
|
|
338
|
+
break
|
|
339
|
+
}
|
|
340
|
+
break
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
return whereObj
|
|
344
|
+
}
|
|
345
|
+
|
|
7
346
|
const filtersToSequelizeWhere = async(filters, opt) => {
|
|
8
347
|
if(!Array.isArray(filters) || filters.length < 1){
|
|
9
348
|
return {
|