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

Commit

Permalink
Rename light endpoint to status
Browse files Browse the repository at this point in the history
  • Loading branch information
duvholt committed Apr 20, 2015
1 parent 7cf696b commit 7fc5728
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
16 changes: 8 additions & 8 deletions libs/light.js → libs/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,26 @@ Light.prototype.get = function(req, affiliation, callback) {
}
var lastDay = new Date();
lastDay.setDate(lastDay.getDate() - 1);
var lightDb = req.db.get('light');
lightDb.findOne({
var statusDb = req.db.get('status');
statusDb.findOne({
$query: {
affiliation: affiliation,
updated: {$gte: lastDay} // Only get light updates from the last 24h
updated: {$gte: lastDay} // Only get status updates from the last 24h
},
$orderby: {
updated: -1 // Latest first
}
}, function(err, light) {
}, function(err, status) {
if(err !== null) {
// Something went wrong!
that.responseData.error = that.msgError;
}
else if(light !== null) {
that.responseData.status = light.status;
that.responseData.updated = light.updated;
else if(status !== null) {
that.responseData.status = status.status;
that.responseData.updated = status.updated;
}
else {
// No light updated today
// No status updated today
that.responseData.status = null;
that.responseData.updated = null;
}
Expand Down
6 changes: 3 additions & 3 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var router = express.Router();
var Cantina = require("../libs/cantina");
var Coffee = require("../libs/coffee");
var Hackerspace = require("../libs/hackerspace");
var Light = require("../libs/light");
var Status = require("../libs/status");
var Meeting = require("../libs/meeting");
var Servant = require("../libs/servant");

Expand All @@ -30,8 +30,8 @@ router.route('/affiliation/:affiliation').get(function(req, res) {
});
},
function(callback) {
var light = new Light();
light.get(req, req.params.affiliation, function(data) {
var status = new Status();
status.get(req, req.params.affiliation, function(data) {
callback(null, {name: 'status', value: data});
});
}
Expand Down
16 changes: 8 additions & 8 deletions routes/notipi.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ router.post('/:affiliation/coffee', function(req, res) {
res.json({success: true});
});

// Light endpoint
router.post('/:affiliation/light', function(req, res) {
var light = req.body.light;
if(light === undefined || !light.match(/^(on|off)$/)) {
// Status endpoint. Typically status if the office is open or not
router.post('/:affiliation/status', function(req, res) {
var status = req.body.status;
if(status === undefined || !status.match(/^(true|false)$/i)) {
res.json({error: 'Mangler lysstatus'});
}
var lightDb = req.db.get('light');
// Adding light status
lightDb.insert({
var statusDb = req.db.get('status');
// Adding status
statusDb.insert({
affiliation: req.affiliation.affiliation,
status: light == 'on',
status: status.toLowerCase() === 'true',
updated: new Date()
});
res.json({success: true});
Expand Down

0 comments on commit 7fc5728

Please sign in to comment.