hola-server 1.0.0 → 1.0.2
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/entity.js +16 -1
- package/package.json +1 -1
- package/router/read.js +2 -2
package/db/entity.js
CHANGED
|
@@ -1060,11 +1060,26 @@ class Entity {
|
|
|
1060
1060
|
* get ref labels of the object, use ref_filter
|
|
1061
1061
|
* @returns
|
|
1062
1062
|
*/
|
|
1063
|
-
get_filtered_ref_labels(ref_by_entity) {
|
|
1063
|
+
get_filtered_ref_labels(ref_by_entity, client_query) {
|
|
1064
1064
|
let query = {};
|
|
1065
1065
|
if (this.meta.user_field) {
|
|
1066
1066
|
query[this.meta.user_field] = get_session_userid();
|
|
1067
1067
|
}
|
|
1068
|
+
|
|
1069
|
+
const search_fields = this.meta.search_fields;
|
|
1070
|
+
//client query: key:value, key:value
|
|
1071
|
+
if (client_query && client_query.trim().length > 0 && search_fields && search_fields.length > 0) {
|
|
1072
|
+
const queries = client_query.split(",");
|
|
1073
|
+
for (let i = 0; i < queries.length; i++) {
|
|
1074
|
+
const query_values = queries[i].split(":");
|
|
1075
|
+
if (query_values && query_values.length == 2) {
|
|
1076
|
+
const field_name = query_values[0];
|
|
1077
|
+
const [search_field] = search_fields.filter(f => f.name == field_name);
|
|
1078
|
+
search_field && (query[field_name] = parse_search_value(field_name, search_field.type, query_values[1]))
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1068
1083
|
if (this.meta.ref_filter && ref_by_entity) {
|
|
1069
1084
|
if (this.meta.ref_filter[ref_by_entity]) {
|
|
1070
1085
|
query = { ...query, ...this.meta.ref_filter[ref_by_entity] };
|
package/package.json
CHANGED
package/router/read.js
CHANGED
|
@@ -53,8 +53,8 @@ const init_read_router = function (router, meta) {
|
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
const { ref_by_entity } = get_params(req, ["ref_by_entity"]);
|
|
57
|
-
const list = await entity.get_filtered_ref_labels(ref_by_entity);
|
|
56
|
+
const { ref_by_entity, query } = get_params(req, ["ref_by_entity", "query"]);
|
|
57
|
+
const list = await entity.get_filtered_ref_labels(ref_by_entity, query);
|
|
58
58
|
const items = list.map(obj => ({ "text": obj[meta.ref_label], "value": obj["_id"] + "" }));
|
|
59
59
|
res.json({ code: SUCCESS, data: items });
|
|
60
60
|
}));
|