dobo 2.11.3 → 2.12.0
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/.bootorder +1 -0
- package/lib/factory/model/_util.js +46 -42
- package/lib/factory/model/validate.js +1 -1
- package/lib/factory/model.js +3 -1
- package/package.json +1 -1
- package/wiki/CHANGES.md +10 -0
package/.bootorder
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
10
|
|
@@ -171,23 +171,25 @@ export async function getSingleRef (record = {}, options = {}) {
|
|
|
171
171
|
if (props.length > 0) {
|
|
172
172
|
for (const prop of props) {
|
|
173
173
|
for (const key in prop.ref) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
174
|
+
try {
|
|
175
|
+
if (!((typeof options.refs === 'string' && ['*', 'all'].includes(options.refs)) || options.refs.includes(key))) continue
|
|
176
|
+
const ref = prop.ref[key]
|
|
177
|
+
if (ref.fields.length === 0) continue
|
|
178
|
+
if (get(record, `_ref.${key}`)) continue
|
|
179
|
+
const rModel = this.app.dobo.getModel(ref.model)
|
|
180
|
+
const query = {}
|
|
181
|
+
query[ref.propName] = record[prop.name]
|
|
182
|
+
if (ref.propName === 'id') query[ref.propName] = this.sanitizeId(query[ref.propName])
|
|
183
|
+
const rFilter = { query }
|
|
184
|
+
const rOptions = { dataOnly: true, refs: [] }
|
|
185
|
+
const results = await rModel.findRecord(rFilter, rOptions)
|
|
186
|
+
const fields = [...ref.fields]
|
|
187
|
+
const data = []
|
|
188
|
+
for (const res of results) {
|
|
189
|
+
data.push(await rModel.sanitizeRecord(res, { fields }))
|
|
190
|
+
}
|
|
191
|
+
refs[key] = ['1:1'].includes(ref.type) ? data[0] : data
|
|
192
|
+
} catch (err) {}
|
|
191
193
|
}
|
|
192
194
|
}
|
|
193
195
|
}
|
|
@@ -202,31 +204,33 @@ export async function getMultiRefs (records = [], options = {}) {
|
|
|
202
204
|
if (props.length > 0) {
|
|
203
205
|
for (const prop of props) {
|
|
204
206
|
for (const key in prop.ref) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
207
|
+
try {
|
|
208
|
+
if (!((typeof options.refs === 'string' && ['*', 'all'].includes(options.refs)) || options.refs.includes(key))) continue
|
|
209
|
+
const ref = prop.ref[key]
|
|
210
|
+
if (ref.fields.length === 0) continue
|
|
211
|
+
if (ref.type !== '1:1') continue
|
|
212
|
+
if (get(records, `0._ref.${key}`)) continue
|
|
213
|
+
const rModel = this.app.dobo.getModel(ref.model)
|
|
214
|
+
let matches = []
|
|
215
|
+
for (const r of records) {
|
|
216
|
+
matches.push(rModel.sanitizeId(r[prop.name]))
|
|
217
|
+
}
|
|
218
|
+
matches = uniq(without(matches, undefined, null, NaN))
|
|
219
|
+
const query = {}
|
|
220
|
+
query[ref.propName] = { $in: matches }
|
|
221
|
+
const rFilter = { query, limit: matches.length }
|
|
222
|
+
const rOptions = { dataOnly: true, refs: [] }
|
|
223
|
+
const results = await rModel.findRecord(rFilter, rOptions)
|
|
224
|
+
const fields = [...ref.fields]
|
|
225
|
+
if (!fields.includes(prop.name)) fields.push(prop.name)
|
|
226
|
+
for (const i in records) {
|
|
227
|
+
records[i]._ref = records[i]._ref ?? {}
|
|
228
|
+
const rec = records[i]
|
|
229
|
+
const res = results.find(res => (res[ref.propName] + '') === rec[prop.name] + '')
|
|
230
|
+
if (res) records[i]._ref[key] = await rModel.sanitizeRecord(res, { fields })
|
|
231
|
+
else records[i]._ref[key] = {}
|
|
232
|
+
}
|
|
233
|
+
} catch (err) {}
|
|
230
234
|
}
|
|
231
235
|
}
|
|
232
236
|
}
|
|
@@ -238,7 +238,7 @@ async function validate (body, joiModel, opts = {}) {
|
|
|
238
238
|
try {
|
|
239
239
|
return await joiModel.validateAsync(body, params)
|
|
240
240
|
} catch (err) {
|
|
241
|
-
const payload = { details: err.details, statusCode: 422, code: 'DB_VALIDATION' }
|
|
241
|
+
const payload = { details: err.details, statusCode: 422, code: 'DB_VALIDATION', model: this.name }
|
|
242
242
|
if (err.values) payload.values = err.values
|
|
243
243
|
throw this.plugin.error('validationError', payload)
|
|
244
244
|
}
|
package/lib/factory/model.js
CHANGED
|
@@ -109,7 +109,9 @@ async function modelFactory () {
|
|
|
109
109
|
if (isEmpty(field)) field = 'id'
|
|
110
110
|
const { getModel } = this.app.dobo
|
|
111
111
|
const ref = getModel(model)
|
|
112
|
-
const
|
|
112
|
+
const opts = { noHook: true, noCache: true, ...options }
|
|
113
|
+
opts.dataOnly = true
|
|
114
|
+
const rec = await ref.findOneRecord({ query }, opts)
|
|
113
115
|
return get(rec, field, null)
|
|
114
116
|
}
|
|
115
117
|
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
## 2026-03-30
|
|
4
|
+
|
|
5
|
+
- [2.12.0] Add ```.bootorder``` level 10
|
|
6
|
+
- [2.12.0] Bug fix in ```model._simpleLookup()```
|
|
7
|
+
- [2.12.0] Add model name in validation error's payload
|
|
8
|
+
|
|
9
|
+
## 2026-03-26
|
|
10
|
+
|
|
11
|
+
- [2.11.4] Exceptions thrown in ```getSingleRef()``` && ```getMultiRefs()``` will be catched and are ignored
|
|
12
|
+
|
|
3
13
|
## 2026-03-25
|
|
4
14
|
|
|
5
15
|
- [2.11.2] Bug fix in result sets cache
|