<commit_before>/*jslint node: true */
"use strict";

var express = require('express');
var bookRouter = express.Router();
var sql = require('mssql'); // its that same like in app.js

var router = function (nav) {
    var books = [
        {
            title: 'War and Peace',
            genre: 'Historical Fiction',
            author: '<NAME>',
            read: false
},
        {
            title: 'Les Misérables',
            genre: 'Historical Fiction',
            author: '<NAME>',
            read: false
},
        {
            title: 'The Time Machine',
            genre: 'Science Fiction',
            author: '<NAME>',
            read: false
},
        {
            title: 'A Journey into the Center of the Earth',
            genre: 'Science Fiction',
            author: '<NAME>',
            read: false
},
        {
            title: 'The Dark World',
            genre: 'Fantasy',
            author: '<NAME>',
            read: false
},
        {
            title: 'The Wind in the Willows',
            genre: 'Fantasy',
            author: '<NAME>',
            read: false
},
        {
            title: 'Life On The Mississippi',
            genre: 'History',
            author: '<NAME>',
            read: false
},
        {
            title: 'Childhood',
            genre: 'Biography',
            author: '<NAME>',
            read: false
}
];

    bookRouter.route('/')
        .get(function (req, res) {
            var request = new sql.Request();

            request.query('select * from books',
                function (err, recordset) { // recordset is already JSON formated
                    res.render('bookListView', {
                        title: 'Books',
                        nav: nav,
                        books: recordset
                    });
                });
        });

    bookRouter.route('/:id')
     .get(function (req, res) {
         var id = req.params.id;
         var ps = new sql.PreparedStatement();
         ps.input('id', sql.Int);
         ps.prepare('select * from books where id = @id',
             function (err) {
                 ps.execute({
                         id: req.params.id
                     },
                     function (err, recordset) {
                         res.render('bookView', {
                             title: 'Single Book',
                             nav: nav,
                             book: recordset[0]
                         });
                     });
             });

     });

    return bookRouter;
};


module.exports = router;<commit_msg>Middleware<commit_after>/*jslint node: true */
"use strict";

var express = require('express');
var bookRouter = express.Router();
var sql = require('mssql'); // its that same like in app.js

var router = function (nav) {
    var books = [
        {
            title: 'War and Peace',
            genre: 'Historical Fiction',
            author: '<NAME>',
            read: false
},
        {
            title: 'Les Misérables',
            genre: 'Historical Fiction',
            author: '<NAME>',
            read: false
},
        {
            title: 'The Time Machine',
            genre: 'Science Fiction',
            author: '<NAME>',
            read: false
},
        {
            title: 'A Journey into the Center of the Earth',
            genre: 'Science Fiction',
            author: '<NAME>',
            read: false
},
        {
            title: 'The Dark World',
            genre: 'Fantasy',
            author: '<NAME>',
            read: false
},
        {
            title: 'The Wind in the Willows',
            genre: 'Fantasy',
            author: '<NAME>',
            read: false
},
        {
            title: 'Life On The Mississippi',
            genre: 'History',
            author: '<NAME>',
            read: false
},
        {
            title: 'Childhood',
            genre: 'Biography',
            author: '<NAME>',
            read: false
}
];

    bookRouter.route('/')
        .get(function (req, res) {
            var request = new sql.Request();

            request.query('select * from books',
                function (err, recordset) { // recordset is already JSON formated
                    res.render('bookListView', {
                        title: 'Books',
                        nav: nav,
                        books: recordset
                    });
                });
        });

    bookRouter.route('/:id')
        .all(function (req, res, next) {
            var id = req.params.id;
            var ps = new sql.PreparedStatement();
            ps.input('id', sql.Int);
            ps.prepare('select * from books where id = @id',
                function (err) {
                    ps.execute({
                            id: req.params.id
                        },
                        function (err, recordset) {
                            if (recordset.length === 0) {
                                res.status(404).send('Not Found');
                            } else {
                                req.book = recordset[0];
                                next();
                            }
                        });
                });
        })
        .get(function (req, res) {
            res.render('bookView', {
                title: 'Single Book',
                nav: nav,
                book: req.book
            });

        });

    return bookRouter;
};


module.exports = router;
{'fraction_non_alphanumeric': 0.1228102189781022, 'fraction_numerical': 0.0010948905109489052, 'mean_word_length': 1.0651846269781462, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, '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': '1648638', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1355, 'n_words': 372}