waibu-db 2.10.2 → 2.10.3
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/lib/method/get-record.js +1 -1
- package/lib/method/remove-record.js +2 -1
- package/lib/method/update-record.js +2 -1
- package/lib/util.js +3 -3
- package/package.json +1 -1
- package/wiki/CHANGES.md +4 -0
package/lib/method/get-record.js
CHANGED
|
@@ -8,7 +8,7 @@ async function getRecord ({ model, req, reply, id, options = {}, transaction } =
|
|
|
8
8
|
opts.trx = opts.trx || trx
|
|
9
9
|
const data = await getOneRecord.call(me, mdl, recId, filter, opts)
|
|
10
10
|
if (attachment) data._attachment = await mdl.findAttachment(data.id, { stats, mimeType })
|
|
11
|
-
return
|
|
11
|
+
return data
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
return opts.trx === true ? await mdl.transaction(handler) : await handler()
|
|
@@ -6,7 +6,8 @@ async function removeRecord ({ model, req, reply, id, options = {}, transaction
|
|
|
6
6
|
|
|
7
7
|
async function handler (trx) {
|
|
8
8
|
opts.trx = opts.trx || trx
|
|
9
|
-
|
|
9
|
+
const resp = await getOneRecord.call(me, mdl, recId, filter, opts)
|
|
10
|
+
opts._data = resp.data
|
|
10
11
|
return await mdl.removeRecord(recId, opts)
|
|
11
12
|
}
|
|
12
13
|
|
|
@@ -6,7 +6,8 @@ async function updateRecord ({ model, req, reply, id, body, options = {}, transa
|
|
|
6
6
|
|
|
7
7
|
async function handler (trx) {
|
|
8
8
|
opts.trx = opts.trx || trx
|
|
9
|
-
|
|
9
|
+
const resp = await getOneRecord.call(me, mdl, recId, filter, opts)
|
|
10
|
+
opts._data = resp.data
|
|
10
11
|
const ret = await mdl.updateRecord(recId, input, opts)
|
|
11
12
|
if (attachment) ret.data._attachment = await mdl.findAttachment(id, { stats, mimeType })
|
|
12
13
|
return ret
|
package/lib/util.js
CHANGED
|
@@ -54,12 +54,12 @@ export async function prepCrud ({ model, body, id, req, reply, transaction, opti
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
export async function getOneRecord (model, id, filter, options) {
|
|
57
|
-
const { cloneDeep, pick } = this.app.lib._
|
|
57
|
+
const { cloneDeep, pick, isEmpty } = this.app.lib._
|
|
58
58
|
let query = cloneDeep(filter.query || {})
|
|
59
59
|
query = { $and: [query, { id }] }
|
|
60
60
|
const opts = pick(options, ['forceNoHidden', 'trx', 'req', 'refs'])
|
|
61
|
-
opts.dataOnly =
|
|
61
|
+
opts.dataOnly = false
|
|
62
62
|
const data = await model.findOneRecord({ query }, opts)
|
|
63
|
-
if (
|
|
63
|
+
if (isEmpty(data.data) && options.throwNotFound) throw this.error('_notFound')
|
|
64
64
|
return data
|
|
65
65
|
}
|
package/package.json
CHANGED