<commit_before>/**
 * Module dependencies.
 */
var mongoose = require('mongoose'),
    async = require('async'),
    Vendor = mongoose.model('Vendor'),
    _ = require('underscore');


/**
 * Find vendor by id
 */
exports.vendor = function(req, res, next, id) {

    Vendor.load(id, function(err, vendor) {
        if (err) return next(err);
        if (!vendor) {
            return res.failure('No results', 404);
        }
        req.vendor = vendor;
        next();
    });
};

/**
 * Find vendor by req.body.vendorId or req.params.vendorId
 * @todo this should be able to piggy back on exports.vendor by checkig for params and body if
 *    id doesn't exist ad the 4th param. However this was not working and causing errors.
 *
 */
exports.findByBodyOrParams = function(req, res, next) {
    
    var id = null;

    if(req.body && req.body.vendorId) {
        id = req.body.vendorId;
    } else if(req.params && req.params.vendorId) {
        id = req.params.vendorId;<commit_msg>Add find method to vendor api<commit_after>/**
 * Module dependencies.
 */
var mongoose = require('mongoose'),
    async = require('async'),
    Vendor = mongoose.model('Vendor'),
    _ = require('underscore');


/**
 * Find / query function, allows us to pass a mongodb style query over rest
 *
 * @todo change to GET!!! might require querystring module and will def require modifying angular service
 * @todo add to remaining controllers, currently only in application controller.
 *
 * @example { 'status' : 'open' } // gets all with status open
 * @example { 'status' : { '$nin' : ['open', 'archived', 'denied'] } } // gets all where status not in array
 *
 * @note these must be passed through JSON.stringify on the angular app side
 *
 */
exports.find = function(req, res, next) {

    // currently query is just request body
    var query = req.body;

/*
    if (req.userHasRole('salesRep')) {
        query.salesRep = req.user._id;
    } else if (req.userHasRole('vendorRep')) {
        query.vendorRep = req.user._id;
    }
*/

    Vendor
        .find(query)
        .exec(function(err, vendors) {
            if (err) {
                res.failure(err);
            } else {
                res.ok(vendors);
            }
        });
};

/**
 * Find vendor by id
 */
exports.vendor = function(req, res, next, id) {

    Vendor.load(id, function(err, vendor) {
        if (err) return next(err);
        if (!vendor) {
            return res.failure('No results', 404);
        }
        req.vendor = vendor;
        next();
    });
};

/**
 * Find vendor by req.body.vendorId or req.params.vendorId
 * @todo this should be able to piggy back on exports.vendor by checkig for params and body if
 *    id doesn't exist ad the 4th param. However this was not working and causing errors.
 *
 */
exports.findByBodyOrParams = function(req, res, next) {
    
    var id = null;

    if(req.body && req.body.vendorId) {
        id = req.body.vendorId;
    } else if(req.params && req.params.vendorId) {
        id = req.params.vendorId;
{'fraction_non_alphanumeric': 0.1335095836087244, 'fraction_numerical': 0.0026437541308658294, 'mean_word_length': 2.4594285714285715, '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': '2249707', 'n_tokens_mistral': 939, 'n_tokens_neox': 915, 'n_words': 286}