From f0a7c05174ad4d912fff35d52973163cfd8787ef Mon Sep 17 00:00:00 2001 From: Jack Foltz Date: Tue, 14 Aug 2018 08:42:05 -0400 Subject: [PATCH] Update key service to use (err, data) callbacks --- app/public/services/KeySvc.js | 55 +++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 26 deletions(-) diff --git a/app/public/services/KeySvc.js b/app/public/services/KeySvc.js index 2394573..16f6e65 100644 --- a/app/public/services/KeySvc.js +++ b/app/public/services/KeySvc.js @@ -1,28 +1,7 @@ var angular = require('angular'); -angular.module('KeySvc', []).service('KeyService', ['$http', function ($http) { - this.getAllKeys = function (cb) { - $http({ - method: 'GET', - url: '/api/keys/get' - }).then(function (res) { - cb(res.data); - }); - }; - - this.deleteKey = function (key, cb) { - $http({ - method: 'POST', - url: '/api/keys/delete', - data: { - key: key - } - }).then(function (res) { - cb(res.data); - }); - }; - - this.createKey = function (identifier, scope, cb) { +angular.module('KeySvc', []).service('KeyService', ['$http', function($http) { + this.createKey = (identifier, scope, cb) => $http({ method: 'POST', url: '/api/keys/create', @@ -30,8 +9,32 @@ angular.module('KeySvc', []).service('KeyService', ['$http', function ($http) { identifier: identifier, scope: scope } - }).then(function(res) { - cb(res.data); + }).then(res => { + cb(null, res.data) + }).catch(err => { + cb(err); + }); + + this.deleteKey = (key, cb) => + $http({ + method: 'POST', + url: '/api/keys/delete', + data: { + key: key + } + }).then(res => { + cb(null, res.data); + }).catch(err => { + cb(err); + }); + + this.getAllKeys = cb => + $http({ + method: 'GET', + url: '/api/keys/get' + }).then(res => { + cb(null, res.data); + }).catch(err => { + cb(err); }); - }; }]);