<commit_before>'use strict';

var _ = require('lodash');
var tasks = require('../../../models/tasks');


module.exports = function (router) {
    var onTaskPostOrPut = function(req, res) {
        var taskID = req.params.taskID || req.body.id;
        var task = req.body;
        task.owner = req.user.id;
        tasks.put(taskID, task, function (err, results) {
            if (err) {
                res.sendStatus(500);
                throw err;
            }

            res.status(200);
            res.send(results);
        });
    };
    router.put('/', onTaskPostOrPut);
    router.get('/', function (req, res) {
        tasks.get(function (err, results) {
            if (err) {
                res.sendStatus(500);
                throw err;
            }

            res.status(200);
            res.send(results);
        });
    });

    router.post('/', function(req, res) {
        var newTask = req.body;
        newTask.owner = req.user.id;
        tasks.post(newTask, function (err, results) {
            if (err) {
                res.sendStatus(500);
                throw err;
            }

            res.status(200);
            res.send(results);
        });
    });

    router.get('/:taskID', function(req, res) {
        var taskID = req.params.taskID;

        tasks.get(taskID, function (err, results) {
            if (err) {
                res.sendStatus(500);
                throw err;
            }

            res.status(200);
            res.send(results);
        })
    });

    router.post('/:taskID', onTaskPostOrPut);

    router.put('/:taskID', onTaskPostOrPut);

    router.delete('/', function(req, res) {
        var taskID = req.params.taskID;

        tasks.delete(taskID, function(err, results) {
            if (err) {
                res.sendStatus(500);
                throw err;
            }

            res.status(200);
            res.send(results);
        });
    });
};<commit_msg>fix(api/tasks): fix the tasks delete and get<commit_after>'use strict';

var _ = require('lodash');
var tasks = require('../../../models/tasks');


module.exports = function (router) {
    var onTaskPostOrPut = function(req, res) {
        var taskID = req.params.taskID || req.body.id;
        var task = req.body;
        task.owner = req.user.id;
        tasks.put(taskID, task, function (err, results) {
            if (err) {
                res.sendStatus(500);
                throw err;
            }

            res.status(200);
            res.send(results);
        });
    };
    router.put('/', onTaskPostOrPut);
    router.get('/', function (req, res) {
            tasks.get(function (err, results) {
                if (err) {
                    res.sendStatus(500);
                    throw err;
                }

                res.status(200);
                res.send(results);
            });

    });

    router.post('/', function(req, res) {
        var newTask = req.body;
        newTask.owner = req.user.id;
        tasks.post(newTask, function (err, results) {
            if (err) {
                res.sendStatus(500);
                throw err;
            }

            res.status(200);
            res.send(results);
        });
    });

    router.get('/:taskID', function(req, res) {
        var taskID = req.params.taskID;

        tasks.get(taskID, function (err, results) {
            if (err) {
                res.sendStatus(500);
                throw err;
            }

            res.status(200);
            res.send(results);
        })
    });

    router.post('/:taskID', onTaskPostOrPut);

    router.put('/:taskID', onTaskPostOrPut);

    router.delete('/:id', function(req, res) {
        var taskID = req.params.id;
        tasks.delete(taskID, function(err, results) {
            if (err) {
                res.sendStatus(500);
                throw err;
            }

            res.status(200);
            res.send(results);
        });
    });
};
{'fraction_non_alphanumeric': 0.1459909228441755, 'fraction_numerical': 0.015128593040847202, 'mean_word_length': 1.3754491017964072, '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': '5912728', 'n_tokens_mistral': 1233, 'n_tokens_neox': 1140, 'n_words': 220}