<commit_before>/**
 * Created by alex on 01.08.2015.
 */

var paginator = require("paginator-express"),
    _ = require('lodash'),
    express = require('express');

var router = express.Router();

module.exports = function (model) {
    var ctrl = new Controller(model);
    return ctrl;
};

function Controller(model) {
    var controller = {
        list: paginator.controller(model.find()),
        create: function (req, res, next) {
            var m = new model(req.body);

            m.save()
                .then(function (result) {
                    res.status(201);
                    res.json(result);
                }, next)

        },
        read: function (req, res, next) {
            load(model, req.params.id || req.query.id)
                .then(function (result) {
                    res.status(200);
                    res.json(result)
                }, next)
        },
        update: function (req, res, next) {
            load(model, req.params.id || req.query.id)
                .then(function (result) {
                    _.assign(result, req.body);
                    return result.save();
                }, next)
                .then(function (result) {
                    res.status(203);
                    res.json(result)
                }, next)
        },
        delete: function (req, res, next) {
            load(model, req.params.id || req.query.id)
                .then(function (result) {
                    return result.remove();
                }, next)
                .then(function () {
                    res.status(203);
                    res.end();
                }, next)
        }
    };
<commit_msg>добавил переопредление/кастомное подключение действий в контроллер<commit_after>/**
 * Created by alex on 01.08.2015.
 */

var paginator = require("paginator-express"),
    _ = require('lodash'),
    express = require('express');

var router = express.Router();

module.exports = function (model, customActions) {
    var ctrl = new Controller(model);

    _.forOwn(customActions, function (action, name) {
        ctrl[name] = action;
    })

    return ctrl;
};

function Controller(model) {
    var controller = {
        list: paginator.controller(model.find()),
        create: function (req, res, next) {
            var m = new model(req.body);

            m.save()
                .then(function (result) {
                    res.status(201);
                    res.json(result);
                }, next)

        },
        read: function (req, res, next) {
            load(model, req.params.id || req.query.id)
                .then(function (result) {
                    res.status(200);
                    res.json(result)
                }, next)
        },
        update: function (req, res, next) {
            load(model, req.params.id || req.query.id)
                .then(function (result) {
                    _.assign(result, req.body);
                    return result.save();
                }, next)
                .then(function (result) {
                    res.status(203);
                    res.json(result)
                }, next)
        },
        delete: function (req, res, next) {
            load(model, req.params.id || req.query.id)
                .then(function (result) {
                    return result.remove();
                }, next)
                .then(function () {
                    res.status(203);
                    res.end();
                }, next)
        }
    };
{'fraction_non_alphanumeric': 0.1297926725362113, 'fraction_numerical': 0.01136040897472309, 'mean_word_length': 1.2855288773523685, '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': '1818878', 'n_tokens_mistral': 1003, 'n_tokens_neox': 925, 'n_words': 202}