dobo 1.1.7 → 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.
@@ -121,6 +121,7 @@
121
121
  "fixtureAdded%s%s%s": "Fixture on '%s': added %s, rejected: %s",
122
122
  "errorAddingFixture%s%s": "Error adding fixture on model '%s': %s",
123
123
  "memoryDbSkipped%s": "'%s' is a memory DB, skipped",
124
+ "db": "DB",
124
125
  "field": {
125
126
  "id": "ID",
126
127
  "code": "Kode",
package/bajo/intl/id.json CHANGED
@@ -114,6 +114,7 @@
114
114
  "addingFixtureToMemDb": "Adding fixture for memory database",
115
115
  "recordsAdded%s%d%d": "%s: %d of %d records added",
116
116
  "driverInstantiated%s%s": "- Driver '%s:%s' instantiated",
117
+ "db": "DB",
117
118
  "field": {
118
119
  "id": "ID",
119
120
  "code": "Kode",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "Database ORM/ODM for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
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) => {