const express = require('express'); const router = express.Router(); const Models = require('../../models'); const fs = require("fs-extra"); var settings = []; //-------------------------- // SETTINGS //-------------------------- router.get('/', function(req, res) { fs.readJson('config/site-settings.json').then(obj => { settings = [] settings = obj; }).catch(err => { //console.error(err) }) if (req.session.user) { Models.User.findById(req.session.user.id).then((user) => { Models.FreshPost.findAll( { order: [ ['id', 'DESC'] ] }).then(posts => { let pages = [] if (settings.menu.length == 0) { for (let index = 0; index < posts.length; index++) { let item = posts[index].post; if (item.page == true || item.page == "true") pages.push( { title: posts[index].post.title, slug: posts[index].post.slug }); } } else { pages = settings.menu } res.render('dash/navigation', { pages: pages, title: 'Dashboard | Global Nav' }); }).catch(err => { console.log("ERROR", err) }) }) } else { res.redirect('/@/dashboard'); } }); module.exports = router;