<commit_before>var mongoose = require("mongoose");
var zngm = mongoose.model("enigmes");

var sendJsonResponse = function(res, status, content) {
    res.status(status);
    res.json(content);
};

module.exports.enigmesList = function(req, res){
    zngm.find()
    .select("-description")
    .exec(
        function(err, enigmes){
            if (err){
                sendJsonResponse(res, 404, err);
            }else{
                sendJsonResponse(res, 200, enigmes);
            }
        }
        );
};

module.exports.enigmeCreate = function(req, res){
    
    zngm.create({
        titre: req.body.titre,
        description: req.body.description,
        niveau: req.body.niveau,
        points: req.body.points,
        numericAnswer: req.body.numericAnswer,
        textualAnswer: req.body.textualAnswer,

    }, function(err, location){

        if (err){
            sendJsonResponse(res, 400, err);
        }else{
            sendJsonResponse(res, 201, location);
        }
    });
};

function _maskAnswers(admin, enigme){
    // if not admin, the Answers are masked
    if (!admin){
        if (enigme.numericAnswer) enigme.numericAnswer = 00000;
        if (enigme.textualAnswer) enigme.textualAnswer = "xxxxx";
    }
}

module.exports.enigmeReadOne = function(req, res){
    if (req.params && req.params.enigmeid){
        zngm.findById(req.params.enigmeid).exec(function(err, enigme){
            if (!enigme){
                sendJsonResponse(res, 404, {"message":"enigmeid not found"});<commit_msg>masked numeric answer should be different from 0 to avoid issues<commit_after>var mongoose = require("mongoose");
var zngm = mongoose.model("enigmes");

var sendJsonResponse = function(res, status, content) {
    res.status(status);
    res.json(content);
};

module.exports.enigmesList = function(req, res){
    zngm.find()
    .select("-description")
    .exec(
        function(err, enigmes){
            if (err){
                sendJsonResponse(res, 404, err);
            }else{
                sendJsonResponse(res, 200, enigmes);
            }
        }
        );
};

module.exports.enigmeCreate = function(req, res){
    
    zngm.create({
        titre: req.body.titre,
        description: req.body.description,
        niveau: req.body.niveau,
        points: req.body.points,
        numericAnswer: req.body.numericAnswer,
        textualAnswer: req.body.textualAnswer,

    }, function(err, location){

        if (err){
            sendJsonResponse(res, 400, err);
        }else{
            sendJsonResponse(res, 201, location);
        }
    });
};

function _maskAnswers(admin, enigme){
    // if not admin, the Answers are masked
    if (!admin){
        if (enigme.numericAnswer) enigme.numericAnswer = 9999999;
        if (enigme.textualAnswer) enigme.textualAnswer = "xxxxx";
    }
}

module.exports.enigmeReadOne = function(req, res){
    if (req.params && req.params.enigmeid){
        zngm.findById(req.params.enigmeid).exec(function(err, enigme){
            if (!enigme){
                sendJsonResponse(res, 404, {"message":"enigmeid not found"});
{'fraction_non_alphanumeric': 0.132130196583951, 'fraction_numerical': 0.013857557202707057, 'mean_word_length': 2.392349726775956, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, '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': '5693260', 'n_tokens_mistral': 1052, 'n_tokens_neox': 966, 'n_words': 193}