Last active
February 23, 2018 18:53
-
-
Save jwhitehorn/d9590beaeaa7d78b4a7a742cb04171ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var onionrm = require('onionrm'); | |
var express = require('express'); | |
var openDb = require('./database.js'); | |
var app = express(); | |
app.get('/api/updates/:model', function (req, res) { | |
var filter = { | |
updated_at: onionrm.gte(req.query.timestamp) | |
}; | |
openDb(function(err, models, closeDb){ | |
//TODO: check for errors | |
var lookup = { | |
'campgrounds': models.Campground, | |
'campground_reviews': models.CampgroundReview, | |
'campground_photos': models.CampgroundPhoto | |
}; | |
var model = lookup[req.params.model]; | |
if(!model){ | |
//TODO: error | |
} | |
model.find(filter, function(err, records){ | |
//TODO: check for errors | |
res.json(records); | |
}); | |
}); | |
}); | |
app.listen(5000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment