<commit_before>'use strict';

/**
 * Module dependencies.
 */
var db = require('../../config/sequelize'),
    errorHandler = require('./errors');

/**
* Create a article
*/
exports.create = function(req, res) {
	var article = req.body;

	article.UserId = req.user.id;

    db.Article.create(req.body).success(function(article){
            return res.jsonp(article);
    }).error(function(err){
        return res.status(400).send({
            message: errorHandler.getErrorMessage(err)
        });
    });
};

/**
* Show the current article
*/
exports.read = function(req, res) {
	res.jsonp(req.article);
};

/**
* Update a article
*/
exports.update = function(req, res) {
	var article = req.article;

	article = _.extend(article, req.body);

	article.save(function(err) {
		if (err) {
			return res.status(400).send({
				message: errorHandler.getErrorMessage(err)
			});
		} else {
			res.jsonp(article);
		}
	});
};

/**
* Delete an article
*/
exports.delete = function(req, res) {
	var article = req.article;

	article.remove(function(err) {
		if (err) {
			return res.status(400).send({
				message: errorHandler.getErrorMessage(err)
			});
		} else {
			res.jsonp(article);
		}
	});
};

/**
* List of Articles
*/
exports.list = function(req, res) {
	Article.find().sort('-created').populate('user', 'displayName').exec(function(err, articles) {
		if (err) {
			return res.status(400).send({
				message: errorHandler.getErrorMessage(err)
			});
		} else {
			res.jsonp(articles);
		}
	});
};

/**
* Article middleware
*/
exports.articleByID = function(req, res, next, id) {
	Article.findById(id).populate('user', 'displayName').exec(function(err, article) {
		if (err) return next(err);
		if (!article) return next(new Error('Failed to load article ' + id));
		req.article = article;
		next();
	});
};

/**
* Article authorization middleware
*/
exports.hasAuthorization = function(req, res, next) {
	if (req.article.user.id !== req.user.id) {
		return res.status(403).send({
			message: 'User is not authorized'
		});
	}
	next();
};
<commit_msg>article populate equivalent<commit_after>'use strict';

/**
 * Module dependencies.
 */
var db = require('../../config/sequelize'),
    errorHandler = require('./errors');

/**
* Create a article
*/
exports.create = function(req, res) {
	var article = req.body;

	article.UserId = req.user.id;

    db.Article.create(req.body).done(function(err, article){
        if(err){
            return res.status(400).send({
                message: errorHandler.getErrorMessage(err)
            });
        }
        return res.jsonp(article);
    });
};

/**
* Show the current article
*/
exports.read = function(req, res) {
	res.jsonp(req.article);
};

/**
* Update a article
*/
exports.update = function(req, res) {

	var article = req.article;

	article = _.extend(article, req.body);

	article.save(function(err) {
		if (err) {
			return res.status(400).send({
				message: errorHandler.getErrorMessage(err)
			});
		} else {
			res.jsonp(article);
		}
	});
};

/**
* Delete an article
*/
exports.delete = function(req, res) {
	var article = req.article;

	article.remove(function(err) {
		if (err) {
			return res.status(400).send({
				message: errorHandler.getErrorMessage(err)
			});
		} else {
			res.jsonp(article);
		}
	});
};

/**
* List of Articles
*/
exports.list = function(req, res) {
    db.Article.findAll({ include: [{ model: db.User, attributes: ['displayName'] }], order: 'created' }).done(function(err, articles) {
		if (err) {
			return res.status(400).send({
				message: errorHandler.getErrorMessage(err)
			});
		} else {
			res.jsonp(articles);
		}
	});
};

/**
* Article middleware
*/
exports.articleByID = function(req, res, next, id) {
    db.Article.find({where: { id: id }, include: [ { model: db.User, attributes: ['displayName'] } ] }).done(function(err, article) {
		if (err) return next(err);
		if (!article) return next(new Error('Failed to load article ' + id));
		req.article = article;
		next();
	});
};

/**
* Article authorization middleware
*/
exports.hasAuthorization = function(req, res, next) {
	if (req.article.user.id !== req.user.id) {
		return res.status(403).send({
			message: 'User is not authorized'
		});
	}
	next();
};

{'fraction_non_alphanumeric': 0.18317535545023697, 'fraction_numerical': 0.0071090047393364926, 'mean_word_length': 3.3203684749232343, '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': '4814249', 'n_tokens_mistral': 1544, 'n_tokens_neox': 1414, 'n_words': 289}