<commit_before>'use strict';

function Dao(model) {
    this.model = model;
}

Dao.prototype = {
    handlePromise: function(promise, context, name) {
        promise
            .success(function(results) {
                var respObj = {};
                respObj[name] = results;
                context.res.send(respObj);
            })
            .error(function(error) {
                context.next(error);
            });
    },
    findAll: function(context, name) {
        var promise = this.model.findAll();
        this.handlePromise(promise, context, name);
    },
    create: function(context, name, params) {
        var promise = this.model.create(params);
        this.handlePromise(promise, context, name);
    },
    show: function(context, name, id) {
        var promise = this.model.find(id);
        this.handlePromise(promise, context, name);
    },
    update: function(context, name, id, params) {
        this.model.find(id)
            .success(function(result) {
                result.updateAttributes(params)
                    .success(function() {
                        var respObj = {};
                        respObj[name] = result;
                        context.res.send(respObj);
                    })
                    .error(function(error) {
                        context.next(error);
                    });
            })
            .error(function(error) {
                context.next(error);
            });
    },
    destroy: function(context, name, id) {
        this.model.find(id)
            .success(function(result) {
                result.destroy()
                    .success(function(result) {
                        var respObj = {};
                        respObj[name] = {};
                        context.res.send(respObj);
                    })
                    .error(function(error) {
                        context.next(error);
                    });
            })
            .error(function(error) {
                context.next(error);
            });
    },
    deleteAll: function(context) {
        if (process.env.NODE_ENV === 'test') {
            this.model.destroy();
        }
        context.res.send({});
    }
};

module.exports = Dao;<commit_msg>Refractor DAO<commit_after>'use strict';

function Dao(model) {
    this.model = model;
}

Dao.prototype = {
    handlePromise: function(promise, context, name) {
        promise
            .success(function(results) {
                var respObj = {};
                respObj[name] = results;
                context.res.send(respObj);
            })
            .error(function(error) {
                context.next(error);
            });
    },
    create: function(context, name, params) {
        var promise = this.model.create(params);
        this.handlePromise(promise, context, name);
    },
    deleteAll: function(context) {
        if (process.env.NODE_ENV === 'test') {
            this.model.destroy();
        }
        context.res.send({});
    },
    destroy: function(context, name, id) {
        this.model.find(id)
            .success(function(result) {
                result.destroy()
                    .success(function(result) {
                        var respObj = {};
                        respObj[name] = {};
                        context.res.send(respObj);
                    })
                    .error(function(error) {
                        context.next(error);
                    });
            })
            .error(function(error) {
                context.next(error);
            });
    },
    findAll: function(context, name) {
        var promise = this.model.findAll();
        this.handlePromise(promise, context, name);
    },
    show: function(context, name, id) {
        var promise = this.model.find(id);
        this.handlePromise(promise, context, name);
    },
    update: function(context, name, id, params) {
        this.model.find(id)
            .success(function(result) {
                result.updateAttributes(params)
                    .success(function() {
                        var respObj = {};
                        respObj[name] = result;
                        context.res.send(respObj);
                    })
                    .error(function(error) {
                        context.next(error);
                    });
            })
            .error(function(error) {
                context.next(error);
            });
    }
};

module.exports = Dao;
{'fraction_non_alphanumeric': 0.1257219013771657, 'fraction_numerical': 0.0, 'mean_word_length': 1.2765419615773508, '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': '1047692', 'n_tokens_mistral': 1183, 'n_tokens_neox': 1136, 'n_words': 184}