<commit_before>var moment = require('moment');
var express = require('express');
var debug = require('debug')('service-route');
var serviceValidator = require('./../../lib/service-validator');

module.exports.getRoutes = function (storage){

    var router = express.Router();

    /**
     * Add service
     */
    //TODO: auth
    router.post('/services', function(req, res){
        var service = req.body;

        debug('loading services');
        var errors = serviceValidator.validate(service);
        if (errors.length) {
            return res.status(400).json({ errors: errors });
        }
        storage.addService(service, function(err, id){
            if (err) {
                return res.status(500).json({ error: err });
            }
            debug('loading loaded');
            return res.status(200).json({ id: id });
        });
    });

    /**
     * Load service
     */

    router.get('/services/:id', function(req, res){
        if (!req.params.id) {
            return res.status(400).json({ error: 'ID parameter not found' });
        }
        storage.getService(req.params.id, function (err, service){
            if (err) {
                console.error(err);
                return res.status(500).json({ error: err });
            }
            res.json(service);
        });
    });

    /**<commit_msg>Add delete route<commit_after>var moment = require('moment');
var express = require('express');
var debug = require('debug')('service-route');
var serviceValidator = require('./../../lib/service-validator');

module.exports.getRoutes = function (storage){

    var router = express.Router();

    /**
     * Add service
     */
    //TODO: auth
    router.post('/services', function(req, res){
        var service = req.body;

        var errors = serviceValidator.validate(service);
        if (errors.length) {
            return res.status(400).json({ errors: errors });
        }
        storage.addService(service, function(err, id){
            if (err) {
                return res.status(500).json({ error: err });
            }
            return res.status(200).json({ id: id });
        });
    });

    /**
     * Delete service
     */
    //TODO: auth
    router.delete('/services/:id', function(req, res){
        var id = req.params.id;
        if (!id) {
            return res.status(400).json({ error: 'ID parameter not found' });
        }
        storage.getService(id, function(err, service){
            if (err) {
                return res.status(500).json({ error: err });
            }

            if (!service) {
                return res.status(400).json({ error: 'service not found' });
            }

            storage.deleteService(id, function(err){
                if (err) {
                    return res.status(500).json({ error: err });
                }
                return res.status(200).json({ id: id });
            });
        });
    });



    /**
     * Load service
     */

    router.get('/services/:id', function(req, res){
        if (!req.params.id) {
            return res.status(400).json({ error: 'ID parameter not found' });
        }
        storage.getService(req.params.id, function (err, service){
            if (err) {
                console.error(err);
                return res.status(500).json({ error: err });
            }
            res.json(service);
        });
    });

    /**
{'fraction_non_alphanumeric': 0.16055180510713238, 'fraction_numerical': 0.013208100968594072, 'mean_word_length': 1.7198723064644852, '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': '4719155', 'n_tokens_mistral': 970, 'n_tokens_neox': 915, 'n_words': 206}