server/bo_client/server/mocks/geonames.js
author ymh <ymh.work@gmail.com>
Wed, 28 Sep 2016 15:58:18 +0200
changeset 305 ff6cf3fc5f40
parent 304 20071981ba2a
child 517 3143195e91b4
permissions -rw-r--r--
api reorganisation and propagation if the changes + some code cleaning
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
305
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
     1
/* jshint node:true */
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
     2
/* eslint-env node */
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
     3
/* eslint global-require: 0, no-magic-numbers: 0 */
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
     4
304
20071981ba2a add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
module.exports = function(app) {
305
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
     6
  const express = require('express');
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
     7
  const _ = require('lodash');
304
20071981ba2a add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
305
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
     9
  const v1GeonamesRouter = express.Router();
304
20071981ba2a add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
305
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
    11
  const geonamesMappings = require('../fixtures/geonames');
304
20071981ba2a add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
305
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
    13
  v1GeonamesRouter.get('/:id', function(req, res) {
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
    14
    const idList = req.params.id.split(',');
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
    15
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
    16
    res.send({
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
    17
      geonamesids: _.reduce(idList, function(r, id) {
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
    18
        r[id] = (id in geonamesMappings) ? geonamesMappings[id] : null;
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
    19
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
    20
        return r;
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
    21
      }, {})
304
20071981ba2a add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    });
305
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
    23
  });
304
20071981ba2a add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
305
ff6cf3fc5f40 api reorganisation and propagation if the changes + some code cleaning
ymh <ymh.work@gmail.com>
parents: 304
diff changeset
    25
  app.use('/api/v1/geonames', v1GeonamesRouter);
304
20071981ba2a add location and geonames resolvers and api
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
};