<commit_before>var _ = require('lodash'),
    debug = require('debug')('freecc:cntr:courseware'),
    Courseware = require('./../models/Courseware'),
    User = require('./../models/User'),
    resources = require('./resources');

/**
 * Courseware controller
 */

exports.coursewareNames = function(req, res) {
    res.render('coursewares/showList', {
        coursewareList: resources.allCoursewareNames()
    });
};

exports.returnNextCourseware = function(req, res, next) {
    if (!req.user) {
        return res.redirect('../coursewares/start-our-challenges');
    }
    var completed = req.user.completedCoursewares.map(function (elem) {
        return elem._id;
    });

    req.user.uncompletedCoursewares = resources.allCoursewareIds().filter(function (elem) {
        if (completed.indexOf(elem) === -1) {
            return elem;
        }
    });

    // *****CALLBACK
    req.user.save();

    var uncompletedCoursewares = req.user.uncompletedCoursewares;

    var displayedCoursewares =  Courseware.find({'_id': uncompletedCoursewares[0]});
    displayedCoursewares.exec(function(err, courseware) {
        if (err) {
            return next(err);
        }
        courseware = courseware.pop();
        if (courseware === undefined) {
            req.flash('errors', {
                msg: "It looks like you've completed all the courses we have available. Good job!"<commit_msg>Fixed user.save error callback handler<commit_after>var _ = require('lodash'),
    debug = require('debug')('freecc:cntr:courseware'),
    Courseware = require('./../models/Courseware'),
    User = require('./../models/User'),
    resources = require('./resources');

/**
 * Courseware controller
 */

exports.coursewareNames = function(req, res) {
    res.render('coursewares/showList', {
        coursewareList: resources.allCoursewareNames()
    });
};

exports.returnNextCourseware = function(req, res, next) {
    if (!req.user) {
        return res.redirect('../coursewares/start-our-challenges');
    }
    var completed = req.user.completedCoursewares.map(function (elem) {
        return elem._id;
    });

    req.user.uncompletedCoursewares = resources.allCoursewareIds().filter(function (elem) {
        if (completed.indexOf(elem) === -1) {
            return elem;
        }
    });

    // *****CALLBACK
    req.user.save(function(err) {
        if (err) {
            return next(err);
        }
        else {
            return;
        }
    });

    var uncompletedCoursewares = req.user.uncompletedCoursewares;

    var displayedCoursewares =  Courseware.find({'_id': uncompletedCoursewares[0]});
    displayedCoursewares.exec(function(err, courseware) {
        if (err) {
            return next(err);
        }
        courseware = courseware.pop();
        if (courseware === undefined) {
            req.flash('errors', {
                msg: "It looks like you've completed all the courses we have available. Good job!"
{'fraction_non_alphanumeric': 0.14717878993881714, 'fraction_numerical': 0.0013596193065941536, 'mean_word_length': 2.66044776119403, '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': '7626845', 'n_tokens_mistral': 895, 'n_tokens_neox': 842, 'n_words': 159}