hola-server 0.4.1 → 0.4.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/db/db.js +10 -10
- package/db/entity.js +11 -6
- package/package.json +1 -1
package/db/db.js
CHANGED
|
@@ -18,7 +18,7 @@ const get_session_userid = () => {
|
|
|
18
18
|
return req && req.session && req.session.user ? req.session.user.id : "";
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
-
const log_msg = (category, level, msg) => {
|
|
21
|
+
const log_msg = (category, level, msg, extra) => {
|
|
22
22
|
const time = format_date_time(new Date());
|
|
23
23
|
const db = get_db();
|
|
24
24
|
const { col_log } = get_settings().log;
|
|
@@ -27,7 +27,7 @@ const log_msg = (category, level, msg) => {
|
|
|
27
27
|
const path = req ? req.originalUrl : "";
|
|
28
28
|
const user = req && req.session && req.session.user ? req.session.user.id : "";
|
|
29
29
|
|
|
30
|
-
db.create(col_log, { time: time, category: category, level: level, msg: msg, user: user, path: path }).then(() => { });
|
|
30
|
+
db.create(col_log, { time: time, category: category, level: level, msg: msg, user: user, path: path, ...extra }).then(() => { });
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
const is_log_debug = () => {
|
|
@@ -50,27 +50,27 @@ const is_log_error = () => {
|
|
|
50
50
|
return save_db && log_level <= LOG_LEVEL_ERROR;
|
|
51
51
|
};
|
|
52
52
|
|
|
53
|
-
const log_debug = (category, msg) => {
|
|
53
|
+
const log_debug = (category, msg, extra) => {
|
|
54
54
|
if (is_log_debug()) {
|
|
55
|
-
log_msg(category, LOG_LEVEL_DEBUG, msg);
|
|
55
|
+
log_msg(category, LOG_LEVEL_DEBUG, msg, extra);
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
const log_info = (category, msg) => {
|
|
59
|
+
const log_info = (category, msg, extra) => {
|
|
60
60
|
if (is_log_info()) {
|
|
61
|
-
log_msg(category, LOG_LEVEL_INFO, msg);
|
|
61
|
+
log_msg(category, LOG_LEVEL_INFO, msg, extra);
|
|
62
62
|
}
|
|
63
63
|
};
|
|
64
64
|
|
|
65
|
-
const log_warn = (category, msg) => {
|
|
65
|
+
const log_warn = (category, msg, extra) => {
|
|
66
66
|
if (is_log_warn()) {
|
|
67
|
-
log_msg(category, LOG_LEVEL_WARN, msg);
|
|
67
|
+
log_msg(category, LOG_LEVEL_WARN, msg, extra);
|
|
68
68
|
}
|
|
69
69
|
};
|
|
70
70
|
|
|
71
|
-
const log_error = (category, msg) => {
|
|
71
|
+
const log_error = (category, msg, extra) => {
|
|
72
72
|
if (is_log_error()) {
|
|
73
|
-
log_msg(category, LOG_LEVEL_ERROR, msg);
|
|
73
|
+
log_msg(category, LOG_LEVEL_ERROR, msg, extra);
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
76
|
|
package/db/entity.js
CHANGED
|
@@ -84,7 +84,7 @@ class Entity {
|
|
|
84
84
|
const array = [];
|
|
85
85
|
for (let j = 0; j < value.length; j++) {
|
|
86
86
|
const v = value[j];
|
|
87
|
-
const ref_entities = await ref_entity.find_by_ref_value(v, { "_id": 1 });
|
|
87
|
+
const ref_entities = await ref_entity.find_by_ref_value(v, { "_id": 1 }, this.meta.collection);
|
|
88
88
|
|
|
89
89
|
if (ref_entities.length == 0) {
|
|
90
90
|
return { code: REF_NOT_FOUND, err: [field.name] };
|
|
@@ -97,7 +97,7 @@ class Entity {
|
|
|
97
97
|
param_obj[field.name] = array;
|
|
98
98
|
|
|
99
99
|
} else if (has_value(value)) {
|
|
100
|
-
const ref_entities = await ref_entity.find_by_ref_value(value, { "_id": 1 });
|
|
100
|
+
const ref_entities = await ref_entity.find_by_ref_value(value, { "_id": 1 }, this.meta.collection);
|
|
101
101
|
|
|
102
102
|
if (ref_entities.length == 0) {
|
|
103
103
|
return { code: REF_NOT_FOUND, err: [field.name] };
|
|
@@ -129,7 +129,7 @@ class Entity {
|
|
|
129
129
|
if (refer_field_names.includes(search_field.name)) {
|
|
130
130
|
//refer field
|
|
131
131
|
const refer_entity = new Entity(get_entity_meta(search_field.ref));
|
|
132
|
-
const oids = await refer_entity.find_by_ref_value(value, { _id: 1 });
|
|
132
|
+
const oids = await refer_entity.find_by_ref_value(value, { _id: 1 }, this.meta.collection);
|
|
133
133
|
if (oids.length > 0) {
|
|
134
134
|
and_array.push({ [search_field.name]: { "$all": oids.map(o => o._id + "") } });
|
|
135
135
|
}
|
|
@@ -787,7 +787,7 @@ class Entity {
|
|
|
787
787
|
* @param {the attributes to load from db} attr
|
|
788
788
|
* @returns array of the objects that are found
|
|
789
789
|
*/
|
|
790
|
-
find_by_ref_value(value, attr) {
|
|
790
|
+
find_by_ref_value(value, attr, ref_by_entity) {
|
|
791
791
|
let query = Array.isArray(value) ? oid_queries(value) : oid_query(value);
|
|
792
792
|
if (query == null) {
|
|
793
793
|
if (Array.isArray(value)) {
|
|
@@ -802,9 +802,14 @@ class Entity {
|
|
|
802
802
|
}
|
|
803
803
|
}
|
|
804
804
|
|
|
805
|
-
if (this.meta.ref_filter) {
|
|
806
|
-
|
|
805
|
+
if (this.meta.ref_filter && ref_by_entity) {
|
|
806
|
+
if (this.meta.ref_filter[ref_by_entity]) {
|
|
807
|
+
query = { ...query, ...this.meta.ref_filter[ref_by_entity] };
|
|
808
|
+
} else if (this.meta.ref_filter["*"]) {
|
|
809
|
+
query = { ...query, ...this.meta.ref_filter["*"] };
|
|
810
|
+
}
|
|
807
811
|
}
|
|
812
|
+
|
|
808
813
|
return this.find(query, attr);
|
|
809
814
|
}
|
|
810
815
|
|