dobo 1.1.4 → 1.1.5

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dobo",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "Database ORM/ODM for Bajo Framework",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,6 +1,6 @@
1
1
  async function sanitizeBody ({ body = {}, schema = {}, partial, strict, extFields = [] }) {
2
2
  const { isSet, dayjs, callHandler } = this.app.bajo
3
- const { has, isString, isNumber, concat } = this.lib._
3
+ const { has, isString, isNumber, concat, isNaN } = this.lib._
4
4
  const result = {}
5
5
  for (const p of concat(schema.properties, extFields)) {
6
6
  if (partial && !has(body, p.name)) continue
@@ -48,14 +48,15 @@ async function sanitizeBody ({ body = {}, schema = {}, partial, strict, extField
48
48
  }
49
49
  }
50
50
  } else {
51
- if (p.default) {
51
+ if (isSet(p.default)) {
52
52
  result[p.name] = p.default
53
53
  if (isString(p.default) && p.default.startsWith('handler:')) {
54
54
  const [, ...args] = p.default.split(':')
55
55
  if (args.length > 0) result[p.name] = await callHandler(args.join(':'))
56
56
  } else {
57
- if (['float', 'double'].includes(p.type)) result[p.name] = parseFloat(result[p.name]) || null
58
- if (['integer', 'smallint'].includes(p.type)) result[p.name] = parseInt(result[p.name]) || null
57
+ if (['float', 'double'].includes(p.type)) result[p.name] = parseFloat(result[p.name])
58
+ if (['integer', 'smallint'].includes(p.type)) result[p.name] = parseInt(result[p.name])
59
+ if (isNaN(result[p.name])) result[p.name] = null
59
60
  }
60
61
  }
61
62
  }