You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Fipamo/brain/routes/back/index.js

53 lines
1.2 KiB
JavaScript

const express = require('express');
const router = express.Router();
const Models = require('../../models');
//--------------------------
// Index
//--------------------------
router.get('/', function(req, res) {
var loggedIn = false;
if (req.session.user) loggedIn = true;
Models.FreshPost.findAll({
order: [['id', 'DESC']]
})
.then(function(posts) {
let title = 'Fipamo Dashboard';
let welcome = '';
!loggedIn
? (welcome = 'Hello.')
: (welcome = 'Welcome back, ' + req.session.user.handle);
let filtered = [];
for (let index = 0; index < posts.length; index++) {
let item = posts[index].post;
if (typeof item.deleted == 'undefined' || item.deleted == false) {
filtered.push(posts[index]);
} else {
continue;
}
}
res.render('dash/index', {
title: title,
welcome: welcome,
user_status: loggedIn,
items: filtered
});
})
.then(() => {
//console.log(value);
})
.catch(() => {
//next(err);
});
});
//--------------------------
// Logout
//--------------------------
router.post('/logout', function(req, res) {
req.logout();
return res.json({
message: 'LOGGED OUT'
});
});
module.exports = router;