waibu-db 1.0.15 → 1.0.16

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,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,7 +2,7 @@ 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 } = prepCrud.call(this, { model, req, reply, body, options, args: ['model'] })
6
6
  const ret = await recordCreate(name, input, opts)
7
7
  const { attachment, stats, mimeType } = req.query
8
8
  if (attachment) ret.data._attachment = await attachmentFind(name, ret.data.id, { stats, mimeType })
@@ -2,7 +2,7 @@ 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 } = prepCrud.call(this, { model, req, reply, options, args: ['model'] })
6
6
  const ret = await recordFindOne(name, filter, opts)
7
7
  const { attachment, stats, mimeType } = req.query
8
8
  if (attachment) {
@@ -2,7 +2,7 @@ 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 } = prepCrud.call(this, { model, req, reply, options, args: ['model'] })
6
6
  const ret = await recordFind(name, filter, opts)
7
7
  const { attachment, stats, mimeType } = req.query
8
8
  if (attachment) {
@@ -3,7 +3,7 @@ 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 } = 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
9
  const { attachment, stats, mimeType } = req.query
@@ -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,7 +2,7 @@ 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 } = prepCrud.call(this, { model, req, reply, body, id, options, args: ['model', 'id'] })
6
6
  const ret = await recordUpdate(name, recId, input, opts)
7
7
  const { attachment, stats, mimeType } = req.query
8
8
  if (attachment) ret.data._attachment = await attachmentFind(name, id, { stats, mimeType })
@@ -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,7 @@ 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
14
15
  const recId = id ?? params.id ?? req.query.id
15
16
  const name = pascalCase(model ?? params.model)
16
17
  const input = body ?? params.body
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "waibu-db",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "DB Helper",
5
5
  "main": "index.js",
6
6
  "scripts": {