Created
September 30, 2014 03:11
Revisions
-
joncodo created this gist
Sep 30, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ myApp.service('DealRetrievalService', ['$http', function($http) { var _this = this; return { removeInactiveDeals: function (deals) { var newDeals = []; _.forEach(deals, function (deal) { if(deal.status === 'Active'){ newDeals.push(deal); } }); return newDeals; }, removeExpiredDeals: function (deals) { var newDeals = []; _.forEach(deals.data, function (deal) { var validTo = Date.parse(deal.valid_to); var today = new Date(); if(validTo > today){ newDeals.push(deal); } }); return _this.removeInactiveDeals(newDeals); }, getAllDeals: function() { return $http.get('/dealRecord') .success(function(deals) { var temp = _this.removeExpiredDeals(deals.data); console.log('deals were:', temp); return _this.removeExpiredDeals(deals.data); }) .error(function(err) { }); }, getRelatedDeals: function (category, retailer) { var q = '/dealRecord?status=Active'; if(category && category !== 'All'){ q += '&category=' + category; } if(retailer && retailer !== 'All'){ q += '&retailer=' + retailer; } return $http.get(q) .success(function(deals) { return _this.removeExpiredDeals(deals.data); }) .error(function(err) { }); } }; }]);