<commit_before>var express = require('express');
var blogsRouter = express.Router();

var Post = require('../models/post.server.model.js');

var info = require('../config/info.config.js')();
var nav = require('../config/nav.config.js')();

module.exports = () => {
    blogsRouter.route('/')
        .all(function (req, res, next) {
            if (req.user) {
                nav[nav.length - 1].item = 'Logout';
                nav[nav.length - 1].link = '/auth/signOut';
            } else {
                nav[nav.length - 1].item = 'Login';
                nav[nav.length - 1].link = '/';
            }
            next();
        })
        .get(function (req, res) {
            Post.find({}, function (err, posts) {
                if (!err) {
                    info.heading = 'ALL POSTS';
                    info.subheading = 'Bloggedin';
                    res.render('pages/allposts', {
                        nav: nav,
                        info: info,
                        posts: posts
                    });
                }
            });
        });

    blogsRouter.route('/:id')
        .all(function (req, res, next) {
            if (req.user) {
                nav[nav.length - 1].item = 'Logout';
                nav[nav.length - 1].link = '/auth/signOut';
            } else {
                nav[nav.length - 1].item = 'Login';
                nav[nav.length - 1].link = '/';
            }
            next();
        })
        .get(function (req, res, next) {
            Post.findById(req.params.id, function (err, post) {
                if (!err) {
                    var isUserAuthor = false;

                    console.log(req.user);
                    console.log(post.authorId);

                    if (req.user && req.user._id == post.authorId) {
                        isUserAuthor = true;
                    }

                    info.heading = post.title;
                    info.subheading = post.caption;
                    res.render('pages/post', {
                        nav: nav,
                        info: info,
                        post: post,
                        isUserAuthor: isUserAuthor
                    });
                } else {
                    res.send('Error!');
                }
            });
        });

    return blogsRouter;
};<commit_msg>checks if the post exists<commit_after>var express = require('express');
var blogsRouter = express.Router();

var Post = require('../models/post.server.model.js');

var info = require('../config/info.config.js')();
var nav = require('../config/nav.config.js')();

module.exports = () => {
    blogsRouter.route('/')
        .all(function (req, res, next) {
            if (req.user) {
                nav[nav.length - 1].item = 'Logout';
                nav[nav.length - 1].link = '/auth/signOut';
            } else {
                nav[nav.length - 1].item = 'Login';
                nav[nav.length - 1].link = '/';
            }
            next();
        })
        .get(function (req, res) {
            Post.find({}, function (err, posts) {
                if (!err) {
                    info.heading = 'ALL POSTS';
                    info.subheading = 'Bloggedin';
                    res.render('pages/allposts', {
                        nav: nav,
                        info: info,
                        posts: posts
                    });
                }
            });
        });

    blogsRouter.route('/:id')
        .all(function (req, res, next) {
            if (req.user) {
                nav[nav.length - 1].item = 'Logout';
                nav[nav.length - 1].link = '/auth/signOut';
            } else {
                nav[nav.length - 1].item = 'Login';
                nav[nav.length - 1].link = '/';
            }
            next();
        })
        .get(function (req, res, next) {
            Post.findById(req.params.id, function (err, post) {
                if (!err && post) {
                    var isUserAuthor = false;

                    console.log(req.user);
                    console.log(post.authorId);

                    if (req.user && req.user._id == post.authorId) {
                        isUserAuthor = true;
                    }

                    info.heading = post.title;
                    info.subheading = post.caption;
                    res.render('pages/post', {
                        nav: nav,
                        info: info,
                        post: post,
                        isUserAuthor: isUserAuthor
                    });
                } else {
                    req.flash('error', 'Error! Can\'t access the requested content');
                    res.redirect('/');
                }
            });
        });

    return blogsRouter;
};
{'fraction_non_alphanumeric': 0.14139728884254432, 'fraction_numerical': 0.0033368091762252345, 'mean_word_length': 1.010901467505241, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4801947', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1215, 'n_words': 242}