nodester 0.3.0 → 0.3.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.
@@ -171,6 +171,7 @@ function traverse(queryNode, filter=null, model=null) {
171
171
 
172
172
  const clausesEntries = Object.entries(clauses);
173
173
  for (let [clauseName, value] of clausesEntries) {
174
+
174
175
  // If clause is not available:
175
176
  if (filter != null) {
176
177
  if (filter.clauses.indexOf(clauseName) === -1)
@@ -270,7 +271,7 @@ function traverse(queryNode, filter=null, model=null) {
270
271
 
271
272
  case null:
272
273
  case undefined:
273
- newQuery.order = [ ['id', 'desc'] ];
274
+ // newQuery.order = [ ['id', 'desc'] ];
274
275
  break;
275
276
 
276
277
  default:
@@ -298,13 +299,22 @@ function traverse(queryNode, filter=null, model=null) {
298
299
 
299
300
 
300
301
  // Where:
302
+
303
+ // Set aatributes from Query:
301
304
  const whereEntries = Object.entries(where);
302
- for (let [attribute, value] of whereEntries) {
303
- _parseWhereEntry(attribute, value, newQuery.where, filter.statics.attributes);
305
+ for (let [ attribute, value ] of whereEntries) {
306
+ _parseWhereEntry(attribute, value, newQuery.where);
307
+ }
308
+
309
+ // Static attributes override previously set attributes:
310
+ const staticAttributesEntries = Object.entries(filter.statics.attributes);
311
+ for (let [ attribute, staticValue ] of staticAttributesEntries) {
312
+ newQuery.where[attribute] = _parseValue(staticValue, attribute);
304
313
  }
305
314
 
306
- // If "where" was not set:
307
- if (whereEntries.length === 0) {
315
+ // If "where" was not set in any way,
316
+ // remove it from the db query:
317
+ if (Object.entries(newQuery.where).length === 0) {
308
318
  delete newQuery.where;
309
319
  }
310
320
  // Where\
@@ -360,9 +370,8 @@ function _addAssociationQuery(associationQuery, includeName, resultQuery) {
360
370
  }
361
371
 
362
372
 
363
- function _parseWhereEntry(attribute, value, whereHolder, staticAttributes) {
373
+ function _parseWhereEntry(attribute, value, whereHolder) {
364
374
  let _value = value;
365
- const staticAttribute = staticAttributes[attribute];
366
375
 
367
376
  // If attribute is Op (not, like, or, etc.):
368
377
  if (attribute in Op) {
@@ -373,12 +382,6 @@ function _parseWhereEntry(attribute, value, whereHolder, staticAttributes) {
373
382
  whereHolder[op] = _value;
374
383
  return;
375
384
  }
376
-
377
- // Static value overrides any other:
378
- if (!!staticAttribute) {
379
- whereHolder[attribute] = staticAttribute;
380
- return;
381
- }
382
385
 
383
386
  whereHolder[attribute] = _parseValue(_value, attribute);
384
387
  }
@@ -140,6 +140,15 @@ module.exports = class NodesterRouter {
140
140
 
141
141
  // Getters:
142
142
 
143
+ /**
144
+ * @return {Map} controllers
145
+ *
146
+ * @access public
147
+ */
148
+ get controllers() {
149
+ return this._controllers;
150
+ }
151
+
143
152
  /**
144
153
  * @return {MiddlewaresStack}
145
154
  *
@@ -149,6 +158,15 @@ module.exports = class NodesterRouter {
149
158
  return this._middlewares;
150
159
  }
151
160
 
161
+ /**
162
+ * @return {Map} providers
163
+ *
164
+ * @access public
165
+ */
166
+ get providers() {
167
+ return this._providers;
168
+ }
169
+
152
170
  /**
153
171
  * Indicates whether user can add more middlewares or not.
154
172
  *
@@ -38,6 +38,8 @@ function _validateParsedRouteMethood(parsedRoute) {
38
38
  * @access public
39
39
  */
40
40
  function _wrapRouteHandler(routeInstance, handler) {
41
+ const router = this;
42
+
41
43
  const handlerType = typeOf(handler);
42
44
 
43
45
  let parsedHandler = null;
@@ -78,6 +80,12 @@ function _wrapRouteHandler(routeInstance, handler) {
78
80
  return next();
79
81
  }
80
82
 
83
+ // Store info about current route in request.
84
+ req._routing = {
85
+ route,
86
+ router
87
+ }
88
+
81
89
  // Populate params.
82
90
  req.params = routeInstance.params;
83
91
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodester",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "A versatile REST framework for Node.js",
5
5
  "directories": {
6
6
  "docs": "docs",
@@ -107,8 +107,7 @@
107
107
  },
108
108
  "scripts": {
109
109
  "lint": "eslint .",
110
- "test": "jest",
111
- "publish": "npm run lint && npm publish"
110
+ "test": "jest"
112
111
  },
113
112
  "author": "Mark Khramko <markkhramko@gmail.com>",
114
113
  "license": "MIT",