<commit_before>var validateHTTP = require("./validateHTTP.js"),
    restify = require('restify'),
    request = require('request'),
    rand = require('csprng'),
    sha1 = require('sha1'),
    uuid = require('node-uuid');

module.exports.getDetails = function(req, res, next, type) {
    if(type == "users") {
        //Grab a users profile
        console.log('GRABBING USER');
        console.log('GET ' + req.params.username);
        var user = {};
        console.log('parameters supplied');
        var url = 'http://localhost:5984/users/' + req.params.username;
        request.get(url, function(err, response, body) {
            console.log("request started")
            // if user is not found will send 404 error
            if(response.statusCode == 404) {
                return next(new restify.BadRequestError('User Not Found'))
            };
            if(response.statusCode == 200) {
                body = JSON.parse(body);
                //res.header('ETag', body._rev);
                res.header('Last-Modified', body.last_modified);
                res.header('Accepts', 'GET');
                user = {
                    id: body._id,
                    date_joined: body.date_joined,
                    last_modified: body.last_modified,
                    points: body.points,
                    transactions: body.transactions
                };
                console.log(user.points)
                console.log("set user");
                res.send(user);
                console.log("sent data");
                res.end();
            };
        });
    } else if(type == "business") {
        //Grab a users profile
        console.log('GRABBING BUSINESS');
        console.log('GET ' + req.params.businessname);
        var business = {};
        console.log('Parameters Supplied');
        var url = 'http://localhost:5984/business/' + req.params.businessname;
        request.get(url, function(err, response, body) {
            console.log("request started")
            // if business is not found will send 404 error
            if(response.statusCode == 404) {
                return next(new restify.BadRequestError('Business Not Found'))
            };
            if(response.statusCode == 200) {
                body = JSON.parse(body);
                //res.header('ETag', body._rev);
                res.header('Last-Modified', body.last_modified);
                res.header('Accepts', 'GET');
                business = {
                    id: body._id,
                    date_joined: body.date_joined,
                    last_modified: body.last_modified,
                };
                console.log("set business");
                res.send(business);
                console.log("sent data");
                res.end();<commit_msg>Added some errors for when not supplying a username<commit_after>var validateHTTP = require("./validateHTTP.js"),
    restify = require('restify'),
    request = require('request'),
    rand = require('csprng'),
    sha1 = require('sha1'),
    uuid = require('node-uuid');
module.exports.getDetails = function(req, res, next, type) {
    if(type == "users") {
        if(!req.params.username) {
            return next(new restify.BadRequestError("You didn't select a user - please add on the username like /users/xxx"))
        }
        //Grab a users profile
        console.log('GRABBING USER');
        console.log('GET ' + req.params.username);
        var user = {};
        console.log('parameters supplied');
        var url = 'http://localhost:5984/users/' + req.params.username;
        request.get(url, function(err, response, body) {
            console.log("request started")
            // if user is not found will send 404 error
            if(response.statusCode == 404) {
                return next(new restify.BadRequestError('User Not Found'))
            };
            if(response.statusCode == 200) {
                body = JSON.parse(body);
                //res.header('ETag', body._rev);
                res.header('Last-Modified', body.last_modified);
                res.header('Accepts', 'GET');
                user = {
                    id: body._id,
                    date_joined: body.date_joined,
                    last_modified: body.last_modified,
                    points: body.points,
                    transactions: body.transactions
                };
                console.log(user.points)
                console.log("set user");
                res.send(user);
                console.log("sent data");
                res.end();
            };
        });
    } else if(type == "business") {
        if(!req.params.businessname) {
            return next(new restify.BadRequestError("You didn't select a user - please add on the username like /users/xxx"))
        }
        //Grab a users profile
        console.log('GRABBING BUSINESS');
        console.log('GET ' + req.params.businessname);
        var business = {};
        console.log('Parameters Supplied');
        var url = 'http://localhost:5984/business/' + req.params.businessname;
        request.get(url, function(err, response, body) {
            console.log("request started")
            // if business is not found will send 404 error
            if(response.statusCode == 404) {
                return next(new restify.BadRequestError('Business Not Found'))
            };
            if(response.statusCode == 200) {
                body = JSON.parse(body);
                //res.header('ETag', body._rev);
                res.header('Last-Modified', body.last_modified);
                res.header('Accepts', 'GET');
                business = {
                    id: body._id,
                    date_joined: body.date_joined,
                    last_modified: body.last_modified,
                };
                console.log("set business");
                res.send(business);
                console.log("sent data");
                res.end();
{'fraction_non_alphanumeric': 0.12794387840320695, 'fraction_numerical': 0.009353599465508603, 'mean_word_length': 1.6148471615720523, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5164750', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1512, 'n_words': 337}