Created
September 30, 2014 16:41
-
-
Save gajus/5a3fba8e12249f4ee4b2 to your computer and use it in GitHub Desktop.
This file contains 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 characters
angular | |
.module('store') | |
.constant('productUrl', 'https://api.parse.com/1/classes/Product/') | |
.constant('orderUrl', 'https://api.parse.com/1/classes/Product/') | |
.controller('storeController', function ($scope, $http, $location, productUrl, orderUrl, cart) { | |
$scope.data = {}; | |
$http | |
.get(productUrl, { | |
headers: { | |
'X-Parse-Application-Id': 'NBLhjbKwI3xcPHyygU0hF2gLFaIVzeIGH9lv1q1E', | |
'X-Parse-REST-API-Key': 'drEzPQCr3rJGZ4i0nk7l7Bq68onUDGqwJWdpHa4n' | |
} | |
}) | |
.success(function (data) { | |
$scope.data.products = data.results; | |
}) | |
.error(function (error) { | |
if (!error) { | |
error = {status: '000'} | |
} | |
$scope.data.error = error; | |
}); | |
$scope.sendOrder = function (shippingDetails) { | |
var order = angular.copy(shippingDetails); | |
order.products = cart.getProducts(); | |
$http | |
.post(orderUrl, { | |
headers: { | |
'X-Parse-Application-Id': 'NBLhjbKwI3xcPHyygU0hF2gLFaIVzeIGH9lv1q1E', | |
'X-Parse-REST-API-Key': 'drEzPQCr3rJGZ4i0nk7l7Bq68onUDGqwJWdpHa4n' | |
} | |
}) | |
.success(function (data) { | |
$scope.data.orderId = data.objectId; | |
cart.getProducts().length = 0; | |
}) | |
.error(function (data) { | |
if (!error) { | |
error = {status: '000'} | |
} | |
$scope.data.error = error; | |
}) | |
.finally(function () { | |
$location.path('/complete'); | |
}); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment