forked from steedos/steedos-platform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpermission_fields.trigger.js
53 lines (47 loc) · 1.76 KB
/
permission_fields.trigger.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const objectql = require('@steedos/objectql');
const auth = require('@steedos/auth');
const _ = require('underscore');
async function getAll() {
const schema = objectql.getSteedosSchema();
const configs = await objectql.registerPermissionFields.getAll(schema.broker)
const dataList = _.pluck(configs, 'metadata');
_.each(dataList, function (item) {
if (!item._id) {
item._id = `${item.name}`
}
})
return dataList;
}
async function get(apiName) {
const schema = objectql.getSteedosSchema();
const config = await objectql.registerPermissionFields.get(schema.broker, apiName)
return config ? config.metadata : null;
}
module.exports = {
listenTo: 'permission_fields',
afterFind: async function () {
let spaceId = this.spaceId;
let dataList = await getAll();
this.data.values = this.data.values.concat(dataList);
this.data.values = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
},
afterAggregate: async function () {
let spaceId = this.spaceId;
let dataList = await getAll();
this.data.values = this.data.values.concat(dataList);
this.data.values = objectql.getSteedosSchema().metadataDriver.find(this.data.values, this.query, spaceId);
},
afterCount: async function () {
let result = await objectql.getObject(this.object_name).find(this.query, await auth.getSessionByUserId(this.userId, this.spaceId))
this.data.values = result.length;
},
afterFindOne: async function () {
if (_.isEmpty(this.data.values)) {
let id = this.id
let data = await get(id);
if (data) {
this.data.values = data;
}
}
}
}