waibu-db 2.0.1 → 2.1.1
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/.github/FUNDING.yml +0 -0
- package/.github/workflows/repo-lockdown.yml +0 -0
- package/.jsdoc.conf.json +0 -0
- package/LICENSE +0 -0
- package/README.md +1 -1
- package/docs/WaibuDb.html +1 -1
- package/docs/data/search.json +0 -0
- package/docs/fonts/Inconsolata-Regular.ttf +0 -0
- package/docs/fonts/OpenSans-Regular.ttf +0 -0
- package/docs/fonts/WorkSans-Bold.ttf +0 -0
- package/docs/global.html +1 -1
- package/docs/index.html +0 -0
- package/docs/index.js.html +130 -21
- package/docs/scripts/core.js +0 -0
- package/docs/scripts/core.min.js +0 -0
- package/docs/scripts/resize.js +0 -0
- package/docs/scripts/search.js +0 -0
- package/docs/scripts/search.min.js +0 -0
- package/docs/scripts/third-party/Apache-License-2.0.txt +0 -0
- package/docs/scripts/third-party/fuse.js +0 -0
- package/docs/scripts/third-party/hljs-line-num-original.js +0 -0
- package/docs/scripts/third-party/hljs-line-num.js +0 -0
- package/docs/scripts/third-party/hljs-original.js +0 -0
- package/docs/scripts/third-party/hljs.js +0 -0
- package/docs/scripts/third-party/popper.js +0 -0
- package/docs/scripts/third-party/tippy.js +0 -0
- package/docs/scripts/third-party/tocbot.js +0 -0
- package/docs/scripts/third-party/tocbot.min.js +0 -0
- package/docs/static/bitcoin.jpeg +0 -0
- package/docs/static/home.md +0 -0
- package/docs/static/logo-ecosystem.png +0 -0
- package/docs/static/logo.png +0 -0
- package/docs/styles/clean-jsdoc-theme-base.css +0 -0
- package/docs/styles/clean-jsdoc-theme-dark.css +0 -0
- package/docs/styles/clean-jsdoc-theme-light.css +0 -0
- package/docs/styles/clean-jsdoc-theme-scrollbar.css +0 -0
- package/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +0 -0
- package/docs/styles/clean-jsdoc-theme.min.css +0 -0
- package/extend/bajo/hook/waibu-rest-api@after-init.js +3 -2
- package/extend/bajo/intl/en-US.json +0 -0
- package/extend/bajo/intl/id.json +0 -0
- package/extend/bajoTemplate/partial/crud/_add-attachment.html +0 -0
- package/extend/bajoTemplate/partial/crud/_add-btns.html +2 -2
- package/extend/bajoTemplate/partial/crud/_addons.html +0 -0
- package/extend/bajoTemplate/partial/crud/_details-attachment.html +0 -0
- package/extend/bajoTemplate/partial/crud/_details-btns.html +0 -0
- package/extend/bajoTemplate/partial/crud/_edit-attachment.html +0 -0
- package/extend/bajoTemplate/partial/crud/_edit-btns.html +2 -0
- package/extend/bajoTemplate/partial/crud/_list-attachment.html +0 -0
- package/extend/bajoTemplate/partial/crud/_list-btns.html +0 -0
- package/extend/bajoTemplate/partial/crud/_list-footer.html +0 -0
- package/extend/bajoTemplate/partial/crud/add-handler.html +0 -0
- package/extend/bajoTemplate/partial/crud/details-handler.html +0 -0
- package/extend/bajoTemplate/partial/crud/edit-handler.html +0 -0
- package/extend/bajoTemplate/partial/crud/list-handler.html +1 -1
- package/extend/bajoTemplate/partial/crud/~echarts-window.html +0 -0
- package/extend/bajoTemplate/template/crud/add.html +0 -0
- package/extend/bajoTemplate/template/crud/details.html +0 -0
- package/extend/bajoTemplate/template/crud/edit.html +0 -0
- package/extend/bajoTemplate/template/crud/list.html +0 -0
- package/extend/bajoTemplate/template/disabled.html +0 -0
- package/extend/waibuBootstrap/theme/component/wdb-base.js +1 -1
- package/extend/waibuBootstrap/theme/component/{factory → widget}/btn-add.js +0 -0
- package/extend/waibuBootstrap/theme/component/{factory → widget}/btn-back.js +1 -1
- package/extend/waibuBootstrap/theme/component/{factory → widget}/btn-clone.js +0 -0
- package/extend/waibuBootstrap/theme/component/{factory → widget}/btn-columns.js +2 -2
- package/extend/waibuBootstrap/theme/component/{factory → widget}/btn-delete.js +1 -1
- package/extend/waibuBootstrap/theme/component/{factory → widget}/btn-details.js +1 -1
- package/extend/waibuBootstrap/theme/component/{factory → widget}/btn-edit.js +1 -1
- package/extend/waibuBootstrap/theme/component/{factory → widget}/btn-export.js +0 -0
- package/extend/waibuBootstrap/theme/component/{factory → widget}/echarts-bar.js +1 -1
- package/extend/waibuBootstrap/theme/component/{factory → widget}/echarts-pie.js +1 -1
- package/extend/waibuBootstrap/theme/component/{factory → widget}/echarts.js +2 -2
- package/extend/waibuBootstrap/theme/component/{factory → widget}/form.js +1 -1
- package/extend/waibuBootstrap/theme/component/{factory → widget}/pagination.js +1 -1
- package/extend/waibuBootstrap/theme/component/{factory → widget}/query.js +3 -3
- package/extend/waibuBootstrap/theme/component/{factory → widget}/recs-info.js +1 -1
- package/extend/waibuBootstrap/theme/component/{factory → widget}/table.js +7 -7
- package/extend/waibuMpa/extend/waibuAdmin/route/@model/@action.js +0 -0
- package/extend/waibuRestApi/route/@model/@id/get.js +1 -1
- package/extend/waibuRestApi/route/@model/@id/remove.js +1 -1
- package/extend/waibuRestApi/route/@model/@id/update.js +1 -1
- package/extend/waibuRestApi/route/@model/create.js +1 -1
- package/extend/waibuRestApi/route/@model/find.js +2 -2
- package/extend/waibuRestApi/route/@model/stat/@stat/find.js +8 -0
- package/index.js +127 -21
- package/lib/crud/add-handler.js +8 -7
- package/lib/crud/all-handler.js +0 -0
- package/lib/crud/delete-handler.js +4 -3
- package/lib/crud/details-handler.js +4 -4
- package/lib/crud/edit-handler.js +7 -8
- package/lib/crud/export-handler.js +3 -3
- package/lib/crud/helper/add-ons-handler.js +2 -2
- package/lib/crud/helper/attachment-handler.js +2 -2
- package/lib/crud/helper/build-params.js +3 -4
- package/lib/crud/list-handler.js +3 -3
- package/lib/method/count-record.js +9 -0
- package/lib/method/create-aggregate.js +13 -0
- package/lib/method/create-histogram.js +13 -0
- package/lib/method/create-record.js +10 -0
- package/lib/method/find-one-record.js +14 -0
- package/lib/method/find-record.js +14 -0
- package/lib/method/get-record.js +10 -0
- package/{method → lib/method}/get-schema-ext.js +6 -7
- package/lib/method/remove-record.js +9 -0
- package/lib/method/update-record.js +10 -0
- package/lib/prep-crud.js +8 -9
- package/package.json +8 -2
- package/wiki/CHANGES.md +9 -0
- package/wiki/CONFIG.md +0 -0
- package/wiki/CONTRIBUTING.md +0 -0
- package/method/format-record.js +0 -41
- package/method/get-lookup-data.js +0 -13
- package/method/get-params.js +0 -18
- package/method/method-map.js +0 -9
- package/method/record/count.js +0 -10
- package/method/record/create.js +0 -11
- package/method/record/find-one.js +0 -15
- package/method/record/find.js +0 -15
- package/method/record/get.js +0 -11
- package/method/record/remove.js +0 -10
- package/method/record/update.js +0 -11
- package/method/stat/aggregate.js +0 -14
- package/method/stat/histogram.js +0 -14
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
async function attachmentHandler ({ schema, id, options = {} }) {
|
|
2
|
-
const { listAttachments } = this.app.dobo
|
|
3
2
|
if (!schema.view.attachment) return []
|
|
4
|
-
|
|
3
|
+
const model = this.app.dobo.getModel(schema.name)
|
|
4
|
+
return await model.listAttachment({ id })
|
|
5
5
|
}
|
|
6
6
|
|
|
7
7
|
export default attachmentHandler
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
function buildParams ({ model, req, reply, action, options = {} }) {
|
|
2
2
|
const { camelCase, kebabCase, map, upperFirst, get } = this.app.lib._
|
|
3
|
-
const { getSchema } = this.app.dobo
|
|
4
3
|
const [, ...names] = map(kebabCase(model).split('-'), n => upperFirst(n))
|
|
5
|
-
const
|
|
6
|
-
const modelTitle = this.app[
|
|
4
|
+
const mdl = this.app.dobo.getModel(model)
|
|
5
|
+
const modelTitle = this.app[mdl.plugin.ns].title + ': ' + req.t(camelCase(names.join(' ')))
|
|
7
6
|
const page = {
|
|
8
|
-
title: req.t(get(req, 'routeOptions.config.title', this.app[
|
|
7
|
+
title: req.t(get(req, 'routeOptions.config.title', this.app[mdl.plugin.ns].title)),
|
|
9
8
|
modelTitle
|
|
10
9
|
}
|
|
11
10
|
return { page }
|
package/lib/crud/list-handler.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
async function listHandler ({ req, reply, model, template, params = {}, addOnsHandler, templateDisabled = 'waibuDb.template:/disabled.html', options = {} } = {}) {
|
|
2
2
|
const { pascalCase } = this.app.lib.aneka
|
|
3
|
-
const {
|
|
3
|
+
const { findRecord, getSchemaExt } = this.app.waibuDb
|
|
4
4
|
const { get, merge, isArray, upperFirst } = this.app.lib._
|
|
5
5
|
const qsKey = this.app.waibu.config.qsKey
|
|
6
|
-
model = model ??
|
|
6
|
+
model = pascalCase(model ?? req.params.model)
|
|
7
7
|
const { schema } = await getSchemaExt(model, 'list', merge({}, { params }, options))
|
|
8
8
|
if (schema.disabled.includes('find')) return await reply.view(templateDisabled, { action: 'list' })
|
|
9
9
|
for (const key of ['sort', 'limit', 'fields']) {
|
|
@@ -13,7 +13,7 @@ async function listHandler ({ req, reply, model, template, params = {}, addOnsHa
|
|
|
13
13
|
}
|
|
14
14
|
if (!req.query[qsKey.page]) req.query[qsKey.page] = 1
|
|
15
15
|
// req.query.attachment = true
|
|
16
|
-
const list = await
|
|
16
|
+
const list = await findRecord({ model, req, options: { count: true, refs: '*' } })
|
|
17
17
|
let addOns = []
|
|
18
18
|
if (addOnsHandler) {
|
|
19
19
|
addOns = await addOnsHandler.call(this.app[req.ns], { req, reply, params, data: list, schema, options })
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import prepCrud from '../prep-crud.js'
|
|
2
|
+
|
|
3
|
+
async function countRecord ({ model, req, reply, options = {} }) {
|
|
4
|
+
const { model: mdl, opts, filter } = await prepCrud.call(this, { model, req, reply, options, args: ['model'] })
|
|
5
|
+
const ret = await mdl.countRecord(filter, opts)
|
|
6
|
+
return ret
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default countRecord
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import prepCrud from '../prep-crud.js'
|
|
2
|
+
|
|
3
|
+
async function createAggregate ({ model, req, reply, options = {} }) {
|
|
4
|
+
const { model: mdl, opts, filter } = await prepCrud.call(this, { model, req, reply, options, args: ['model'] })
|
|
5
|
+
const params = {}
|
|
6
|
+
for (const item of ['group', 'field', 'aggregates']) {
|
|
7
|
+
params[item] = options[item] ?? req.params[item] ?? req.query[item]
|
|
8
|
+
}
|
|
9
|
+
params.aggregates = params.aggregates ?? ['count']
|
|
10
|
+
return await mdl.createAggregate(filter, params, opts)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default createAggregate
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import prepCrud from '../prep-crud.js'
|
|
2
|
+
|
|
3
|
+
async function createHistogram ({ model, req, reply, options = {} }) {
|
|
4
|
+
const { model: mdl, opts, filter } = await prepCrud.call(this, { model, req, reply, options, args: ['model'] })
|
|
5
|
+
const params = {}
|
|
6
|
+
for (const item of ['type', 'group', 'field', 'aggregates']) {
|
|
7
|
+
params[item] = options[item] ?? req.params[item] ?? req.query[item]
|
|
8
|
+
}
|
|
9
|
+
params.aggregates = params.aggregates ?? ['count']
|
|
10
|
+
return await mdl.createHistogram(filter, params, opts)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default createHistogram
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import prepCrud from '../prep-crud.js'
|
|
2
|
+
|
|
3
|
+
async function createRecord ({ model, req, reply, body, options = {} }) {
|
|
4
|
+
const { model: mdl, input, opts, attachment, stats, mimeType } = await prepCrud.call(this, { model, req, reply, body, options, args: ['model'] })
|
|
5
|
+
const ret = await mdl.createRecord(input, opts)
|
|
6
|
+
if (attachment) ret.data._attachment = await mdl.findAttachment(ret.data.id, { stats, mimeType })
|
|
7
|
+
return ret
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default createRecord
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import prepCrud from '../prep-crud.js'
|
|
2
|
+
|
|
3
|
+
async function findOneRecord ({ model, req, reply, options = {} }) {
|
|
4
|
+
const { model: mdl, opts, filter, attachment, stats, mimeType } = await prepCrud.call(this, { model, req, reply, options, args: ['model'] })
|
|
5
|
+
const ret = await mdl.findOneRecord(filter, opts)
|
|
6
|
+
if (attachment) {
|
|
7
|
+
for (const d of ret.data) {
|
|
8
|
+
d._attachment = await mdl.findAttachment(d.id, { stats, mimeType })
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return ret
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default findOneRecord
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import prepCrud from '../prep-crud.js'
|
|
2
|
+
|
|
3
|
+
async function findRecord ({ model, req, reply, options = {} }) {
|
|
4
|
+
const { model: mdl, opts, filter, attachment, stats, mimeType } = await prepCrud.call(this, { model, req, reply, options, args: ['model'] })
|
|
5
|
+
const ret = await mdl.findRecord(filter, opts)
|
|
6
|
+
if (attachment) {
|
|
7
|
+
for (const d of ret.data) {
|
|
8
|
+
d._attachment = await mdl.findAttachment(d.id, { stats, mimeType })
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return ret
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default findRecord
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import prepCrud from '../prep-crud.js'
|
|
2
|
+
|
|
3
|
+
async function getRecord ({ model, req, reply, id, options = {} }) {
|
|
4
|
+
const { model: mdl, recId, filter, opts } = await prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'] })
|
|
5
|
+
filter.query = { $and: [filter.query ?? {}, { id: recId }] }
|
|
6
|
+
const ret = await mdl.findOneRecord(filter, opts)
|
|
7
|
+
return ret
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default getRecord
|
|
@@ -167,19 +167,18 @@ const handler = {
|
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
|
|
170
|
-
async function getSchemaExt (
|
|
170
|
+
async function getSchemaExt (modelName, view, options = {}) {
|
|
171
171
|
const { readConfig } = this.app.bajo
|
|
172
172
|
const { defaultsDeep } = this.app.lib.aneka
|
|
173
|
-
const { getSchema } = this.app.dobo
|
|
174
173
|
const { pick } = this.app.lib._
|
|
175
174
|
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
175
|
+
const model = this.app.dobo.getModel(modelName)
|
|
176
|
+
const schema = pick(model, ['name', 'properties', 'indexes', 'disabled', 'attachment', 'sortables', 'view', 'hidden'])
|
|
177
|
+
const base = path.basename(model.file, path.extname(model.file))
|
|
178
|
+
let ext = await readConfig(`${model.plugin.ns}:/extend/waibuDb/schema/${base}.*`, { ignoreError: true, options })
|
|
179
|
+
const over = await readConfig(`main:/extend/waibuDb/extend/${model.plugin.ns}/schema/${base}.*`, { ignoreError: true, options })
|
|
180
180
|
ext = defaultsDeep(options.schema ?? {}, over, ext)
|
|
181
181
|
await handler[view].call(this, schema, ext, options)
|
|
182
|
-
schema = pick(schema, ['name', 'properties', 'indexes', 'disabled', 'attachment', 'sortables', 'view'])
|
|
183
182
|
return { schema, ext }
|
|
184
183
|
}
|
|
185
184
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import prepCrud from '../prep-crud.js'
|
|
2
|
+
|
|
3
|
+
async function removeRecord ({ model, req, reply, id, options = {} }) {
|
|
4
|
+
const { model: mdl, recId, opts } = await prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'] })
|
|
5
|
+
const result = await mdl.removeRecord(recId, opts)
|
|
6
|
+
return result
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default removeRecord
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import prepCrud from '../prep-crud.js'
|
|
2
|
+
|
|
3
|
+
async function updateRecord ({ model, req, reply, id, body, options = {} }) {
|
|
4
|
+
const { model: mdl, input, opts, recId, attachment, stats, mimeType } = await prepCrud.call(this, { model, req, reply, body, id, options, args: ['model', 'id'] })
|
|
5
|
+
const ret = await mdl.updateRecord(recId, input, opts)
|
|
6
|
+
if (attachment) ret.data._attachment = await mdl.findAttachment(id, { stats, mimeType })
|
|
7
|
+
return ret
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default updateRecord
|
package/lib/prep-crud.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
function prepCrud ({ model, body, id, req, reply, options = {}, args }) {
|
|
1
|
+
async function prepCrud ({ model, body, id, req, reply, options = {}, args }) {
|
|
2
2
|
const { parseFilter } = this.app.waibu
|
|
3
|
-
const { buildQuery, getInfo } = this.app.dobo
|
|
4
3
|
const { pascalCase } = this.app.lib.aneka
|
|
5
|
-
const { cloneDeep, has } = this.app.lib._
|
|
4
|
+
const { cloneDeep, has, pick } = this.app.lib._
|
|
6
5
|
const cfgWeb = this.app.waibu.getConfig()
|
|
7
6
|
const opts = cloneDeep(options)
|
|
8
7
|
const params = this.getParams(req, ...args)
|
|
@@ -20,18 +19,18 @@ function prepCrud ({ model, body, id, req, reply, options = {}, args }) {
|
|
|
20
19
|
mimeType = mimeType ?? req.query.mimeType
|
|
21
20
|
|
|
22
21
|
const recId = id ?? params.id ?? req.query.id
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
const input = body ?? params.body
|
|
22
|
+
model = model ?? pascalCase(params.model)
|
|
23
|
+
const mdl = this.app.dobo.getModel(model)
|
|
24
|
+
const input = await mdl.sanitizeBody({ body: body ?? params.body, partial: true, strict: true })
|
|
25
|
+
|
|
26
26
|
opts.bboxLatField = req.query[cfgWeb.qsKey.bboxLatField]
|
|
27
27
|
opts.bboxLngField = req.query[cfgWeb.qsKey.bboxLngField]
|
|
28
|
-
const filter = parseFilter(req)
|
|
28
|
+
const filter = pick(parseFilter(req), ['query', 'match', 'limit', 'sort', 'page', 'skip'])
|
|
29
29
|
if (options.query) filter.query = cloneDeep(options.query)
|
|
30
30
|
if (options.limit) filter.limit = options.limit
|
|
31
31
|
if (options.sort) filter.sort = options.sort
|
|
32
32
|
if (options.page) filter.page = options.page
|
|
33
|
-
|
|
34
|
-
return { name, recId, input, opts, filter, attachment, stats, mimeType }
|
|
33
|
+
return { model: mdl, recId, input, opts, filter, attachment, stats, mimeType }
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
export default prepCrud
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "waibu-db",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "DB Helper",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,13 @@
|
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
11
|
"bajo": {
|
|
12
|
-
"type": "plugin"
|
|
12
|
+
"type": "plugin",
|
|
13
|
+
"alias": "wdb",
|
|
14
|
+
"dependencies": [
|
|
15
|
+
"dobo",
|
|
16
|
+
"waibu",
|
|
17
|
+
"dobo-extra"
|
|
18
|
+
]
|
|
13
19
|
},
|
|
14
20
|
"repository": {
|
|
15
21
|
"type": "git",
|
package/wiki/CHANGES.md
ADDED
package/wiki/CONFIG.md
CHANGED
|
File without changes
|
package/wiki/CONTRIBUTING.md
CHANGED
|
File without changes
|
package/method/format-record.js
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
async function formatRow ({ data, req, schema, options = {} }) {
|
|
2
|
-
const { get, find, isFunction, cloneDeep } = this.app.lib._
|
|
3
|
-
const { format, callHandler } = this.app.bajo
|
|
4
|
-
const { escape } = this.app.waibu
|
|
5
|
-
const fields = get(schema, 'view.fields', Object.keys(schema.properties))
|
|
6
|
-
const rec = cloneDeep(data)
|
|
7
|
-
for (const f of fields) {
|
|
8
|
-
if (f === '_rel') continue
|
|
9
|
-
let prop = find(schema.properties, { name: f })
|
|
10
|
-
if (!prop) prop = find(schema.view.calcFields, { name: f })
|
|
11
|
-
if (!prop) continue
|
|
12
|
-
const opts = {
|
|
13
|
-
lang: options.lang ?? (req ? req.lang : undefined),
|
|
14
|
-
longitude: ['lng', 'longitude'].includes(f),
|
|
15
|
-
latitude: ['lat', 'latitude'].includes(f),
|
|
16
|
-
speed: ['speed'].includes(f),
|
|
17
|
-
degree: ['course', 'heading'].includes(f),
|
|
18
|
-
distance: ['distance'].includes(f)
|
|
19
|
-
}
|
|
20
|
-
rec[f] = format(data[f], prop.type, opts)
|
|
21
|
-
const vf = get(schema, `view.valueFormatter.${f}`)
|
|
22
|
-
if (vf) {
|
|
23
|
-
if (isFunction(vf)) rec[f] = await vf.call(this, data[f], data)
|
|
24
|
-
else rec[f] = await callHandler(vf, { req, value: data[f], data })
|
|
25
|
-
} else if (['string', 'text'].includes(prop.type)) rec[f] = escape(rec[f])
|
|
26
|
-
}
|
|
27
|
-
return rec
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async function formatRecord ({ data, req, schema, options = {} }) {
|
|
31
|
-
const { isArray } = this.app.lib._
|
|
32
|
-
if (!isArray(data)) return await formatRow.call(this, { data, req, schema, options })
|
|
33
|
-
const items = []
|
|
34
|
-
for (const d of data) {
|
|
35
|
-
const item = await formatRow.call(this, { data: d, req, schema, options })
|
|
36
|
-
items.push(item)
|
|
37
|
-
}
|
|
38
|
-
return items
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export default formatRecord
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
async function getLookupData ({ model, req, data, id = 'id', field, query }) {
|
|
2
|
-
const { set, map } = this.app.lib._
|
|
3
|
-
const $in = map(data, id)
|
|
4
|
-
const q = query ?? set({}, field, { $in })
|
|
5
|
-
const options = {
|
|
6
|
-
dataOnly: true,
|
|
7
|
-
limit: -1,
|
|
8
|
-
query: q
|
|
9
|
-
}
|
|
10
|
-
return await this.recordFind({ model, req, options })
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export default getLookupData
|
package/method/get-params.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
function getParams (req, ...items) {
|
|
2
|
-
const { map, trim, get } = this.app.lib._
|
|
3
|
-
let fields
|
|
4
|
-
req.query = req.query ?? {}
|
|
5
|
-
req.params = req.params ?? {}
|
|
6
|
-
if (req.query.fields) fields = map((req.query.fields ?? '').split(','), i => trim(i))
|
|
7
|
-
const params = {
|
|
8
|
-
fields,
|
|
9
|
-
count: get(this, 'config.dbModel.count', false),
|
|
10
|
-
body: req.body
|
|
11
|
-
}
|
|
12
|
-
items.forEach(i => {
|
|
13
|
-
params[i] = req.params[i]
|
|
14
|
-
})
|
|
15
|
-
return params
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default getParams
|
package/method/method-map.js
DELETED
package/method/record/count.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import prepCrud from '../../lib/prep-crud.js'
|
|
2
|
-
|
|
3
|
-
async function count ({ model, req, reply, options = {} }) {
|
|
4
|
-
const { recordCount } = this.app.dobo
|
|
5
|
-
const { name, opts, filter } = prepCrud.call(this, { model, req, reply, options, args: ['model'] })
|
|
6
|
-
const ret = await recordCount(name, filter, opts)
|
|
7
|
-
return ret
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default count
|
package/method/record/create.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import prepCrud from '../../lib/prep-crud.js'
|
|
2
|
-
|
|
3
|
-
async function create ({ model, req, reply, body, options = {} }) {
|
|
4
|
-
const { recordCreate, attachmentFind } = this.app.dobo
|
|
5
|
-
const { name, input, opts, attachment, stats, mimeType } = prepCrud.call(this, { model, req, reply, body, options, args: ['model'] })
|
|
6
|
-
const ret = await recordCreate(name, input, opts)
|
|
7
|
-
if (attachment) ret.data._attachment = await attachmentFind(name, ret.data.id, { stats, mimeType })
|
|
8
|
-
return ret
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default create
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import prepCrud from '../../lib/prep-crud.js'
|
|
2
|
-
|
|
3
|
-
async function find ({ model, req, reply, options = {} }) {
|
|
4
|
-
const { recordFindOne, attachmentFind } = this.app.dobo
|
|
5
|
-
const { name, opts, filter, attachment, stats, mimeType } = prepCrud.call(this, { model, req, reply, options, args: ['model'] })
|
|
6
|
-
const ret = await recordFindOne(name, filter, opts)
|
|
7
|
-
if (attachment) {
|
|
8
|
-
for (const d of ret.data) {
|
|
9
|
-
d._attachment = await attachmentFind(name, d.id, { stats, mimeType })
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return ret
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default find
|
package/method/record/find.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import prepCrud from '../../lib/prep-crud.js'
|
|
2
|
-
|
|
3
|
-
async function find ({ model, req, reply, options = {} }) {
|
|
4
|
-
const { recordFind, attachmentFind } = this.app.dobo
|
|
5
|
-
const { name, opts, filter, attachment, stats, mimeType } = prepCrud.call(this, { model, req, reply, options, args: ['model'] })
|
|
6
|
-
const ret = await recordFind(name, filter, opts)
|
|
7
|
-
if (attachment) {
|
|
8
|
-
for (const d of ret.data) {
|
|
9
|
-
d._attachment = await attachmentFind(name, d.id, { stats, mimeType })
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return ret
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default find
|
package/method/record/get.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import prepCrud from '../../lib/prep-crud.js'
|
|
2
|
-
|
|
3
|
-
async function get ({ model, req, reply, id, options = {} }) {
|
|
4
|
-
const { recordFindOne } = this.app.dobo
|
|
5
|
-
const { name, recId, filter, opts } = prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'] })
|
|
6
|
-
filter.query = { $and: [filter.query ?? {}, { id: recId }] }
|
|
7
|
-
const ret = await recordFindOne(name, filter, opts)
|
|
8
|
-
return ret
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default get
|
package/method/record/remove.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import prepCrud from '../../lib/prep-crud.js'
|
|
2
|
-
|
|
3
|
-
async function remove ({ model, req, reply, id, options = {} }) {
|
|
4
|
-
const { recordRemove } = this.app.dobo
|
|
5
|
-
const { name, recId, opts } = prepCrud.call(this, { model, req, reply, id, options, args: ['model', 'id'] })
|
|
6
|
-
const result = await recordRemove(name, recId, opts)
|
|
7
|
-
return result
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export default remove
|
package/method/record/update.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import prepCrud from '../../lib/prep-crud.js'
|
|
2
|
-
|
|
3
|
-
async function update ({ model, req, reply, id, body, options = {} }) {
|
|
4
|
-
const { recordUpdate, attachmentFind } = this.app.dobo
|
|
5
|
-
const { name, input, opts, recId, attachment, stats, mimeType } = prepCrud.call(this, { model, req, reply, body, id, options, args: ['model', 'id'] })
|
|
6
|
-
const ret = await recordUpdate(name, recId, input, opts)
|
|
7
|
-
if (attachment) ret.data._attachment = await attachmentFind(name, id, { stats, mimeType })
|
|
8
|
-
return ret
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default update
|
package/method/stat/aggregate.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import prepCrud from '../../lib/prep-crud.js'
|
|
2
|
-
|
|
3
|
-
async function aggregate ({ model, req, reply, options = {} }) {
|
|
4
|
-
const { statAggregate } = this.app.dobo
|
|
5
|
-
const { parseFilter } = this.app.waibu
|
|
6
|
-
const { name, opts } = prepCrud.call(this, { model, req, reply, options, args: ['model'] })
|
|
7
|
-
for (const item of ['group', 'aggregate']) {
|
|
8
|
-
opts[item] = options[item] ?? req.params[item] ?? req.query[item]
|
|
9
|
-
}
|
|
10
|
-
opts.aggregate = opts.aggregate ?? 'count'
|
|
11
|
-
return await statAggregate(name, parseFilter(req), opts)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default aggregate
|
package/method/stat/histogram.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import prepCrud from '../../lib/prep-crud.js'
|
|
2
|
-
|
|
3
|
-
async function histogram ({ model, req, reply, options = {} }) {
|
|
4
|
-
const { statHistogram } = this.app.dobo
|
|
5
|
-
const { parseFilter } = this.app.waibu
|
|
6
|
-
const { name, opts } = prepCrud.call(this, { model, req, reply, options, args: ['model'] })
|
|
7
|
-
for (const item of ['type', 'group', 'aggregate']) {
|
|
8
|
-
opts[item] = options[item] ?? req.params[item] ?? req.query[item]
|
|
9
|
-
}
|
|
10
|
-
opts.aggregate = opts.aggregate ?? 'count'
|
|
11
|
-
return await statHistogram(name, parseFilter(req), opts)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export default histogram
|