Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
updated api for dates which will return last date currenies if it don…
Browse files Browse the repository at this point in the history
…t have values (#9)
  • Loading branch information
nikhila05 authored Jun 6, 2018
1 parent 2754162 commit 87bbf73
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 5 additions & 3 deletions api.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ http.createServer(function (req, res) {
var db = dbo.db("currency");
var collection = db.collection('prices');
fields = {base:1, date:1, _id:0, rates: 1}
query = {'base': "EUR", 'date': req.url.split('/api/')[1].split('?')[0].toString()}
query = {'base': "EUR", 'date': { $lte: req.url.split('/api/')[1].split('?')[0].toString() } }
if(q.query['base']){
query['base']= q.query['base'].toUpperCase()
}
Expand All @@ -75,8 +75,10 @@ http.createServer(function (req, res) {
fields[symbol] = 1;
}
}
var cursor = collection.find(query, {fields: fields}).toArray(function(err, result) {
if (err) throw err;
var cursor = collection.find(query, {fields: fields}).sort({date: -1}).toArray(function(err, result) {
if (err){
throw err;
}
dbo.close();
if(result[0]){
res.writeHead(200, {'Content-Type': 'text/json'});
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"mongodb": "^3.0.7"
"mongodb": "^3.0.7",
"nodemon": "^1.17.5"
}
}

0 comments on commit 87bbf73

Please sign in to comment.