mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-13 06:32:39 +00:00
Creating new home page, added new account route
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const _ = require('lodash');
|
||||
|
||||
module.exports = (Brew) => {
|
||||
module.exports = (BrewModel) => {
|
||||
const cmds = {
|
||||
termSearch : (terms='', opts, fullAccess) => {
|
||||
let query = {};
|
||||
@@ -42,7 +42,7 @@ module.exports = (Brew) => {
|
||||
queryObj.published = true;
|
||||
}
|
||||
|
||||
const searchQuery = Brew
|
||||
const searchQuery = BrewModel
|
||||
.find(queryObj)
|
||||
.sort(opts.sort)
|
||||
.select(filter)
|
||||
@@ -51,7 +51,7 @@ module.exports = (Brew) => {
|
||||
.lean()
|
||||
.exec();
|
||||
|
||||
const countQuery = Brew.count(queryObj).exec();
|
||||
const countQuery = BrewModel.count(queryObj).exec();
|
||||
|
||||
return Promise.all([searchQuery, countQuery])
|
||||
.then((result) => {
|
||||
|
||||
@@ -16,6 +16,20 @@ const statics = {
|
||||
oldTest : fs.readFileSync('./statics/oldTest.brew.md', 'utf8'),
|
||||
};
|
||||
|
||||
let topBrews = [];
|
||||
const getTopBrews = ()=>{
|
||||
return BrewData.search({}, {
|
||||
limit : 4,
|
||||
sort : {views : -1}
|
||||
}).then(({brews, total})=>brews);
|
||||
};
|
||||
|
||||
getTopBrews().then((brews)=>{
|
||||
console.log('top brews', brews);
|
||||
topBrews=brews;
|
||||
});
|
||||
|
||||
|
||||
|
||||
const vitreumRender = require('vitreum/steps/render');
|
||||
const templateFn = require('../client/template.js');
|
||||
@@ -54,9 +68,18 @@ router.get('/source/:sharedId', mw.viewBrew, (req, res, next)=>{
|
||||
});
|
||||
|
||||
//User Page
|
||||
router.get('/account', (req, res, next)=>{
|
||||
if(req.account && req.account.username){
|
||||
return res.redirect(`/user/${req.account.username}`);
|
||||
}else{
|
||||
return res.redirect(config.get('login_path'));
|
||||
}
|
||||
});
|
||||
router.get('/user/:username', (req, res, next) => {
|
||||
BrewData.search({ user : req.params.username })
|
||||
.then((brews) => {
|
||||
const isSelf = req.account && req.params.username == req.account.username;
|
||||
|
||||
BrewData.userSearch(req.params.username, isSelf)
|
||||
.then(({brews, total}) => {
|
||||
req.brews = brews;
|
||||
return next();
|
||||
})
|
||||
@@ -100,6 +123,7 @@ router.get('/new', renderPage);
|
||||
//Home Page
|
||||
router.get('/', (req, res, next) => {
|
||||
req.brew = { text : statics.welcomeBrew };
|
||||
//TODO add in top brews
|
||||
return next();
|
||||
}, renderPage);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user