Skip to content

Instantly share code, notes, and snippets.

@gajus
Created September 30, 2014 16:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gajus/5a3fba8e12249f4ee4b2 to your computer and use it in GitHub Desktop.
Save gajus/5a3fba8e12249f4ee4b2 to your computer and use it in GitHub Desktop.
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