waibu-db 1.0.16 → 1.0.18

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
  }
@@ -0,0 +1,5 @@
1
+ <% for (const ao of addOns) { %>
2
+ <c:div append-to="#sb-addons" margin="bottom-3">
3
+ <!-- include <%= ao.resource %>|<%= JSON.stringify(ao.data) %> -->
4
+ </c:div>
5
+ <% } %>
@@ -1,5 +1,5 @@
1
1
  <c:form>
2
- <c:include resource="waibuDb.partial:/crud/_form.html" />
2
+ <!-- include waibuDb.partial:/crud/_form.html -->
3
3
  <c:grid-row gutter="2" margin="top-2">
4
4
  <c:grid-col col="6-md">
5
5
  <c:wdb-btn-back />
@@ -16,4 +16,4 @@
16
16
  </c:grid-col>
17
17
  </c:grid-row>
18
18
  </c:form>
19
- <c:include resource="waibuDb.partial:/crud/_addons.html" />
19
+ <!-- include waibuDb.partial:/crud/_addons.html -->
@@ -1,5 +1,5 @@
1
1
  <c:div id="main-form">
2
- <c:include resource="waibuDb.partial:/crud/_form.html" />
2
+ <!-- include waibuDb.partial:/crud/_form.html -->
3
3
  </c:div>
4
4
  <c:grid-row gutter="2" margin="top-2">
5
5
  <c:grid-col col="6-lg">
@@ -18,4 +18,4 @@
18
18
  <c:wdb-btn-delete/>
19
19
  </c:grid-col>
20
20
  </c:grid-row>
21
- <c:include resource="waibuDb.partial:/crud/_addons.html" />
21
+ <!-- include waibuDb.partial:/crud/_addons.html -->
@@ -1,5 +1,5 @@
1
1
  <c:form id="main-form">
2
- <c:include resource="waibuDb.partial:/crud/_form.html" />
2
+ <!-- include waibuDb.partial:/crud/_form.html -->
3
3
  <c:grid-row gutter="2" margin="top-2">
4
4
  <c:grid-col col="6-lg">
5
5
  <c:wdb-btn-back />
@@ -16,4 +16,4 @@
16
16
  </c:grid-col>
17
17
  </c:grid-row>
18
18
  </c:form>
19
- <c:include resource="waibuDb.partial:/crud/_addons.html" />
19
+ <!-- include waibuDb.partial:/crud/_addons.html -->
@@ -15,5 +15,5 @@
15
15
  </c:grid-col>
16
16
  </c:grid-row>
17
17
  <c:wdb-table id="main-table" border body-divider strip responsive />
18
- <c:include resource="waibuDb.partial:/crud/_list-footer.html" />
19
- <c:include resource="waibuDb.partial:/crud/_addons.html" />
18
+ <!-- include waibuDb.partial:/crud/_list-footer.html -->
19
+ <!-- include waibuDb.partial:/crud/_addons.html -->
@@ -1,2 +1,2 @@
1
1
  <c:heading move-to="#fullTitle" type="5" t:content="%s - %s|<%= page.modelTitle %>|<%= _t('Add') %>" />
2
- <c:include resource="waibuDb.partial:/crud/add-handler.html" />
2
+ <!-- include waibuDb.partial:/crud/add-handler.html -->
@@ -1,2 +1,2 @@
1
1
  <c:heading move-to="#fullTitle" type="5" t:content="%s - %s|<%= page.modelTitle %>|<%= _t('Details') %>" />
2
- <c:include resource="waibuDb.partial:/crud/details-handler.html" />
2
+ <!-- include waibuDb.partial:/crud/details-handler.html -->
@@ -1,2 +1,2 @@
1
1
  <c:heading move-to="#fullTitle" type="5" t:content="%s - %s|<%= page.modelTitle %>|<%= _t('Edit') %>" />
2
- <c:include resource="waibuDb.partial:/crud/edit-handler.html" />
2
+ <!-- include waibuDb.partial:/crud/edit-handler.html -->
@@ -1,2 +1,2 @@
1
1
  <c:heading move-to="#fullTitle" type="5" t:content="%s - %s|<%= page.modelTitle %>|<%= _t('List') %>" />
2
- <c:include resource="waibuDb.partial:/crud/list-handler.html" />
2
+ <!-- include waibuDb.partial:/crud/list-handler.html -->
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.18",
4
4
  "description": "DB Helper",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,5 +0,0 @@
1
- <% for (const ao of addOns) { %>
2
- <c:div append-to="#sb-addons" margin="bottom-3">
3
- <c:include resource="<%= ao.resource %>" <% for (const k in ao.data) { print(k + '="' + ao.data[k] + '" ') } %>/>
4
- </c:div>
5
- <% } %>