dobo 2.39.1 → 2.40.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/lib/factory/model/create-record.js +2 -1
- package/lib/factory/model/find-all-record.js +2 -1
- package/lib/factory/model/find-record.js +2 -1
- package/lib/factory/model/get-record.js +2 -1
- package/lib/factory/model/helper.js +18 -0
- package/lib/factory/model/remove-record.js +3 -2
- package/lib/factory/model/sanitize-record.js +1 -0
- package/lib/factory/model/update-record.js +2 -1
- package/lib/factory/model/upsert-record.js +2 -1
- package/package.json +1 -1
- package/wiki/CHANGES.md +10 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getFilterAndOptions, execHook, execValidation, execModelHook, execDynHook, getRefs, handleReq } from './helper.js'
|
|
1
|
+
import { getFilterAndOptions, execHook, execValidation, execModelHook, execDynHook, getRefs, getAttachments, handleReq } from './helper.js'
|
|
2
2
|
|
|
3
3
|
export const onlyTypes = ['datetime', 'date', 'time', 'timestamp', 'array', 'object']
|
|
4
4
|
const action = 'createRecord'
|
|
@@ -39,6 +39,7 @@ async function createRecord (...args) {
|
|
|
39
39
|
const { warnings } = getDefaultValues(options)
|
|
40
40
|
if (!warnings) delete result.warnings
|
|
41
41
|
if (isSet(options.refs)) await getRefs.call(this, [result.data], options)
|
|
42
|
+
if (options.attachments) await getAttachments.call(this, [result.data], options)
|
|
42
43
|
if (!noResultSanitizer) result.data = await this.sanitizeRecord(result.data, options)
|
|
43
44
|
await execDynHook.call(this, 'afterCreateRecord', input, result, options)
|
|
44
45
|
await execModelHook.call(this, 'afterCreateRecord', input, result, options)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getRefs, execHook, execModelHook, execDynHook, getFilterAndOptions, cloneOptions, sanitizeQuery } from './helper.js'
|
|
1
|
+
import { getRefs, getAttachments, execHook, execModelHook, execDynHook, getFilterAndOptions, cloneOptions, sanitizeQuery } from './helper.js'
|
|
2
2
|
const action = 'findAllRecord'
|
|
3
3
|
|
|
4
4
|
async function native (...args) {
|
|
@@ -42,6 +42,7 @@ async function native (...args) {
|
|
|
42
42
|
if (!warnings) delete result.warnings
|
|
43
43
|
|
|
44
44
|
if (isSet(options.refs)) await getRefs.call(this, result.data, options)
|
|
45
|
+
if (options.attachments) await getAttachments.call(this, result.data, options)
|
|
45
46
|
if (!noResultSanitizer) {
|
|
46
47
|
for (const idx in result.data) {
|
|
47
48
|
result.data[idx] = await this.sanitizeRecord(result.data[idx], options)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getFilterAndOptions, execHook, execModelHook, execDynHook, getRefs, sanitizeQuery } from './helper.js'
|
|
1
|
+
import { getFilterAndOptions, execHook, execModelHook, execDynHook, getRefs, sanitizeQuery, getAttachments } from './helper.js'
|
|
2
2
|
const action = 'findRecord'
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -67,6 +67,7 @@ async function findRecord (...args) {
|
|
|
67
67
|
result.pages = options.count ? Math.ceil(result.count / filter.limit) : undefined
|
|
68
68
|
if (!warnings) delete result.warnings
|
|
69
69
|
if (isSet(options.refs)) await getRefs.call(this, result.data, options)
|
|
70
|
+
if (options.attachments) await getAttachments.call(this, result.data, options)
|
|
70
71
|
if (!noResultSanitizer) {
|
|
71
72
|
for (const idx in result.data) {
|
|
72
73
|
result.data[idx] = await this.sanitizeRecord(result.data[idx], options)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getFilterAndOptions, execHook, execModelHook, execDynHook, getRefs } from './helper.js'
|
|
1
|
+
import { getFilterAndOptions, execHook, execModelHook, execDynHook, getRefs, getAttachments } from './helper.js'
|
|
2
2
|
const action = 'getRecord'
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -41,6 +41,7 @@ async function getRecord (...args) {
|
|
|
41
41
|
if (!warnings) delete result.warnings
|
|
42
42
|
if (isEmpty(result.data) && !options.throwNotFound) return dataOnly ? undefined : { data: undefined }
|
|
43
43
|
if (isSet(options.refs)) await getRefs.call(this, [result.data], options)
|
|
44
|
+
if (options.attachments) await getAttachments.call(this, [result.data], options)
|
|
44
45
|
if (!noResultSanitizer) result.data = await this.sanitizeRecord(result.data, options)
|
|
45
46
|
await execDynHook.call(this, 'afterGetRecord', id, result, options)
|
|
46
47
|
await execModelHook.call(this, 'afterGetRecord', id, result, options)
|
|
@@ -283,6 +283,21 @@ export async function handleAttachmentUpload (id, trigger, options = {}) {
|
|
|
283
283
|
return copyAttachment.call(this, id, { req, mimeType, stats, setFile, setField })
|
|
284
284
|
}
|
|
285
285
|
|
|
286
|
+
/**
|
|
287
|
+
* Get attachments for the given records.
|
|
288
|
+
* @async
|
|
289
|
+
* @memberof module:Helper/Model
|
|
290
|
+
* @method
|
|
291
|
+
* @name getAttachments
|
|
292
|
+
* @returns {Promise<void>}
|
|
293
|
+
* @param {Array<Object>} records - The records to get attachments for.
|
|
294
|
+
*/
|
|
295
|
+
export async function getAttachments (records = []) {
|
|
296
|
+
for (const rec of records) {
|
|
297
|
+
rec._attachments = await this.listAttachment({ id: rec.id })
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
286
301
|
/**
|
|
287
302
|
* Gets reference records for the given records.
|
|
288
303
|
* @async
|
|
@@ -336,8 +351,11 @@ export async function getRefs (records = [], options = {}) {
|
|
|
336
351
|
let items = isValues ? [...(rec[prop.name] ?? [])] : (rec[prop.name] ? [rec[prop.name]] : [])
|
|
337
352
|
items = items.map(item => item + '')
|
|
338
353
|
const res = results.filter(r => items.includes(r[ref.field] + ''))
|
|
354
|
+
/*
|
|
339
355
|
if (res.length === 0) records[i]._ref[key] = isValues ? [] : {}
|
|
340
356
|
else records[i]._ref[key] = isValues ? res : res[0]
|
|
357
|
+
*/
|
|
358
|
+
if (res.length > 0) records[i]._ref[key] = isValues ? (res ?? []) : (res[0] ?? {})
|
|
341
359
|
}
|
|
342
360
|
} catch (err) {
|
|
343
361
|
if (this.app.bajo.config.log.level === 'trace') console.error(err)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getFilterAndOptions, execHook, execModelHook, execDynHook, getRefs, handleReq, clearCache } from './helper.js'
|
|
1
|
+
import { getFilterAndOptions, execHook, execModelHook, execDynHook, getRefs, getAttachments, handleReq, clearCache } from './helper.js'
|
|
2
2
|
const action = 'removeRecord'
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -34,7 +34,8 @@ async function removeRecord (...args) {
|
|
|
34
34
|
const { warnings } = getDefaultValues(options)
|
|
35
35
|
if (!warnings) delete result.warnings
|
|
36
36
|
if (!noResultSanitizer) result.oldData = await this.sanitizeRecord(result.oldData, options)
|
|
37
|
-
if (isSet(options.refs)) await getRefs.call(this, [result.
|
|
37
|
+
if (isSet(options.refs)) await getRefs.call(this, [result.oldData], options)
|
|
38
|
+
if (options.attachments) await getAttachments.call(this, [result.oldData], options)
|
|
38
39
|
await execDynHook.call(this, 'afterRemoveRecord', id, result, options)
|
|
39
40
|
await execModelHook.call(this, 'afterRemoveRecord', id, result, options)
|
|
40
41
|
await execHook.call(this, 'afterRemoveRecord', id, result, options)
|
|
@@ -33,6 +33,7 @@ async function sanitizeRecord (record = {}, opts = {}) {
|
|
|
33
33
|
const body = fillObject(record, newFields, null)
|
|
34
34
|
const newRecord = await this.sanitizeBody({ body, partial: true, noDefault: true, allProps: true })
|
|
35
35
|
if (record._ref) newRecord._ref = cloneDeep(record._ref)
|
|
36
|
+
if (record._attachments) newRecord._attachments = cloneDeep(record._attachments)
|
|
36
37
|
for (const key in newRecord) {
|
|
37
38
|
const prop = this.getProperty(key)
|
|
38
39
|
if (!prop) continue
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getFilterAndOptions, execHook, execValidation, execModelHook, execDynHook, getRefs, handleReq, clearCache } from './helper.js'
|
|
1
|
+
import { getFilterAndOptions, execHook, execValidation, execModelHook, execDynHook, getRefs, getAttachments, handleReq, clearCache } from './helper.js'
|
|
2
2
|
import { onlyTypes } from './create-record.js'
|
|
3
3
|
const action = 'updateRecord'
|
|
4
4
|
|
|
@@ -45,6 +45,7 @@ async function updateRecord (...args) {
|
|
|
45
45
|
const { warnings } = getDefaultValues(options)
|
|
46
46
|
if (!warnings) delete result.warnings
|
|
47
47
|
if (isSet(options.refs)) await getRefs.call(this, [result.data], options)
|
|
48
|
+
if (options.attachments) await getAttachments.call(this, [result.data], options)
|
|
48
49
|
if (!noResultSanitizer) {
|
|
49
50
|
result.data = await this.sanitizeRecord(result.data, options)
|
|
50
51
|
result.oldData = await this.sanitizeRecord(result.oldData, options)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getFilterAndOptions, execHook, execModelHook, execDynHook, execValidation, getRefs, handleReq, clearCache } from './helper.js'
|
|
1
|
+
import { getFilterAndOptions, execHook, execModelHook, execDynHook, execValidation, getRefs, getAttachments, handleReq, clearCache } from './helper.js'
|
|
2
2
|
const action = 'upsertRecord'
|
|
3
3
|
|
|
4
4
|
async function native (body = {}, opts = {}) {
|
|
@@ -22,6 +22,7 @@ async function native (body = {}, opts = {}) {
|
|
|
22
22
|
const { warnings } = getDefaultValues(options)
|
|
23
23
|
if (!warnings) delete result.warnings
|
|
24
24
|
if (isSet(options.refs)) await getRefs.call(this, [result.data], options)
|
|
25
|
+
if (options.attachments) await getAttachments.call(this, [result.data], options)
|
|
25
26
|
if (!noResultSanitizer) result.data = await this.sanitizeRecord(result.data, options)
|
|
26
27
|
await execDynHook.call(this, 'afterUpsertRecord', input, result, options)
|
|
27
28
|
await execModelHook.call(this, 'afterUpsertRecord', input, result, options)
|
package/package.json
CHANGED
package/wiki/CHANGES.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changes
|
|
2
2
|
|
|
3
|
+
|
|
4
|
+
## 2026-10-21
|
|
5
|
+
|
|
6
|
+
- [2.40.0] Add `helper.getAttachments()`
|
|
7
|
+
- [2.40.0] Auto attach `_attachments` if `options.attachments` is true
|
|
8
|
+
|
|
9
|
+
## 2026-10-17
|
|
10
|
+
|
|
11
|
+
- [2.39.2] Bug fix in `helper.getRefs()`
|
|
12
|
+
|
|
3
13
|
## 2026-09-06
|
|
4
14
|
|
|
5
15
|
- [2.39.1] Bug fix in `helper.getRefs()`
|