<commit_before>// TODO: Improve errormessages: hide the real messages, write a errorhandler, ...

var express = require('express');
var authentificator = require('./authMiddleware');

function getEntries(Model){
    return function(req, res, next){
        Model.find(function(err, entries){
            if(err){
                res.send(err);
                return;
            }
            res.send(entries);
        });
    }
}

function getEntry(Model) {
    return function (req, res, next) {
        var id = req.params.id;
        Model.findById(id, function (err, entry) {
            if (err) {
                res.send(err);
                return;
            }
            res.send(entry);
        });
    }
}

function createEntry(Model) {
    return function (req, res, next) {
        var model = new Model();
        Model.schema.eachPath(function(path) {
            if(req.body[path]){
                model[path] = req.body[path];
            }
        });

        model.save(function (err) {
            if (err) {
                res.send(err);
                return;
            }
            res.send({message: Model.modelName + ' created'});
        });
    }
}

function updateEntry(Model) {
    return function (req, res, next) {
        var id = req.params.id;
        Model.findById(id, function (err, entry) {
            if (err) {
                res.send(err);
                return;
            }
            Model.schema.eachPath(function(path) {
                if(req.body[path]){
                    entry[path] = req.body[path];
                }
            });
            entry.save(function (err) {
                if (err) {
                    res.send(err);
                    return;
                }
                res.send({message: Model.modelName + ' updated'});
            });
        });
    }
}

function deleteEntry(Model) {
    return function (req, res, next) {
        var id = req.params.id;<commit_msg>fixed bug that it isnt possible to save false<commit_after>// TODO: Improve errormessages: hide the real messages, write a errorhandler, ...

var express = require('express');
var authentificator = require('./authMiddleware');

function getEntries(Model){
    return function(req, res, next){
        Model.find(function(err, entries){
            if(err){
                res.send(err);
                return;
            }
            res.send(entries);
        });
    }
}

function getEntry(Model) {
    return function (req, res, next) {
        var id = req.params.id;
        Model.findById(id, function (err, entry) {
            if (err) {
                res.send(err);
                return;
            }
            res.send(entry);
        });
    }
}

function createEntry(Model) {
    return function (req, res, next) {
        var model = new Model();
        Model.schema.eachPath(function(path) {
            if(req.body[path]){
                model[path] = req.body[path];
            }
        });

        model.save(function (err) {
            if (err) {
                res.send(err);
                return;
            }
            res.send({message: Model.modelName + ' created'});
        });
    }
}

function updateEntry(Model) {
    return function (req, res, next) {
        console.log("req",req.body);
        var id = req.params.id;
        Model.findById(id, function (err, entry) {
            if (err) {
                res.send(err);
                return;
            }
            Model.schema.eachPath(function(path) {
                if(req.body.hasOwnProperty(path)){
                    entry[path] = req.body[path];
                }
            });
            entry.save(function (err) {
                if (err) {
                    res.send(err);
                    return;
                }
                res.send({message: Model.modelName + ' updated'});
            });
        });
    }
}

function deleteEntry(Model) {
    return function (req, res, next) {
        var id = req.params.id;
{'fraction_non_alphanumeric': 0.12947316103379722, 'fraction_numerical': 0.0, 'mean_word_length': 1.3524254821741672, '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': '491858', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1107, 'n_words': 234}