dobo 1.1.8 → 1.1.9
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/plugin/factory.js +31 -1
package/package.json
CHANGED
package/plugin/factory.js
CHANGED
|
@@ -271,7 +271,37 @@ async function factory (pkgName) {
|
|
|
271
271
|
if (trim(filter.query).startsWith('{')) query = JSON.parse(filter.query)
|
|
272
272
|
else query = nql(filter.query).parse()
|
|
273
273
|
} else if (isPlainObject(filter.query)) query = filter.query
|
|
274
|
-
return query
|
|
274
|
+
return this.sanitizeQuery(query, schema)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
sanitizeQuery = (query, schema, parent) => {
|
|
278
|
+
const { cloneDeep, isPlainObject, isArray, find } = this.lib._
|
|
279
|
+
const { isSet } = this.app.bajo
|
|
280
|
+
const { dayjs } = this.lib
|
|
281
|
+
const obj = cloneDeep(query)
|
|
282
|
+
const keys = Object.keys(obj)
|
|
283
|
+
const sanitize = (key, val, p) => {
|
|
284
|
+
if (!isSet(val)) return val
|
|
285
|
+
const prop = find(schema.properties, { name: key.startsWith('$') ? p : key })
|
|
286
|
+
if (!prop) return val
|
|
287
|
+
if (['datetime', 'date', 'time'].includes(prop.type)) {
|
|
288
|
+
const dt = dayjs(val)
|
|
289
|
+
return dt.isValid() ? dt.toDate() : val
|
|
290
|
+
} else if (['smallint', 'integer'].includes(prop.type)) return parseInt(val) || val
|
|
291
|
+
else if (['float', 'double'].includes(prop.type)) return parseFloat(val) || val
|
|
292
|
+
else if (['boolean'].includes(prop.type)) return !!val
|
|
293
|
+
return val
|
|
294
|
+
}
|
|
295
|
+
keys.forEach(k => {
|
|
296
|
+
const v = obj[k]
|
|
297
|
+
if (isPlainObject(v)) obj[k] = this.sanitizeQuery(v, schema, k)
|
|
298
|
+
else if (isArray(v)) {
|
|
299
|
+
v.forEach((i, idx) => {
|
|
300
|
+
if (isPlainObject(i)) obj[k][idx] = this.sanitizeQuery(i, schema, k)
|
|
301
|
+
})
|
|
302
|
+
} else obj[k] = sanitize(k, v, parent)
|
|
303
|
+
})
|
|
304
|
+
return obj
|
|
275
305
|
}
|
|
276
306
|
|
|
277
307
|
validationErrorMessage = (err) => {
|