-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindone.js
31 lines (25 loc) · 829 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
import { CollectionHooks } from './collection-hooks'
CollectionHooks.defineAdvice('findOne', function (userId, _super, instance, aspects, getTransform, args, suppressAspects) {
const ctx = { context: this, _super, args }
const selector = CollectionHooks.normalizeSelector(instance._getFindSelector(args))
const options = instance._getFindOptions(args)
let abort
// before
if (!suppressAspects) {
aspects.before.forEach((o) => {
const r = o.aspect.call(ctx, userId, selector, options)
if (r === false) abort = true
})
if (abort) return
}
function after (doc) {
if (!suppressAspects) {
aspects.after.forEach((o) => {
o.aspect.call(ctx, userId, selector, options, doc)
})
}
}
const ret = _super.call(this, selector, options)
after(ret)
return ret
})