<commit_before>'use strict';

/**
 * Module dependencies.
 */
var mongoose = require('mongoose'),
    Card = mongoose.model('Card'),
    Pack = mongoose.model('Pack'),
    _ = require('lodash');

/**
 * Get the error message from error object
 */
var getErrorMessage = function (err) {
    var message = '';

    if (err.code) {
        switch (err.code) {
            case 11000:
            case 11001:
                message = 'Card already exists';
                break;
            default:
                message = 'Something went wrong ' + err;
        }
    } else {
        for (var errName in err.errors) {
            if (err.errors[errName].message) message = err.errors[errName].message;
        }
    }

    return message;
};

/**
 * Create a Card
 */
exports.create = function (req, res) {

    var card = new Card(req.body);


    if (req.body.userId) {
        card.user = req.body.userId;
    } else {
        card.user = req.user;
    }


    card.save(function (err) {
        if (err) {
            return res.send(400, {
                message: getErrorMessage(err)
            });
        } else {
            res.jsonp(card);
        }
    });
};

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


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


    if (true) {
        return res.send(400, {

            message: 'test'
        });
    }

    var card = req.card;


    //card.__v = undefined;
    card = _.extend(card, req.body);




    if (!req.body.startDate) {
        card.startDate = undefined;
    }


    if (!req.body.dueDate) {
        card.dueDate = undefined;
    }


    if (!req.body.answer) {
        card.answer = undefined;
    }

    if (!req.body.question) {<commit_msg>trying to fix up production<commit_after>'use strict';

/**
 * Module dependencies.
 */
var mongoose = require('mongoose'),
    Card = mongoose.model('Card'),
    Pack = mongoose.model('Pack'),
    _ = require('lodash');

/**
 * Get the error message from error object
 */
var getErrorMessage = function (err) {
    var message = '';

    if (err.code) {
        switch (err.code) {
            case 11000:
            case 11001:
                message = 'Card already exists';
                break;
            default:
                message = 'Something went wrong ' + err;
        }
    } else {
        for (var errName in err.errors) {
            if (err.errors[errName].message) message = err.errors[errName].message;
        }
    }

    return message;
};

/**
 * Create a Card
 */
exports.create = function (req, res) {

    var card = new Card(req.body);


    if (req.body.userId) {
        card.user = req.body.userId;
    } else {
        card.user = req.user;
    }


    card.save(function (err) {
        if (err) {
            return res.send(400, {
                message: getErrorMessage(err)
            });
        } else {
            res.jsonp(card);
        }
    });
};

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


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


    //if (true) {
    //    return res.send(400, {
    //
    //        message: 'test'
    //    });
    //}

    var card = req.card;


    //card.__v = undefined;
    card = _.extend(card, req.body);




    if (!req.body.startDate) {
        card.startDate = undefined;
    }


    if (!req.body.dueDate) {
        card.dueDate = undefined;
    }


    if (!req.body.answer) {
        card.answer = undefined;
    }

    if (!req.body.question) {
{'fraction_non_alphanumeric': 0.14634146341463414, 'fraction_numerical': 0.008869179600886918, 'mean_word_length': 1.6247272727272728, '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': '4927534', 'n_tokens_mistral': 1192, 'n_tokens_neox': 1124, 'n_words': 260}