hola-server 0.4.1 → 0.4.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.
Files changed (2) hide show
  1. package/db/entity.js +11 -6
  2. package/package.json +1 -1
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
- query = { ...query, ...this.meta.ref_filter };
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hola-server",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "a meta programming framework used to build nodejs restful api",
5
5
  "main": "index.js",
6
6
  "scripts": {