Browse Source

moved helper functions outside of setup scope

pull/782/head
Stephen Hess 8 years ago
parent
commit
73ef71d863
  1. 14
      controller/place.js
  2. 20
      controller/search.js

14
controller/place.js

@ -6,15 +6,15 @@ const retry = require('retry');
const mgetService = require('../service/mget'); const mgetService = require('../service/mget');
const logger = require('pelias-logger').get('api'); const logger = require('pelias-logger').get('api');
function setup( apiConfig, esclient ){ function requestHasErrors(request) {
function requestHasErrors(request) { return _.get(request, 'errors', []).length > 0;
return _.get(request, 'errors', []).length > 0; }
}
function isRequestTimeout(err) { function isRequestTimeout(err) {
return _.get(err, 'status') === 408; return _.get(err, 'status') === 408;
} }
function setup( apiConfig, esclient ){
function controller( req, res, next ){ function controller( req, res, next ){
// do not run controller when a request validation error has occurred. // do not run controller when a request validation error has occurred.
if (requestHasErrors(req)){ if (requestHasErrors(req)){

20
controller/search.js

@ -7,19 +7,19 @@ const logger = require('pelias-logger').get('api');
const logging = require( '../helper/logging' ); const logging = require( '../helper/logging' );
const retry = require('retry'); const retry = require('retry');
function setup( apiConfig, esclient, query ){ function requestHasErrors(request) {
function requestHasErrors(request) { return _.get(request, 'errors', []).length > 0;
return _.get(request, 'errors', []).length > 0; }
}
function responseHasData(response) { function responseHasData(response) {
return _.get(response, 'data', []).length > 0; return _.get(response, 'data', []).length > 0;
} }
function isRequestTimeout(err) { function isRequestTimeout(err) {
return _.get(err, 'status') === 408; return _.get(err, 'status') === 408;
} }
function setup( apiConfig, esclient, query ){
function controller( req, res, next ){ function controller( req, res, next ){
// do not run controller when a request // do not run controller when a request
// validation error has occurred. // validation error has occurred.

Loading…
Cancel
Save