waibu-db 1.0.15 → 1.0.17
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/record/count.js +1 -1
- package/bajo/method/record/create.js +1 -2
- package/bajo/method/record/find-one.js +1 -2
- package/bajo/method/record/find.js +1 -2
- package/bajo/method/record/get.js +1 -2
- package/bajo/method/record/remove.js +1 -1
- package/bajo/method/record/update.js +1 -2
- package/bajo/method/stat/aggregate.js +1 -1
- package/bajo/method/stat/histogram.js +1 -1
- package/lib/prep-crud.js +9 -2
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import prepCrud from '../../../lib/prep-crud.js'
|
|
|
2
2
|
|
|
3
3
|
async function count ({ model, req, reply, options = {} }) {
|
|
4
4
|
const { recordCount } = this.app.dobo
|
|
5
|
-
const { name, opts, filter } = prepCrud.call(this, { model, req, options, args: ['model'] })
|
|
5
|
+
const { name, opts, filter } = prepCrud.call(this, { model, req, reply, options, args: ['model'] })
|
|
6
6
|
const ret = await recordCount(name, filter, opts)
|
|
7
7
|
return ret
|
|
8
8
|
}
|
|
@@ -2,9 +2,8 @@ import prepCrud from '../../../lib/prep-crud.js'
|
|
|
2
2
|
|
|
3
3
|
async function create ({ model, req, reply, body, options = {} }) {
|
|
4
4
|
const { recordCreate, attachmentFind } = this.app.dobo
|
|
5
|
-
const { name, input, opts } = prepCrud.call(this, { model, req, body, options, args: ['model'] })
|
|
5
|
+
const { name, input, opts, attachment, stats, mimeType } = prepCrud.call(this, { model, req, reply, body, options, args: ['model'] })
|
|
6
6
|
const ret = await recordCreate(name, input, opts)
|
|
7
|
-
const { attachment, stats, mimeType } = req.query
|
|
8
7
|
if (attachment) ret.data._attachment = await attachmentFind(name, ret.data.id, { stats, mimeType })
|
|
9
8
|
return ret
|
|
10
9
|
}
|
|
@@ -2,9 +2,8 @@ import prepCrud from '../../../lib/prep-crud.js'
|
|
|
2
2
|
|
|
3
3
|
async function find ({ model, req, reply, options = {} }) {
|
|
4
4
|
const { recordFindOne, attachmentFind } = this.app.dobo
|
|
5
|
-
const { name, opts, filter } = prepCrud.call(this, { model, req, options, args: ['model'] })
|
|
5
|
+
const { name, opts, filter, attachment, stats, mimeType } = prepCrud.call(this, { model, req, reply, options, args: ['model'] })
|
|
6
6
|
const ret = await recordFindOne(name, filter, opts)
|
|
7
|
-
const { attachment, stats, mimeType } = req.query
|
|
8
7
|
if (attachment) {
|
|
9
8
|
for (const d of ret.data) {
|
|
10
9
|
d._attachment = await attachmentFind(name, d.id, { stats, mimeType })
|
|
@@ -2,9 +2,8 @@ import prepCrud from '../../../lib/prep-crud.js'
|
|
|
2
2
|
|
|
3
3
|
async function find ({ model, req, reply, options = {} }) {
|
|
4
4
|
const { recordFind, attachmentFind } = this.app.dobo
|
|
5
|
-
const { name, opts, filter } = prepCrud.call(this, { model, req, options, args: ['model'] })
|
|
5
|
+
const { name, opts, filter, attachment, stats, mimeType } = prepCrud.call(this, { model, req, reply, options, args: ['model'] })
|
|
6
6
|
const ret = await recordFind(name, filter, opts)
|
|
7
|
-
const { attachment, stats, mimeType } = req.query
|
|
8
7
|
if (attachment) {
|
|
9
8
|
for (const d of ret.data) {
|
|
10
9
|
d._attachment = await attachmentFind(name, d.id, { stats, mimeType })
|
|
@@ -3,10 +3,9 @@ import prepCrud from '../../../lib/prep-crud.js'
|
|
|
3
3
|
async function get ({ model, req, reply, id, options = {} }) {
|
|
4
4
|
const { recordGet, attachmentFind } = this.app.dobo
|
|
5
5
|
const { parseFilter } = this.app.waibu
|
|
6
|
-
const { name, recId, opts } = prepCrud.call(this, { model, req, id, options, args: ['model', 'id'] })
|
|
6
|
+
const { name, recId, opts, attachment, stats, mimeType } = prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'] })
|
|
7
7
|
opts.filter = parseFilter(req)
|
|
8
8
|
const ret = await recordGet(name, recId, opts)
|
|
9
|
-
const { attachment, stats, mimeType } = req.query
|
|
10
9
|
if (attachment) ret.data._attachment = await attachmentFind(name, id, { stats, mimeType })
|
|
11
10
|
return ret
|
|
12
11
|
}
|
|
@@ -2,7 +2,7 @@ import prepCrud from '../../../lib/prep-crud.js'
|
|
|
2
2
|
|
|
3
3
|
async function remove ({ model, req, reply, id, options = {} }) {
|
|
4
4
|
const { recordRemove } = this.app.dobo
|
|
5
|
-
const { name, recId, opts } = prepCrud.call(this, { model, req, id, options, args: ['model', 'id'] })
|
|
5
|
+
const { name, recId, opts } = prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'] })
|
|
6
6
|
const result = await recordRemove(name, recId, opts)
|
|
7
7
|
return result
|
|
8
8
|
}
|
|
@@ -2,9 +2,8 @@ import prepCrud from '../../../lib/prep-crud.js'
|
|
|
2
2
|
|
|
3
3
|
async function update ({ model, req, reply, id, body, options = {} }) {
|
|
4
4
|
const { recordUpdate, attachmentFind } = this.app.dobo
|
|
5
|
-
const { name, input, opts, recId } = prepCrud.call(this, { model, req, body, id, options, args: ['model', 'id'] })
|
|
5
|
+
const { name, input, opts, recId, attachment, stats, mimeType } = prepCrud.call(this, { model, req, reply, body, id, options, args: ['model', 'id'] })
|
|
6
6
|
const ret = await recordUpdate(name, recId, input, opts)
|
|
7
|
-
const { attachment, stats, mimeType } = req.query
|
|
8
7
|
if (attachment) ret.data._attachment = await attachmentFind(name, id, { stats, mimeType })
|
|
9
8
|
return ret
|
|
10
9
|
}
|
|
@@ -3,7 +3,7 @@ import prepCrud from '../../../lib/prep-crud.js'
|
|
|
3
3
|
async function aggregate ({ model, req, reply, options = {} }) {
|
|
4
4
|
const { statAggregate } = this.app.dobo
|
|
5
5
|
const { parseFilter } = this.app.waibu
|
|
6
|
-
const { name, opts } = prepCrud.call(this, { model, req, options, args: ['model'] })
|
|
6
|
+
const { name, opts } = prepCrud.call(this, { model, req, reply, options, args: ['model'] })
|
|
7
7
|
for (const item of ['group', 'aggregate']) {
|
|
8
8
|
opts[item] = options[item] ?? req.params[item] ?? req.query[item]
|
|
9
9
|
}
|
|
@@ -3,7 +3,7 @@ import prepCrud from '../../../lib/prep-crud.js'
|
|
|
3
3
|
async function histogram ({ model, req, reply, options = {} }) {
|
|
4
4
|
const { statHistogram } = this.app.dobo
|
|
5
5
|
const { parseFilter } = this.app.waibu
|
|
6
|
-
const { name, opts } = prepCrud.call(this, { model, req, options, args: ['model'] })
|
|
6
|
+
const { name, opts } = prepCrud.call(this, { model, req, reply, options, args: ['model'] })
|
|
7
7
|
for (const item of ['type', 'group', 'aggregate']) {
|
|
8
8
|
opts[item] = options[item] ?? req.params[item] ?? req.query[item]
|
|
9
9
|
}
|
package/lib/prep-crud.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
function prepCrud ({ model, body, id, req, options, args }) {
|
|
1
|
+
function prepCrud ({ model, body, id, req, reply, options = {}, args }) {
|
|
2
2
|
const { parseFilter } = this.app.waibu
|
|
3
3
|
const { pascalCase } = this.app.bajo
|
|
4
4
|
const { cloneDeep, has } = this.app.bajo.lib._
|
|
@@ -11,6 +11,13 @@ function prepCrud ({ model, body, id, req, options, args }) {
|
|
|
11
11
|
if (has(options, 'count')) opts.count = options.count
|
|
12
12
|
opts.dataOnly = opts.dataOnly ?? false
|
|
13
13
|
opts.req = req
|
|
14
|
+
opts.reply = reply
|
|
15
|
+
|
|
16
|
+
let { attachment, stats, mimeType } = opts
|
|
17
|
+
attachment = attachment ?? req.query.attachment
|
|
18
|
+
stats = stats ?? req.query.stats
|
|
19
|
+
mimeType = mimeType ?? req.query.mimeType
|
|
20
|
+
|
|
14
21
|
const recId = id ?? params.id ?? req.query.id
|
|
15
22
|
const name = pascalCase(model ?? params.model)
|
|
16
23
|
const input = body ?? params.body
|
|
@@ -20,7 +27,7 @@ function prepCrud ({ model, body, id, req, options, args }) {
|
|
|
20
27
|
if (options.query) filter.query = cloneDeep(options.query)
|
|
21
28
|
if (options.limit) filter.limit = options.limit
|
|
22
29
|
if (options.sort) filter.sort = options.sort
|
|
23
|
-
return { name, recId, input, opts, filter }
|
|
30
|
+
return { name, recId, input, opts, filter, attachment, stats, mimeType }
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
export default prepCrud
|