MCPcopy Create free account
hub / github.com/CloudBoost/cloudboost / validateSocketQuery

Function validateSocketQuery

helpers/socketQuery.js:69–299  ·  view source on GitHub ↗
(cloudObject, query)

Source from the content-addressed store, hash-verified

67 }
68 },
69 validateSocketQuery(cloudObject, query) {
70 // validate query.
71 const queryKeys = Object.keys(query);
72 for (let i = 0; i < queryKeys.length; i++) {
73 const key = queryKeys[i];
74 if (query[key]) {
75 const value = query[key];
76 if (typeof value === 'object') {
77 if (key === '$or') {
78 if (query[key].length > 0) {
79 let isTrue = false;
80 for (let j = 0; j < query[key].length; j++) {
81 if (obj.validateSocketQuery(cloudObject, query[key][j])) {
82 isTrue = true;
83 break;
84 }
85 }
86
87 if (!isTrue) {
88 return false;
89 }
90 }
91 } else {
92 const valueKeys = Object.keys(value);
93 for (let k = 0; k < valueKeys.length; k++) {
94 const objectKeys = valueKeys[k];
95 // near query
96 if (objectKeys === '$near') {
97 const cbVal = cloudObject[key];
98 const qVal = query[key].$near;
99 const lat1 = cbVal.latitude;
100 const lon1 = cbVal.longitude;
101 const lat2 = qVal.$geometry.coordinates[1];
102 const lon2 = qVal.$geometry.coordinates[0];
103 let maxDistance = qVal.$maxDistance;
104 let minDistance = qVal.$minDistance;
105 const distance = util.getLatLongDistance(lat1, lon1, lat2, lon2);
106 if (!minDistance) minDistance = 0;
107 if (!maxDistance) maxDistance = 21036000; // maximum distance b/w 2 poits on earth
108 if (distance > maxDistance || distance < minDistance) return false;
109 }
110
111 // not equalTo query
112 if (objectKeys === '$ne') {
113 if (cloudObject[key] === query[key].$ne) {
114 return false;
115 }
116 }
117
118 // greater than
119 if (objectKeys === '$gt') {
120 if (cloudObject[key] <= query[key].$gt) {
121 return false;
122 }
123 }
124
125 // less than
126 if (objectKeys === '$lt') {

Callers

nothing calls this directly

Calls 2

substringMethod · 0.80
trimStartFunction · 0.70

Tested by

no test coverage detected