dobo 2.30.3 → 2.30.4
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/lib/factory/driver.js
CHANGED
|
@@ -191,9 +191,10 @@ async function driverFactory () {
|
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
async _prepBodyForCreate (model, body = {}, options = {}) {
|
|
194
|
+
const { callHandler } = this.app.bajo
|
|
194
195
|
const { isSet, generateId } = this.app.lib.aneka
|
|
195
196
|
for (const prop of model.getProperties({ noVirtual: true })) {
|
|
196
|
-
if (!isSet(body[prop.name])
|
|
197
|
+
if (isSet(prop.default) && (!options.noDefault) && (!isSet(body[prop.name]) || body[prop.name] === prop.default)) {
|
|
197
198
|
if (isFunction(prop.default)) body[prop.name] = await prop.default.call(model)
|
|
198
199
|
else if (typeof prop.default !== 'string') body[prop.name] = prop.default
|
|
199
200
|
else {
|
|
@@ -207,6 +208,9 @@ async function driverFactory () {
|
|
|
207
208
|
body[prop.name] = ulid().slice(0, prop.maxLength)
|
|
208
209
|
} else if (prop.default === 'generateid' && prop.type === 'string') {
|
|
209
210
|
body[prop.name] = generateId()
|
|
211
|
+
} else if (prop.default.startsWith('handler:')) {
|
|
212
|
+
const [, ...args] = prop.default.split(':')
|
|
213
|
+
if (args.length > 0) body[prop.name] = await callHandler(args.join(':'))
|
|
210
214
|
} else if (prop.default.startsWith('md5:') && prop.type === 'string') {
|
|
211
215
|
const [, field] = prop.default.split(':')
|
|
212
216
|
const fields = field.split(',')
|
|
@@ -14,9 +14,8 @@
|
|
|
14
14
|
*/
|
|
15
15
|
async function sanitizeBody ({ body = {}, partial, strict, extFields = [], noDefault, truncateString, onlyTypes = [], action } = {}) {
|
|
16
16
|
const { isSet } = this.app.lib.aneka
|
|
17
|
-
const { callHandler } = this.app.bajo
|
|
18
17
|
const { sanitizeByType } = this.app.dobo
|
|
19
|
-
const { omit, has
|
|
18
|
+
const { omit, has } = this.app.lib._
|
|
20
19
|
const result = {}
|
|
21
20
|
|
|
22
21
|
const sanitize = (name, type) => {
|
|
@@ -37,15 +36,6 @@ async function sanitizeBody ({ body = {}, partial, strict, extFields = [], noDef
|
|
|
37
36
|
result[prop.name] = body[prop.name]
|
|
38
37
|
if (prop.type === 'array' && isSet(result[prop.name]) && !Array.isArray(result[prop.name])) result[prop.name] = [result[prop.name]]
|
|
39
38
|
if (isSet(result[prop.name])) sanitize(prop.name, prop.type)
|
|
40
|
-
else {
|
|
41
|
-
if (isSet(prop.default) && !noDefault) {
|
|
42
|
-
result[prop.name] = prop.default
|
|
43
|
-
if (isString(prop.default) && prop.default.startsWith('handler:')) {
|
|
44
|
-
const [, ...args] = prop.default.split(':')
|
|
45
|
-
if (args.length > 0) result[prop.name] = await callHandler(args.join(':'))
|
|
46
|
-
} else sanitize(prop.name, prop.type)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
39
|
if (result[prop.name] === null) continue
|
|
50
40
|
if (truncateString && isSet(result[prop.name]) && ['string', 'text'].includes(prop.type)) result[prop.name] = result[prop.name].slice(0, prop.maxLength)
|
|
51
41
|
if (prop.name.endsWith('Id') && isSet(result[prop.name]) && prop.type === 'string' && ['smallint', 'integer'].includes(this.driver.idField.type)) result[prop.name] = result[prop.name] + ''
|
package/package.json
CHANGED