-
-
Notifications
You must be signed in to change notification settings - Fork 93
/
Copy pathfindone.js
33 lines (28 loc) · 883 Bytes
/
findone.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { CollectionHooks } from './collection-hooks'
CollectionHooks.defineWrapper('findOne', async function (userId, _super, instance, hooks, getTransform, args, suppressHooks) {
const ctx = { context: this, _super, args }
const selector = CollectionHooks.normalizeSelector(instance._getFindSelector(args))
const options = instance._getFindOptions(args)
let abort
// before
if (!suppressHooks) {
for (const o of hooks.before) {
const r = await o.hook.call(ctx, userId, selector, options)
if (r === false) {
abort = true
break
}
}
if (abort) return
}
async function after (doc) {
if (!suppressHooks) {
for (const o of hooks.after) {
await o.hook.call(ctx, userId, selector, options, doc)
}
}
}
const ret = await _super.call(this, selector, options)
await after(ret)
return ret
})