waibu-db 1.0.16 → 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.
@@ -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, reply, 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, reply, 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, reply, 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, reply, 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,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, reply, 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
  }
package/lib/prep-crud.js CHANGED
@@ -1,4 +1,4 @@
1
- function prepCrud ({ model, body, id, req, reply, 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._
@@ -12,6 +12,12 @@ function prepCrud ({ model, body, id, req, reply, options, args }) {
12
12
  opts.dataOnly = opts.dataOnly ?? false
13
13
  opts.req = req
14
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
+
15
21
  const recId = id ?? params.id ?? req.query.id
16
22
  const name = pascalCase(model ?? params.model)
17
23
  const input = body ?? params.body
@@ -21,7 +27,7 @@ function prepCrud ({ model, body, id, req, reply, options, args }) {
21
27
  if (options.query) filter.query = cloneDeep(options.query)
22
28
  if (options.limit) filter.limit = options.limit
23
29
  if (options.sort) filter.sort = options.sort
24
- return { name, recId, input, opts, filter }
30
+ return { name, recId, input, opts, filter, attachment, stats, mimeType }
25
31
  }
26
32
 
27
33
  export default prepCrud
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-db",
3
- "version": "1.0.16",
3
+ "version": "1.0.17",
4
4
  "description": "DB Helper",
5
5
  "main": "index.js",
6
6
  "scripts": {