-
Notifications
You must be signed in to change notification settings - Fork 3
/
order-api.js
53 lines (48 loc) · 1.71 KB
/
order-api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var request = require('request');
var auth = require('./auth');
var helper = require('./helpers');
var c = require('./config.json');
var api = {};
api.createOrder = function (userID, restaurantID) {
return new Promise(function (resolve, reject) {
request
.post({
'url': c.url + '/users/' + userID + '/orders/',
headers: {
'authentication': auth.getAuth(),
"Content-Type": "application/json"
},
body: JSON.stringify({"restaurant_id": restaurantID})
}, helper.handleResponse(resolve, reject));
});
};
api.addToCart = function (order, item) {
order.sections[0].items.push(item);
order.operation = "validate";
return new Promise(function (resolve, reject) {
request
.put({
'url': c.url + '/users/' + order.general.user_id + '/orders/' + order.id + '/',
headers: {
'authentication': auth.getAuth(),
"Content-Type": "application/json"
},
body: JSON.stringify(order)
}, helper.handleResponse(resolve, reject));
});
};
api.checkout = function (order) {
order.operation = "final";
return new Promise(function (resolve, reject) {
request
.put({
'url': c.url + '/users/' + order.general.user_id + '/orders/' + order.id + '/',
headers: {
'authentication': auth.getAuth(),
"Content-Type": "application/json"
},
body: JSON.stringify(order)
}, helper.handleResponse(resolve, reject));
});
};
module.exports = api;