Skip to content

Commit

Permalink
Fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thani-sh committed Aug 31, 2016
1 parent cc4d678 commit a2e6a1c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
11 changes: 3 additions & 8 deletions dist/server/middleware/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ var _bodyParser = require('body-parser');

var _bodyParser2 = _interopRequireDefault(_bodyParser);

var _uuid = require('uuid');

var _uuid2 = _interopRequireDefault(_uuid);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var Database = exports.Database = function () {
Expand All @@ -100,11 +96,10 @@ var Database = exports.Database = function () {
// and sort it by each key (and its order) and then apply the limit
var allDocs = this.db.get(collection).filter(query).value();
var sorted = (0, _keys2.default)(sort).reduce(function (unsorted, key) {
var order = sort[key];
var sorter = function sorter(x, y) {
return unsorted.sort(function (x, y) {
var order = sort[key];
return x[key] > y[key] ? order * 1 : order * -1;
};
return unsorted.sort(sorter);
});
}, allDocs);
// apply the limit after sorting
return sorted.slice(0, limit);
Expand Down
16 changes: 8 additions & 8 deletions src/server/middleware/datastore.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { Router } from 'express';
import lowdb from 'lowdb';
import fileAsyncStorage from 'lowdb/lib/file-async';
import bodyParser from 'body-parser';
import uuid from 'uuid';

export class Database {
constructor(dbPath) {
Expand All @@ -24,9 +23,10 @@ export class Database {
// and sort it by each key (and its order) and then apply the limit
const allDocs = this.db.get(collection).filter(query).value();
const sorted = Object.keys(sort).reduce((unsorted, key) => {
const order = sort[key];
const sorter = (x, y) => (x[key] > y[key]) ? order * 1 : order * -1;
return unsorted.sort(sorter);
return unsorted.sort(function (x, y) {
const order = sort[key];
return (x[key] > y[key]) ? order * 1 : order * -1;
});
}, allDocs);
// apply the limit after sorting
return sorted.slice(0, limit);
Expand All @@ -36,7 +36,7 @@ export class Database {
// if the database doesn't exist, add the item
// and return the inserted item as the result.
if (!this.db.has(collection).value()) {
this.db.set(collection, [ item ]).value();
this.db.set(collection, [item]).value();
return item;
}
// if the item already exists in the database, update it
Expand All @@ -46,7 +46,7 @@ export class Database {
}
// If the item is not available in the database, insert it
const coll = this.db.get(collection).value();
this.db.set(collection, [ ...coll, item ]).value();
this.db.set(collection, [...coll, item]).value();
return item;
}
}
Expand All @@ -61,14 +61,14 @@ export default function (configDir) {
router.post('/get', function (req, res) {
const { collection, query, sort, limit } = req.body;
const out = db.get(collection, query, sort, limit);
res.send({data: out});
res.send({ data: out });
res.end();
});

router.post('/set', function (req, res) {
const { collection, item } = req.body;
const out = db.set(collection, item);
res.send({data: out});
res.send({ data: out });
res.end();
});

Expand Down

0 comments on commit a2e6a1c

Please sign in to comment.