dobo 1.0.19 → 1.0.20
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/bajo/method/attachment/copy-uploaded.js +0 -1
- package/bajo/method/record/create.js +2 -0
- package/bajo/method/record/find-one.js +1 -1
- package/bajo/method/record/find.js +1 -1
- package/bajo/method/record/get.js +1 -1
- package/bajo/method/record/update.js +2 -0
- package/lib/single-rel-rows.js +1 -1
- package/package.json +1 -1
- package/waibuMpa/route/attachment/@model/@id/@field/@file.js +1 -1
|
@@ -3,7 +3,6 @@ import path from 'path'
|
|
|
3
3
|
async function copyUploaded (name, id, options = {}) {
|
|
4
4
|
const { fs } = this.app.bajo.lib
|
|
5
5
|
const { omit } = this.app.bajo.lib._
|
|
6
|
-
console.log(omit(options, ['req']))
|
|
7
6
|
const { req, setField, setFile, mimeType, stats, silent = true } = options
|
|
8
7
|
name = this.attachmentPreCheck(name)
|
|
9
8
|
if (!name) {
|
|
@@ -4,6 +4,7 @@ import checkUnique from '../../../lib/check-unique.js'
|
|
|
4
4
|
import handleAttachmentUpload from '../../../lib/handle-attachment-upload.js'
|
|
5
5
|
import execValidation from '../../../lib/exec-validation.js'
|
|
6
6
|
import execFeatureHook from '../../../lib/exec-feature-hook.js'
|
|
7
|
+
import singleRelRows from '../../../lib/single-rel-rows.js'
|
|
7
8
|
|
|
8
9
|
async function create (name, input, opts = {}) {
|
|
9
10
|
const { generateId, runHook, isSet } = this.app.bajo
|
|
@@ -49,6 +50,7 @@ async function create (name, input, opts = {}) {
|
|
|
49
50
|
nbody[k] = v
|
|
50
51
|
})
|
|
51
52
|
record = await handler.call(this.app[driver.ns], { schema, body: nbody, options })
|
|
53
|
+
if (isSet(options.rels)) await singleRelRows.call(this, { schema, record: record.data, options })
|
|
52
54
|
if (options.req) {
|
|
53
55
|
if (options.req.file) await handleAttachmentUpload.call(this, { name: schema.name, id: body.id, body, options, action: 'create' })
|
|
54
56
|
if (options.req.flash && !options.noFlash) options.req.flash('notify', options.req.t('recordCreated'))
|
|
@@ -32,12 +32,12 @@ async function findOne (name, filter = {}, opts = {}) {
|
|
|
32
32
|
}
|
|
33
33
|
const record = await handler.call(this.app[driver.ns], { schema, filter, options })
|
|
34
34
|
record.data = record.data[0]
|
|
35
|
+
if (isSet(options.rels)) await singleRelRows.call(this, { schema, record: record.data, options })
|
|
35
36
|
if (!noHook) {
|
|
36
37
|
await runHook(`${this.name}.${camelCase(name)}:afterRecordFindOne`, filter, options, record)
|
|
37
38
|
await runHook(`${this.name}:afterRecordFindOne`, name, filter, options, record)
|
|
38
39
|
}
|
|
39
40
|
record.data = await this.pickRecord({ record: record.data, fields, schema, hidden, forceNoHidden })
|
|
40
|
-
if (isSet(options.rels)) await singleRelRows.call(this, { schema, record: record.data, options })
|
|
41
41
|
if (set && !noCache) await set({ model: name, filter, options, record })
|
|
42
42
|
return dataOnly ? record.data : record
|
|
43
43
|
}
|
|
@@ -30,6 +30,7 @@ async function find (name, filter = {}, opts = {}) {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
const records = await handler.call(this.app[driver.ns], { schema, filter, options })
|
|
33
|
+
if (isSet(options.rels)) await multiRelRows.call(this, { schema, records: records.data, options })
|
|
33
34
|
if (!noHook) {
|
|
34
35
|
await runHook(`${this.name}.${camelCase(name)}:afterRecordFind`, filter, options, records)
|
|
35
36
|
await runHook(`${this.name}:afterRecordFind`, name, filter, options, records)
|
|
@@ -37,7 +38,6 @@ async function find (name, filter = {}, opts = {}) {
|
|
|
37
38
|
for (const idx in records.data) {
|
|
38
39
|
records.data[idx] = await this.pickRecord({ record: records.data[idx], fields, schema, hidden, forceNoHidden })
|
|
39
40
|
}
|
|
40
|
-
if (isSet(options.rels)) await multiRelRows.call(this, { schema, records: records.data, options })
|
|
41
41
|
if (set && !noCache) await set({ model: name, filter, options, records })
|
|
42
42
|
return dataOnly ? records.data : records
|
|
43
43
|
}
|
|
@@ -27,12 +27,12 @@ async function get (name, id, opts = {}) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
const record = await handler.call(this.app[driver.ns], { schema, id, options })
|
|
30
|
+
if (isSet(options.rels)) await singleRelRows.call(this, { schema, record: record.data, options })
|
|
30
31
|
if (!noHook) {
|
|
31
32
|
await runHook(`${this.name}.${camelCase(name)}:afterRecordGet`, id, options, record)
|
|
32
33
|
await runHook(`${this.name}:afterRecordGet`, name, id, options, record)
|
|
33
34
|
}
|
|
34
35
|
record.data = await this.pickRecord({ record: record.data, fields, schema, hidden, forceNoHidden })
|
|
35
|
-
if (isSet(options.rels)) await singleRelRows.call(this, { schema, record: record.data, options })
|
|
36
36
|
|
|
37
37
|
if (set && !noCache) await set({ model: name, id, options, record })
|
|
38
38
|
return dataOnly ? record.data : record
|
|
@@ -3,6 +3,7 @@ import checkUnique from '../../../lib/check-unique.js'
|
|
|
3
3
|
import handleAttachmentUpload from '../../../lib/handle-attachment-upload.js'
|
|
4
4
|
import execValidation from '../../../lib/exec-validation.js'
|
|
5
5
|
import execFeatureHook from '../../../lib/exec-feature-hook.js'
|
|
6
|
+
import singleRelRows from '../../../lib/single-rel-rows.js'
|
|
6
7
|
|
|
7
8
|
async function update (name, id, input, opts = {}) {
|
|
8
9
|
const { runHook, isSet } = this.app.bajo
|
|
@@ -39,6 +40,7 @@ async function update (name, id, input, opts = {}) {
|
|
|
39
40
|
})
|
|
40
41
|
delete nbody.id
|
|
41
42
|
const record = await handler.call(this.app[driver.ns], { schema, id, body: nbody, options })
|
|
43
|
+
if (isSet(options.rels)) await singleRelRows.call(this, { schema, record: record.data, options })
|
|
42
44
|
if (options.req) {
|
|
43
45
|
if (options.req.file) await handleAttachmentUpload.call(this, { name: schema.name, id, body, options, action: 'update' })
|
|
44
46
|
if (options.req.flash && !options.noFlash) options.req.flash('notify', options.req.t('recordUpdated'))
|
package/lib/single-rel-rows.js
CHANGED
|
@@ -10,7 +10,7 @@ async function singleRelRows ({ schema, record, options = {} }) {
|
|
|
10
10
|
const val = prop.rel[key]
|
|
11
11
|
if (val.fields.length === 0) continue
|
|
12
12
|
const relschema = this.getSchema(val.schema)
|
|
13
|
-
const relFilter = options.filter
|
|
13
|
+
const relFilter = options.filter ?? {}
|
|
14
14
|
const query = {}
|
|
15
15
|
query[val.propName] = record[prop.name]
|
|
16
16
|
relFilter.query = query
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@ async function attachment (req, reply) {
|
|
|
5
5
|
const mime = await importPkg('waibu:mime')
|
|
6
6
|
const { fs } = this.app.bajo.lib
|
|
7
7
|
const file = `${getPluginDataDir('dobo')}/attachment/${pascalCase(req.params.model)}/${req.params.id}/${req.params.field}/${req.params.file}`
|
|
8
|
-
if (!fs.existsSync(file)) throw this.error('_notFound')
|
|
8
|
+
if (!fs.existsSync(file)) throw this.error('_notFound', { noView: true })
|
|
9
9
|
const mimeType = mime.getType(path.extname(file))
|
|
10
10
|
reply.header('Content-Type', mimeType)
|
|
11
11
|
const stream = fs.createReadStream(file)
|