mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
Added support for tags
This commit is contained in:
@ -5,6 +5,6 @@ module.exports = function(piler) {
|
||||
js: piler.js.renderTags(),
|
||||
css: piler.css.renderTags()
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
50
app/controllers/tags.js
Normal file
50
app/controllers/tags.js
Normal file
@ -0,0 +1,50 @@
|
||||
var mongoose = require('mongoose'),
|
||||
Tag = mongoose.model('Tag');
|
||||
|
||||
module.exports = function(piler) {
|
||||
return {
|
||||
index: function(req, res, next) {
|
||||
|
||||
host = String(req.headers.host);
|
||||
host = host.split(':')[0];
|
||||
|
||||
if (host != 'n.atlb.co') {
|
||||
return next();
|
||||
}
|
||||
|
||||
if (!req.user) {
|
||||
req.session.redirectUrl = req.url
|
||||
}
|
||||
|
||||
var path = req.path.slice(1);
|
||||
|
||||
Tag.findById(path)
|
||||
.populate('client', 'name identifier address')
|
||||
.exec(function(err, result) {
|
||||
var payload = {
|
||||
user: req.user,
|
||||
id: path,
|
||||
tag: result || undefined,
|
||||
};
|
||||
|
||||
res.render('tag.jade', {
|
||||
css: piler.css.renderTags(),
|
||||
payload: payload
|
||||
});
|
||||
})
|
||||
},
|
||||
post: function(req, res) {
|
||||
|
||||
var tag_id = req.body.tag_id;
|
||||
delete req.body.tag_id;
|
||||
|
||||
Tag.findByIdAndUpdate(tag_id, req.body, { upsert: true }, function(err, result) {
|
||||
if (err) {
|
||||
res.json(500, err);
|
||||
} else {
|
||||
res.json(result);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user