sumba 0.3.3 → 0.3.5
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/bajo/hook/bajoDb@on-before-record-create.js +3 -3
- package/bajo/hook/bajoDb@on-before-record-find-one.js +8 -0
- package/bajo/hook/bajoDb@on-before-record-find.js +21 -18
- package/bajo/hook/bajoDb@on-before-record-get.js +4 -3
- package/bajo/hook/bajoDb@on-before-record-update.js +1 -1
- package/bajo/init.js +11 -0
- package/bajoAdmin/coll/user.json +2 -0
- package/lib/check-user-id.js +1 -2
- package/lib/collect-routes.js +1 -1
- package/package.json +1 -1
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
const bajoDbOnBeforeRecordCreate = {
|
|
2
2
|
level: 1000,
|
|
3
3
|
handler: async function (coll, body, options) {
|
|
4
|
-
const { importPkg } = this.bajo.helper
|
|
5
4
|
const { get } = this.bajo.helper._
|
|
6
5
|
const { hasColumn } = this.sumba.helper
|
|
7
|
-
|
|
6
|
+
if (options.noAutoFilter) return
|
|
7
|
+
const item = { siteId: 'site.id', userId: 'user.id' }
|
|
8
8
|
for (const i in item) {
|
|
9
|
-
const rec = get(options, item[i])
|
|
9
|
+
const rec = get(options.req, item[i])
|
|
10
10
|
if (rec && await hasColumn(i, coll)) body[i] = rec
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -1,23 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
if (isEmpty(filter.query)) filter.query = undefined
|
|
18
|
-
}
|
|
1
|
+
export async function handler (coll, filter, options) {
|
|
2
|
+
const { isSet } = this.bajo.helper
|
|
3
|
+
const { isEmpty, cloneDeep, get, set } = this.bajo.helper._
|
|
4
|
+
const { hasColumn } = this.sumba.helper
|
|
5
|
+
if (options.noAutoFilter) return
|
|
6
|
+
const item = { siteId: 'site.id', userId: 'user.id' }
|
|
7
|
+
for (const i in item) {
|
|
8
|
+
const rec = get(options.req, item[i])
|
|
9
|
+
if (isSet(rec) && await hasColumn(i, coll)) {
|
|
10
|
+
filter.query = filter.query ?? {}
|
|
11
|
+
const old = cloneDeep(filter.query.$or)
|
|
12
|
+
if (old) {
|
|
13
|
+
filter.query = { $and: [old] }
|
|
14
|
+
filter.query.$and.push(set({}, i, rec))
|
|
15
|
+
} else filter.query[i] = rec
|
|
16
|
+
if (isEmpty(filter.query)) filter.query = undefined
|
|
19
17
|
}
|
|
20
18
|
}
|
|
21
19
|
}
|
|
22
20
|
|
|
21
|
+
const bajoDbOnBeforeRecordFind = {
|
|
22
|
+
level: 1000,
|
|
23
|
+
handler
|
|
24
|
+
}
|
|
25
|
+
|
|
23
26
|
export default bajoDbOnBeforeRecordFind
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
export async function checker (coll, id,
|
|
1
|
+
export async function checker (coll, id, options) {
|
|
2
2
|
const { error } = this.bajo.helper
|
|
3
3
|
const { recordFind } = this.bajoDb.helper
|
|
4
4
|
const { get } = this.bajo.helper._
|
|
5
5
|
const { hasColumn } = this.sumba.helper
|
|
6
|
+
if (options.noAutoFilter) return
|
|
6
7
|
const item = { siteId: 'site.id', userId: 'user.id' }
|
|
7
8
|
for (const i in item) {
|
|
8
|
-
const rec = get(req, item[i])
|
|
9
|
+
const rec = get(options.req, item[i])
|
|
9
10
|
if (rec && await hasColumn(i, coll)) {
|
|
10
11
|
const filter = { query: { id }, limit: 1 }
|
|
11
12
|
filter.query[i] = rec
|
|
@@ -18,7 +19,7 @@ export async function checker (coll, id, req) {
|
|
|
18
19
|
const bajoDbOnBeforeRecordGet = {
|
|
19
20
|
level: 1000,
|
|
20
21
|
handler: async function (coll, id, options) {
|
|
21
|
-
await checker.call(this, coll, id, options
|
|
22
|
+
await checker.call(this, coll, id, options)
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
|
|
@@ -3,7 +3,7 @@ import { checker } from './bajoDb@on-before-record-get.js'
|
|
|
3
3
|
const bajoDbOnBeforeRecordUpdate = {
|
|
4
4
|
level: 1000,
|
|
5
5
|
handler: async function (coll, id, body, options) {
|
|
6
|
-
await checker.call(this, coll, id, options
|
|
6
|
+
await checker.call(this, coll, id, options)
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
|
package/bajo/init.js
ADDED
package/bajoAdmin/coll/user.json
CHANGED
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
}]
|
|
52
52
|
},
|
|
53
53
|
"edit": {
|
|
54
|
+
"shown": ["password"],
|
|
54
55
|
"layouts": [{
|
|
55
56
|
"title": "Meta Info",
|
|
56
57
|
"fields": [
|
|
@@ -65,6 +66,7 @@
|
|
|
65
66
|
"fields": [
|
|
66
67
|
"username;small:6,medium:6",
|
|
67
68
|
"email;small:6,medium:6",
|
|
69
|
+
"password;small:12,medium:12",
|
|
68
70
|
"firstName;small:6,medium:6",
|
|
69
71
|
"lastName;small:6,medium:6"
|
|
70
72
|
]
|
package/lib/check-user-id.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
async function checker (req, container) {
|
|
2
|
-
const {
|
|
2
|
+
const { getConfig, outmatch } = this.bajo.helper
|
|
3
3
|
const { get } = this.bajo.helper._
|
|
4
|
-
const outmatch = await importPkg('outmatch')
|
|
5
4
|
let match
|
|
6
5
|
for (const item of container) {
|
|
7
6
|
let path = item.path
|
package/lib/collect-routes.js
CHANGED
|
@@ -2,7 +2,7 @@ const indexes = []
|
|
|
2
2
|
const invIndexes = []
|
|
3
3
|
|
|
4
4
|
async function collect (type, { file, plugin, dir }) {
|
|
5
|
-
const { readConfig
|
|
5
|
+
const { readConfig } = this.bajo.helper
|
|
6
6
|
const { routeDir } = this.bajoWeb.helper
|
|
7
7
|
const { trim } = this.bajo.helper._
|
|
8
8
|
const { hash } = this.bajoExtra.helper
|