mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
Added clock stuff
This commit is contained in:
42
app/controllers/clock.js
Normal file
42
app/controllers/clock.js
Normal file
@ -0,0 +1,42 @@
|
||||
var mongoose = require('mongoose'),
|
||||
Clock = mongoose.model('Clock');
|
||||
|
||||
module.exports = function(piler) {
|
||||
return {
|
||||
index: function(req, res, next) {
|
||||
host = String(req.headers['x-forwarded-host']);
|
||||
host = host.split(':')[0];
|
||||
|
||||
if (host != 'clock.atlb.co') {
|
||||
return next();
|
||||
}
|
||||
|
||||
if (!req.user) {
|
||||
req.session.redirectUrl = req.url
|
||||
}
|
||||
|
||||
var path = req.path.slice(1);
|
||||
|
||||
res.render('clock.jade', {
|
||||
css: piler.css.renderTags()
|
||||
});
|
||||
},
|
||||
post: function(req, res) {
|
||||
var clock = new Clock({
|
||||
tech: req.user,
|
||||
action: req.body.action,
|
||||
lat: req.body.lat,
|
||||
long: req.body.long,
|
||||
dt: new Date()
|
||||
});
|
||||
|
||||
clock.save(function(err, result) {
|
||||
if (err) {
|
||||
return res.json(500, err);
|
||||
} else {
|
||||
res.json(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,8 @@
|
||||
|
||||
var mongoose = require('mongoose'),
|
||||
async = require('async'),
|
||||
User = mongoose.model('User');
|
||||
User = mongoose.model('User'),
|
||||
Clock = mongoose.model('Clock');
|
||||
|
||||
var log = require('log4node');
|
||||
|
||||
@ -163,6 +164,24 @@ module.exports = function(config, directory) {
|
||||
return res.json(user);
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
clocks: function(req, res) {
|
||||
var id = req.param('user_id');
|
||||
|
||||
var criteria = {
|
||||
tech: id
|
||||
};
|
||||
|
||||
var query = Clock.find(criteria)
|
||||
.sort('-dt')
|
||||
.exec(function(err, results) {
|
||||
if (err) {
|
||||
res.json(500, err);
|
||||
} else {
|
||||
res.json(results);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
Reference in New Issue
Block a user