/**
 * @package admiral
 * @author Andrew Munsell <andrew@wizardapps.net>
 * @copyright 2015 WizardApps
 */

exports = module.exports = function(app, config) {
    /**
     * Get the services
     */
    app.get('/v1/services', function(req, res) {
        config.getAsync('/services', { recursive: true })
            .spread(function(result) {
                res
                    .header('Cache-Control', 'private, max-age=60')
                    .json((result.node.nodes || [] ).map(function(node) {
                        return JSON.parse(node.value);
                    }));
            })
            .catch(function(err) {
                if(err.errorCode == 100) {
                    res
                        .json([]);
                } else {
                    res
                        .status(500)
                        .json({
                            error: 500,
                            message: 'There was a problem retrieving the list of services.'
                        });
                }
            })
            .finally(function() {
                res.end();
            });
    });
};

exports['@singleton'] = true;
exports['@require'] = ['app', 'config'];
@@ -149,16 +149,26 @@
 , config
+, Services
 ) %7B%0A    
@@ -264,56 +264,21 @@
     
-config.getAsync('/services', %7B recursive: true %7D
+Services.all(
 )%0A  
@@ -292,14 +292,12 @@
    .
-spread
+then
 (fun
@@ -302,22 +302,24 @@
 unction(
-result
+services
 ) %7B%0A    
@@ -432,341 +432,89 @@
 son(
-(result.node.nodes %7C%7C %5B%5D ).map(function(node) %7B%0A                        return JSON.parse(node.value);%0A                    %7D));%0A            %7D)%0A            .catch(function(err) %7B%0A                if(err.errorCode == 100) %7B%0A                    res%0A                        .json(%5B%5D);%0A                %7D else %7B%0A                    res%0A    
+services);%0A            %7D)%0A            .catch(function(err) %7B%0A                res%0A
     
@@ -542,20 +542,16 @@
 us(500)%0A
-    
         
@@ -594,20 +594,16 @@
         
-    
 error: 5
@@ -606,20 +606,16 @@
 r: 500,%0A
-    
         
@@ -718,33 +718,11 @@
     
-    %7D);%0A                %7D
+%7D);
 %0A   
@@ -890,10 +890,29 @@
 'config'
+, 'models/Services'
 %5D;

Use new services model helper