orderiom-api-package 0.4.98 → 0.4.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/common.js +7 -10
- package/src/modules/auth.js +298 -319
- package/src/modules/order.js +24 -92
- package/src/modules/product.js +8 -27
package/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -31,8 +31,10 @@ export function commonErrorCallback(unknownErrorMessage = 'Something went wrong'
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export function calculateBasketIdParameter(
|
|
35
|
-
|
|
34
|
+
export function calculateBasketIdParameter(restaurantId) {
|
|
35
|
+
const pt = !!localStorage.getItem('privateToken');
|
|
36
|
+
if(pt) return undefined
|
|
37
|
+
|
|
36
38
|
// localStorage might fail
|
|
37
39
|
let baskets = [];
|
|
38
40
|
try{
|
|
@@ -155,10 +157,7 @@ const getAuthToken = async ($store, hadPrivateToken = false) => {
|
|
|
155
157
|
return commonErrorCallback()(error)
|
|
156
158
|
} finally {
|
|
157
159
|
while (reqBuffer.length) {
|
|
158
|
-
let basketId = null;
|
|
159
|
-
if(hadPrivateToken){
|
|
160
|
-
basketId = calculateBasketIdParameter(false, restaurantIdEnv())
|
|
161
|
-
}
|
|
160
|
+
let basketId = hadPrivateToken ? calculateBasketIdParameter() : null;
|
|
162
161
|
reqBuffer.shift()(basketId); // First in First out
|
|
163
162
|
}
|
|
164
163
|
isFetchingToken = false;
|
|
@@ -178,14 +177,12 @@ export const defineInterceptors = ({$store}) => {
|
|
|
178
177
|
if(idFromEnv && !data.restaurantId) data.restaurantId = idFromEnv;
|
|
179
178
|
config[key] = data;
|
|
180
179
|
|
|
181
|
-
const userId = $store.state.orderiomApiPackage.auth.user.id;
|
|
182
|
-
|
|
183
180
|
// use the valid token if possible
|
|
184
181
|
let token = localStorage.getItem("privateToken") || localStorage.getItem("publicToken");
|
|
185
182
|
if(
|
|
186
183
|
token &&
|
|
187
184
|
!isTokenExpired(token) &&
|
|
188
|
-
(
|
|
185
|
+
(!$store.getters['auth/userId'] || localStorage.getItem("privateToken")) // if userId exists then private token must exist too
|
|
189
186
|
){
|
|
190
187
|
config.headers["Authorization"] = `Bearer ${token}`
|
|
191
188
|
return config;
|
|
@@ -193,7 +190,7 @@ export const defineInterceptors = ({$store}) => {
|
|
|
193
190
|
|
|
194
191
|
// if the token is expired or does not exist, wait for public token to be fetched
|
|
195
192
|
return new Promise((resolve, reject) => {
|
|
196
|
-
const hadPrivateToken = Boolean(localStorage.getItem("privateToken") || userId);
|
|
193
|
+
const hadPrivateToken = Boolean(localStorage.getItem("privateToken") || $store.getters['auth/userId']);
|
|
197
194
|
// remove invalid or expired tokens
|
|
198
195
|
token = null;
|
|
199
196
|
localStorage.removeItem("privateToken");
|
package/src/modules/auth.js
CHANGED
|
@@ -1,198 +1,176 @@
|
|
|
1
|
-
import {commonErrorCallback, $http, restaurantIdEnv } from '../common';
|
|
1
|
+
import {commonErrorCallback, $http, restaurantIdEnv, isTokenExpired} from '../common';
|
|
2
2
|
|
|
3
3
|
const state = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
deliveryType: null,
|
|
11
|
-
userAddress: []
|
|
4
|
+
user: {},
|
|
5
|
+
restaurantInfo: {},
|
|
6
|
+
email: null,
|
|
7
|
+
fullAddress: {},
|
|
8
|
+
deliveryType: null,
|
|
9
|
+
userAddress: []
|
|
12
10
|
};
|
|
11
|
+
const getters = {
|
|
12
|
+
isLogin(state) {
|
|
13
|
+
return Boolean(state.user.id)
|
|
14
|
+
},
|
|
15
|
+
userId(state){
|
|
16
|
+
return state.user.id || null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
13
19
|
const mutations = {
|
|
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
|
-
setDeliveryType(state, deliveryType) {
|
|
44
|
-
state.deliveryType = deliveryType
|
|
45
|
-
},
|
|
46
|
-
setUserAddress(state, userAddress) {
|
|
47
|
-
state.userAddress = userAddress
|
|
48
|
-
}
|
|
20
|
+
storeUser(state, userData) {
|
|
21
|
+
state.user = userData
|
|
22
|
+
},
|
|
23
|
+
updateUser(state, userData) {
|
|
24
|
+
state.user = {
|
|
25
|
+
...state.user,
|
|
26
|
+
...userData
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
clearAuthData(state) {
|
|
30
|
+
window.localStorage.removeItem("privateToken");
|
|
31
|
+
state.user = {};
|
|
32
|
+
},
|
|
33
|
+
setrestaurantInfo(state, restaurantInfo) {
|
|
34
|
+
state.restaurantInfo = restaurantInfo
|
|
35
|
+
},
|
|
36
|
+
setEmail(state, email) {
|
|
37
|
+
state.email = email
|
|
38
|
+
},
|
|
39
|
+
setFullAddress(state, fullAddress) {
|
|
40
|
+
state.fullAddress = fullAddress
|
|
41
|
+
},
|
|
42
|
+
setDeliveryType(state, deliveryType) {
|
|
43
|
+
state.deliveryType = deliveryType
|
|
44
|
+
},
|
|
45
|
+
setUserAddress(state, userAddress) {
|
|
46
|
+
state.userAddress = userAddress
|
|
47
|
+
}
|
|
49
48
|
};
|
|
50
49
|
const actions = {
|
|
51
|
-
|
|
50
|
+
auth({}) {
|
|
52
51
|
console.warn('auth/auth action is deprecated. No need to call');
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
commit("authUser", {
|
|
71
|
-
privateToken: res.data.data.access_token,
|
|
72
|
-
expires_at: res.data.data.expires_at
|
|
73
|
-
});
|
|
74
|
-
dispatch("fetchUser");
|
|
75
|
-
const basketData = JSON.parse(window.localStorage.getItem("basket"));
|
|
52
|
+
},
|
|
53
|
+
login({commit, dispatch}, authData) {
|
|
54
|
+
var data = {...authData};
|
|
55
|
+
if (authData.ordermood) {
|
|
56
|
+
delete data.restaurantId;
|
|
57
|
+
delete data.ordermood
|
|
58
|
+
}
|
|
59
|
+
return $http
|
|
60
|
+
.post(`api/auth/login`, data)
|
|
61
|
+
.then(res => {
|
|
62
|
+
if (authData.manager) {
|
|
63
|
+
window.localStorage.setItem("managerToken", res.data.data.access_token);
|
|
64
|
+
return res;
|
|
65
|
+
}
|
|
66
|
+
window.localStorage.setItem("privateToken", res.data.data.access_token);
|
|
67
|
+
dispatch("fetchUser");
|
|
68
|
+
const basketData = JSON.parse(window.localStorage.getItem("basket"));
|
|
76
69
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
70
|
+
const restaurantId = authData.restaurantId || restaurantIdEnv();
|
|
71
|
+
if (Array.isArray(basketData) && restaurantId) {
|
|
72
|
+
for (let i = 0; i < basketData.length; i++) {
|
|
73
|
+
if (basketData[i].restaurantId == restaurantId) {
|
|
74
|
+
dispatch('assignBasket', restaurantId);
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
86
79
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
.get("api/auth/user")
|
|
166
|
-
.then(res => {
|
|
167
|
-
const user = res.data.data;
|
|
168
|
-
user.postalCode = user.postal_code
|
|
169
|
-
commit("storeUser", user);
|
|
170
|
-
})
|
|
171
|
-
.catch(
|
|
172
|
-
commonErrorCallback()
|
|
173
|
-
);
|
|
174
|
-
},
|
|
175
|
-
assignBasket({ dispatch }, restaurantId) {
|
|
176
|
-
const basket = JSON.parse(localStorage.getItem("basket"));
|
|
177
|
-
if(!basket || !Array.isArray(basket)) return;
|
|
178
|
-
const foundBasket = basket.find(item => Number(item.restaurantId) === Number(restaurantId || restaurantIdEnv()))
|
|
179
|
-
const basketId = foundBasket ? foundBasket.basketId : undefined;
|
|
80
|
+
return res
|
|
81
|
+
})
|
|
82
|
+
.catch(
|
|
83
|
+
commonErrorCallback()
|
|
84
|
+
);
|
|
85
|
+
},
|
|
86
|
+
signup({dispatch}, authData) {
|
|
87
|
+
var data = {...authData};
|
|
88
|
+
if (authData.ordermood) {
|
|
89
|
+
delete data.restaurantId;
|
|
90
|
+
delete authData.ordermood
|
|
91
|
+
}
|
|
92
|
+
return $http
|
|
93
|
+
.post(
|
|
94
|
+
`api/auth/signup`, null, {
|
|
95
|
+
params: data
|
|
96
|
+
}
|
|
97
|
+
)
|
|
98
|
+
.then((res) => {
|
|
99
|
+
const restaurantId = authData.restaurantId || restaurantIdEnv();
|
|
100
|
+
const ordermood = authData.ordermood ? {ordermood: authData.ordermood} : {}
|
|
101
|
+
dispatch("login", {
|
|
102
|
+
email: authData.email,
|
|
103
|
+
password: authData.password,
|
|
104
|
+
restaurantId: restaurantId ? restaurantId : undefined,
|
|
105
|
+
...ordermood
|
|
106
|
+
});
|
|
107
|
+
return {
|
|
108
|
+
...res,
|
|
109
|
+
msg: res.data.message.body
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
.catch(
|
|
113
|
+
commonErrorCallback()
|
|
114
|
+
);
|
|
115
|
+
},
|
|
116
|
+
tryAutoLogin({commit, dispatch}) {
|
|
117
|
+
const pt = window.localStorage.getItem("privateToken") || null
|
|
118
|
+
if (!pt || isTokenExpired(pt)) return;
|
|
119
|
+
dispatch('fetchUser')
|
|
120
|
+
},
|
|
121
|
+
logout({commit, state, dispatch}, restaurantId) {
|
|
122
|
+
if (!window.localStorage.getItem("privateToken") && !state.user.id) return;
|
|
123
|
+
return $http
|
|
124
|
+
.get("api/auth/logout", {
|
|
125
|
+
params: {
|
|
126
|
+
restaurantId
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
.then(() => {
|
|
130
|
+
commit("clearAuthData");
|
|
131
|
+
dispatch('unassignBasket', restaurantId)
|
|
132
|
+
// commit("product/SetShoppingCart", [], { root: true });
|
|
133
|
+
// commit("product/SetSubtotalPrice", null, { root: true });
|
|
134
|
+
return true
|
|
135
|
+
})
|
|
136
|
+
.catch(
|
|
137
|
+
commonErrorCallback()
|
|
138
|
+
);
|
|
139
|
+
},
|
|
140
|
+
fetchUser({commit, state}) {
|
|
141
|
+
if (!window.localStorage.getItem("privateToken")) return;
|
|
142
|
+
return $http
|
|
143
|
+
.get("api/auth/user")
|
|
144
|
+
.then(res => {
|
|
145
|
+
const user = res.data.data;
|
|
146
|
+
user.postalCode = user.postal_code
|
|
147
|
+
commit("storeUser", user);
|
|
148
|
+
})
|
|
149
|
+
.catch(
|
|
150
|
+
commonErrorCallback()
|
|
151
|
+
);
|
|
152
|
+
},
|
|
153
|
+
assignBasket({dispatch}, restaurantId) {
|
|
154
|
+
const basket = JSON.parse(localStorage.getItem("basket"));
|
|
155
|
+
if (!basket || !Array.isArray(basket)) return;
|
|
156
|
+
const foundBasket = basket.find(item => Number(item.restaurantId) === Number(restaurantId || restaurantIdEnv()))
|
|
157
|
+
const basketId = foundBasket ? foundBasket.basketId : undefined;
|
|
180
158
|
|
|
181
159
|
// assign basket id to logged-in use (so basket actions need a private token now)
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
160
|
+
basketId && $http
|
|
161
|
+
.post(`api/basket/assign-basket`, {basketId, restaurantId})
|
|
162
|
+
.then(() => {
|
|
163
|
+
dispatch('product/getBasket', restaurantId, {root: true})
|
|
164
|
+
})
|
|
165
|
+
.catch(
|
|
166
|
+
commonErrorCallback()
|
|
167
|
+
);
|
|
168
|
+
},
|
|
169
|
+
unassignBasket(_, restaurantId) {
|
|
192
170
|
restaurantId = restaurantId || restaurantIdEnv();
|
|
193
171
|
let baskets = JSON.parse(localStorage.getItem("basket"));
|
|
194
172
|
|
|
195
|
-
if(!Array.isArray(baskets) || !baskets.length) return;
|
|
173
|
+
if (!Array.isArray(baskets) || !baskets.length) return;
|
|
196
174
|
|
|
197
175
|
// Find all basketId where restaurantId does not exist, or find all basketId linked to a specific restaurantId if it exists.
|
|
198
176
|
const basketsIdToUnassign = baskets.filter(basket => (
|
|
@@ -213,149 +191,150 @@ const actions = {
|
|
|
213
191
|
})
|
|
214
192
|
)
|
|
215
193
|
).catch(commonErrorCallback())
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
194
|
+
},
|
|
195
|
+
restaurantInfo({commit}, restaurantId) {
|
|
196
|
+
return $http
|
|
197
|
+
.get("api/restaurant/restaurant-by-id", {
|
|
198
|
+
params: {
|
|
199
|
+
restaurantId: restaurantId
|
|
200
|
+
}
|
|
201
|
+
})
|
|
202
|
+
.then(res => {
|
|
203
|
+
commit('setrestaurantInfo', res.data.data)
|
|
204
|
+
})
|
|
205
|
+
.catch(
|
|
206
|
+
commonErrorCallback()
|
|
207
|
+
);
|
|
208
|
+
},
|
|
209
|
+
userUpdate({dispatch}, userData) {
|
|
210
|
+
return $http
|
|
211
|
+
.post("api/auth/user/update", {
|
|
212
|
+
params: {
|
|
213
|
+
userData,
|
|
214
|
+
restaurantId: userData.restaurantId
|
|
215
|
+
}
|
|
216
|
+
})
|
|
217
|
+
.then(() => {
|
|
218
|
+
dispatch('fetchUser')
|
|
219
|
+
})
|
|
220
|
+
.catch(
|
|
221
|
+
commonErrorCallback()
|
|
222
|
+
);
|
|
223
|
+
},
|
|
224
|
+
forgotPassword({dispatch}, data) {
|
|
225
|
+
const formData = typeof data == 'object' ? {
|
|
226
|
+
email: data.email,
|
|
227
|
+
restaurantId: data.restaurantId
|
|
228
|
+
} : {email: data};
|
|
229
|
+
return $http
|
|
230
|
+
.post("api/auth/forgot-password", formData)
|
|
231
|
+
.then((res) => {
|
|
232
|
+
dispatch("fetchUser");
|
|
233
|
+
return {
|
|
234
|
+
...res,
|
|
235
|
+
msg: res.data.message.body
|
|
236
|
+
}
|
|
237
|
+
})
|
|
238
|
+
.catch(
|
|
239
|
+
commonErrorCallback()
|
|
240
|
+
);
|
|
241
|
+
},
|
|
242
|
+
checkToken({commit}, token) {
|
|
243
|
+
return $http
|
|
244
|
+
.get(`api/auth/password/reset`, {params: {token: token}})
|
|
245
|
+
.then((res) => {
|
|
246
|
+
commit('setEmail', res.data.data.email);
|
|
247
|
+
return res
|
|
248
|
+
})
|
|
249
|
+
.catch(
|
|
250
|
+
commonErrorCallback()
|
|
251
|
+
);
|
|
252
|
+
},
|
|
253
|
+
resetPassword({}, data) {
|
|
254
|
+
return $http
|
|
255
|
+
.post("api/auth/password/reset-password", {
|
|
256
|
+
email: data.email,
|
|
257
|
+
token: data.token,
|
|
258
|
+
password: data.password,
|
|
281
259
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
260
|
+
})
|
|
261
|
+
.then((res) => {
|
|
262
|
+
// dispatch("fetchUser");
|
|
263
|
+
return {
|
|
264
|
+
...res,
|
|
265
|
+
msg: 'your password has successfully changed'
|
|
266
|
+
}
|
|
289
267
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
268
|
+
})
|
|
269
|
+
.catch(
|
|
270
|
+
commonErrorCallback()
|
|
271
|
+
);
|
|
294
272
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
273
|
+
},
|
|
274
|
+
update({commit}, userData) {
|
|
275
|
+
return $http.post('api/auth/user/update', null, {
|
|
276
|
+
params: userData
|
|
277
|
+
}).then(res => {
|
|
278
|
+
commit('updateUser', {
|
|
279
|
+
...userData,
|
|
280
|
+
updated_at: new Date().toISOString() // has a little difference with server
|
|
281
|
+
});
|
|
282
|
+
return {
|
|
283
|
+
...res,
|
|
306
284
|
type: res.data.message.type,
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
285
|
+
msg: res.data.message.body
|
|
286
|
+
}
|
|
287
|
+
}).catch(
|
|
288
|
+
commonErrorCallback()
|
|
289
|
+
);
|
|
290
|
+
},
|
|
291
|
+
getUserAddress({commit}) {
|
|
292
|
+
return $http.get('api/auth/user/address').then((res) => {
|
|
293
|
+
commit('setUserAddress', res.data.data);
|
|
294
|
+
return res
|
|
295
|
+
}).catch(
|
|
296
|
+
commonErrorCallback()
|
|
297
|
+
);
|
|
298
|
+
},
|
|
299
|
+
addUserAddress({dispatch}, data) {
|
|
300
|
+
return $http.post('api/auth/user/address/add', data).then((res) => {
|
|
301
|
+
dispatch('getUserAddress')
|
|
302
|
+
return {
|
|
303
|
+
...res,
|
|
304
|
+
msg: res.data.message.body
|
|
305
|
+
}
|
|
306
|
+
}).catch(
|
|
307
|
+
commonErrorCallback()
|
|
308
|
+
);
|
|
309
|
+
},
|
|
310
|
+
removeUserAddress({dispatch}, id) {
|
|
311
|
+
return $http.put('api/auth/user/address/remove', {id}).then((res) => {
|
|
312
|
+
dispatch('getUserAddress')
|
|
313
|
+
return {
|
|
314
|
+
...res,
|
|
315
|
+
msg: res.data.message.body
|
|
316
|
+
}
|
|
317
|
+
}).catch(
|
|
318
|
+
commonErrorCallback()
|
|
319
|
+
);
|
|
320
|
+
},
|
|
321
|
+
editUserAddress({dispatch}, data) {
|
|
322
|
+
return $http.post('api/auth/user/address/edit', data).then((res) => {
|
|
323
|
+
dispatch('getUserAddress')
|
|
324
|
+
return {
|
|
325
|
+
...res,
|
|
326
|
+
msg: res.data.message.body
|
|
327
|
+
}
|
|
328
|
+
}).catch(
|
|
329
|
+
commonErrorCallback()
|
|
330
|
+
);
|
|
331
|
+
}
|
|
354
332
|
};
|
|
355
333
|
|
|
356
334
|
export default {
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
335
|
+
namespaced: true,
|
|
336
|
+
state,
|
|
337
|
+
getters,
|
|
338
|
+
mutations,
|
|
339
|
+
actions
|
|
361
340
|
};
|
package/src/modules/order.js
CHANGED
|
@@ -140,10 +140,7 @@ const actions = {
|
|
|
140
140
|
setTable({ rootState }, data) {
|
|
141
141
|
let basketId = undefined;
|
|
142
142
|
try {
|
|
143
|
-
basketId = calculateBasketIdParameter(
|
|
144
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
145
|
-
data.restaurantId
|
|
146
|
-
);
|
|
143
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
147
144
|
} catch (e) {
|
|
148
145
|
console.error(e);
|
|
149
146
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -175,10 +172,7 @@ const actions = {
|
|
|
175
172
|
|
|
176
173
|
let basketId = undefined;
|
|
177
174
|
try {
|
|
178
|
-
basketId = calculateBasketIdParameter(
|
|
179
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
180
|
-
data.restaurantId
|
|
181
|
-
);
|
|
175
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
182
176
|
} catch (e) {
|
|
183
177
|
console.error(e);
|
|
184
178
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -225,10 +219,7 @@ const actions = {
|
|
|
225
219
|
|
|
226
220
|
let basketId = undefined;
|
|
227
221
|
try {
|
|
228
|
-
basketId = calculateBasketIdParameter(
|
|
229
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
230
|
-
data.restaurantId
|
|
231
|
-
);
|
|
222
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
232
223
|
} catch (e) {
|
|
233
224
|
console.error(e);
|
|
234
225
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -269,10 +260,7 @@ const actions = {
|
|
|
269
260
|
|
|
270
261
|
let basketId = undefined;
|
|
271
262
|
try {
|
|
272
|
-
basketId = calculateBasketIdParameter(
|
|
273
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
274
|
-
data.restaurantId
|
|
275
|
-
);
|
|
263
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
276
264
|
} catch (e) {
|
|
277
265
|
console.error(e);
|
|
278
266
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -312,10 +300,7 @@ const actions = {
|
|
|
312
300
|
|
|
313
301
|
let basketId = undefined;
|
|
314
302
|
try {
|
|
315
|
-
basketId = calculateBasketIdParameter(
|
|
316
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
317
|
-
data.restaurantId
|
|
318
|
-
);
|
|
303
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
319
304
|
} catch (e) {
|
|
320
305
|
console.error(e);
|
|
321
306
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -356,10 +341,7 @@ const actions = {
|
|
|
356
341
|
|
|
357
342
|
let basketId = undefined;
|
|
358
343
|
try {
|
|
359
|
-
basketId = calculateBasketIdParameter(
|
|
360
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
361
|
-
data.restaurantId
|
|
362
|
-
);
|
|
344
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
363
345
|
} catch (e) {
|
|
364
346
|
console.error(e);
|
|
365
347
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -391,10 +373,7 @@ const actions = {
|
|
|
391
373
|
|
|
392
374
|
let basketId = undefined;
|
|
393
375
|
try {
|
|
394
|
-
basketId = calculateBasketIdParameter(
|
|
395
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
396
|
-
data ? data.restaurantId : undefined
|
|
397
|
-
);
|
|
376
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
398
377
|
} catch (e) {
|
|
399
378
|
console.error(e);
|
|
400
379
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -426,10 +405,7 @@ const actions = {
|
|
|
426
405
|
|
|
427
406
|
let basketId = undefined;
|
|
428
407
|
try {
|
|
429
|
-
basketId = calculateBasketIdParameter(
|
|
430
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
431
|
-
data.restaurantId
|
|
432
|
-
);
|
|
408
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
433
409
|
} catch (e) {
|
|
434
410
|
console.error(e);
|
|
435
411
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -468,10 +444,7 @@ const actions = {
|
|
|
468
444
|
|
|
469
445
|
let basketId = undefined;
|
|
470
446
|
try {
|
|
471
|
-
basketId = calculateBasketIdParameter(
|
|
472
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
473
|
-
data.restaurantId
|
|
474
|
-
);
|
|
447
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
475
448
|
} catch (e) {
|
|
476
449
|
console.error(e);
|
|
477
450
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -506,10 +479,7 @@ const actions = {
|
|
|
506
479
|
addAddress({ rootState }, data) {
|
|
507
480
|
let basketId = undefined;
|
|
508
481
|
try {
|
|
509
|
-
basketId = calculateBasketIdParameter(
|
|
510
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
511
|
-
data.restaurantId
|
|
512
|
-
);
|
|
482
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
513
483
|
} catch (e) {
|
|
514
484
|
console.error(e);
|
|
515
485
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -529,10 +499,7 @@ const actions = {
|
|
|
529
499
|
checkAddress({ rootState }, data) {
|
|
530
500
|
let basketId = undefined;
|
|
531
501
|
try {
|
|
532
|
-
basketId = calculateBasketIdParameter(
|
|
533
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
534
|
-
data.restaurantId
|
|
535
|
-
);
|
|
502
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
536
503
|
} catch (e) {
|
|
537
504
|
console.error(e);
|
|
538
505
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -560,10 +527,7 @@ const actions = {
|
|
|
560
527
|
createOrder({commit, rootState}, data) {
|
|
561
528
|
let basketId = undefined;
|
|
562
529
|
try {
|
|
563
|
-
basketId = calculateBasketIdParameter(
|
|
564
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
565
|
-
data.restaurantId
|
|
566
|
-
);
|
|
530
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
567
531
|
} catch (e) {
|
|
568
532
|
console.error(e);
|
|
569
533
|
return {type: "error", msg: "Basket not found"};
|
|
@@ -712,10 +676,7 @@ const actions = {
|
|
|
712
676
|
preparePayment({ rootState }, data) {
|
|
713
677
|
let basketId = undefined;
|
|
714
678
|
try {
|
|
715
|
-
basketId = calculateBasketIdParameter(
|
|
716
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
717
|
-
data ? data.restaurantId : undefined
|
|
718
|
-
);
|
|
679
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
719
680
|
} catch (e) {
|
|
720
681
|
console.error(e);
|
|
721
682
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -762,10 +723,7 @@ const actions = {
|
|
|
762
723
|
|
|
763
724
|
let basketId = undefined;
|
|
764
725
|
try {
|
|
765
|
-
basketId = calculateBasketIdParameter(
|
|
766
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
767
|
-
data.restaurantId
|
|
768
|
-
);
|
|
726
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
769
727
|
} catch (e) {
|
|
770
728
|
console.error(e);
|
|
771
729
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -808,10 +766,7 @@ const actions = {
|
|
|
808
766
|
|
|
809
767
|
let basketId = undefined;
|
|
810
768
|
try {
|
|
811
|
-
basketId = calculateBasketIdParameter(
|
|
812
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
813
|
-
data.restaurantId
|
|
814
|
-
);
|
|
769
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
815
770
|
} catch (e) {
|
|
816
771
|
console.error(e);
|
|
817
772
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -835,10 +790,7 @@ const actions = {
|
|
|
835
790
|
addDeliveryTimeToBasket({commit, dispatch, rootState}, data) {
|
|
836
791
|
let basketId = undefined;
|
|
837
792
|
try {
|
|
838
|
-
basketId = calculateBasketIdParameter(
|
|
839
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
840
|
-
data.restaurantId
|
|
841
|
-
);
|
|
793
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
842
794
|
} catch (e) {
|
|
843
795
|
console.error(e);
|
|
844
796
|
return {type: "error", msg: "Basket not found"};
|
|
@@ -928,10 +880,7 @@ const actions = {
|
|
|
928
880
|
addVoucher({ rootState, dispatch }, data) {
|
|
929
881
|
let basketId = undefined;
|
|
930
882
|
try {
|
|
931
|
-
basketId = calculateBasketIdParameter(
|
|
932
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
933
|
-
data.restaurantId
|
|
934
|
-
);
|
|
883
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
935
884
|
} catch (e) {
|
|
936
885
|
console.error(e);
|
|
937
886
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -957,10 +906,7 @@ const actions = {
|
|
|
957
906
|
removeVoucher({ rootState, dispatch }, restaurantId) {
|
|
958
907
|
let basketId = undefined;
|
|
959
908
|
try {
|
|
960
|
-
basketId = calculateBasketIdParameter(
|
|
961
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
962
|
-
restaurantId
|
|
963
|
-
);
|
|
909
|
+
basketId = calculateBasketIdParameter(restaurantId);
|
|
964
910
|
} catch (e) {
|
|
965
911
|
console.error(e);
|
|
966
912
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -985,10 +931,7 @@ const actions = {
|
|
|
985
931
|
addTip({ rootState, dispatch }, data) {
|
|
986
932
|
let basketId = undefined;
|
|
987
933
|
try {
|
|
988
|
-
basketId = calculateBasketIdParameter(
|
|
989
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
990
|
-
data.restaurantId
|
|
991
|
-
);
|
|
934
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
992
935
|
} catch (e) {
|
|
993
936
|
console.error(e);
|
|
994
937
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -1012,10 +955,7 @@ const actions = {
|
|
|
1012
955
|
removeTip({ rootState, dispatch }, restaurantId) {
|
|
1013
956
|
let basketId = undefined;
|
|
1014
957
|
try {
|
|
1015
|
-
basketId = calculateBasketIdParameter(
|
|
1016
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
1017
|
-
restaurantId
|
|
1018
|
-
);
|
|
958
|
+
basketId = calculateBasketIdParameter(restaurantId);
|
|
1019
959
|
} catch (e) {
|
|
1020
960
|
console.error(e);
|
|
1021
961
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -1038,10 +978,7 @@ const actions = {
|
|
|
1038
978
|
checkOrderValidity({ rootState }, data) {
|
|
1039
979
|
let basketId = undefined;
|
|
1040
980
|
try {
|
|
1041
|
-
basketId = calculateBasketIdParameter(
|
|
1042
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
1043
|
-
data ? data.restaurantId : undefined
|
|
1044
|
-
);
|
|
981
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
1045
982
|
} catch (e) {
|
|
1046
983
|
console.error(e);
|
|
1047
984
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -1060,10 +997,7 @@ const actions = {
|
|
|
1060
997
|
editCartProductExtraInfo({ rootState, commit }, data) {
|
|
1061
998
|
let basketId = undefined;
|
|
1062
999
|
try {
|
|
1063
|
-
basketId = calculateBasketIdParameter(
|
|
1064
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
1065
|
-
data.restaurantId
|
|
1066
|
-
);
|
|
1000
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
1067
1001
|
} catch (e) {
|
|
1068
1002
|
console.error(e);
|
|
1069
1003
|
return { type: "error", msg: "Basket not found" };
|
|
@@ -1091,10 +1025,7 @@ const actions = {
|
|
|
1091
1025
|
editBasketExtraInfo({rootState, commit}, data) {
|
|
1092
1026
|
let basketId = undefined;
|
|
1093
1027
|
try {
|
|
1094
|
-
basketId = calculateBasketIdParameter(
|
|
1095
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
1096
|
-
data ? data.restaurantId : undefined
|
|
1097
|
-
);
|
|
1028
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
1098
1029
|
} catch (e) {
|
|
1099
1030
|
console.error(e);
|
|
1100
1031
|
return {type: "error", msg: "Basket not found"};
|
|
@@ -1154,6 +1085,7 @@ const actions = {
|
|
|
1154
1085
|
.catch(commonErrorCallback());
|
|
1155
1086
|
},
|
|
1156
1087
|
};
|
|
1088
|
+
|
|
1157
1089
|
export default {
|
|
1158
1090
|
namespaced: true,
|
|
1159
1091
|
state,
|
package/src/modules/product.js
CHANGED
|
@@ -285,9 +285,7 @@ const actions = {
|
|
|
285
285
|
getCategories({ commit, dispatch, rootState, state }, restaurantId) {
|
|
286
286
|
let basketId = undefined;
|
|
287
287
|
try {
|
|
288
|
-
basketId = calculateBasketIdParameter(
|
|
289
|
-
!!rootState.orderiomApiPackage.auth.privateToken, restaurantId
|
|
290
|
-
);
|
|
288
|
+
basketId = calculateBasketIdParameter(restaurantId);
|
|
291
289
|
} catch(e) {
|
|
292
290
|
console.error("getCategories: " + e);
|
|
293
291
|
}
|
|
@@ -329,10 +327,7 @@ const actions = {
|
|
|
329
327
|
commit("setSelectedCategory", data.category);
|
|
330
328
|
let basketId = undefined;
|
|
331
329
|
try {
|
|
332
|
-
basketId = calculateBasketIdParameter(
|
|
333
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
334
|
-
data ? data.restaurantId : undefined
|
|
335
|
-
);
|
|
330
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
336
331
|
} catch(e) {
|
|
337
332
|
console.error("getProducts: " + e);
|
|
338
333
|
}
|
|
@@ -380,10 +375,7 @@ const actions = {
|
|
|
380
375
|
getPinnedProducts({ commit, state, dispatch, rootState }, data) {
|
|
381
376
|
let basketId = undefined;
|
|
382
377
|
try {
|
|
383
|
-
basketId = calculateBasketIdParameter(
|
|
384
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
385
|
-
data ? data.restaurantId : undefined
|
|
386
|
-
);
|
|
378
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
387
379
|
} catch(e) {
|
|
388
380
|
console.error("getPinnedProducts: " + e);
|
|
389
381
|
}
|
|
@@ -484,10 +476,7 @@ const actions = {
|
|
|
484
476
|
|
|
485
477
|
let basketId = undefined;
|
|
486
478
|
try{
|
|
487
|
-
basketId = calculateBasketIdParameter(
|
|
488
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
489
|
-
data ? data.restaurantId : undefined
|
|
490
|
-
);
|
|
479
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
491
480
|
} catch(e) {
|
|
492
481
|
console.error(e);
|
|
493
482
|
return false;
|
|
@@ -511,10 +500,7 @@ const actions = {
|
|
|
511
500
|
getAttributeItems({ commit, state, rootState }, data) {
|
|
512
501
|
let basketId = undefined;
|
|
513
502
|
try {
|
|
514
|
-
basketId = calculateBasketIdParameter(
|
|
515
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
516
|
-
data ? data.restaurantId : undefined
|
|
517
|
-
);
|
|
503
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
518
504
|
} catch(e) {
|
|
519
505
|
console.error("getAttributeItems: " + e);
|
|
520
506
|
}
|
|
@@ -533,10 +519,7 @@ const actions = {
|
|
|
533
519
|
getPackage({ commit, state, rootState }, data) {
|
|
534
520
|
let basketId = undefined;
|
|
535
521
|
try {
|
|
536
|
-
basketId = calculateBasketIdParameter(
|
|
537
|
-
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
538
|
-
data ? data.restaurantId : undefined
|
|
539
|
-
);
|
|
522
|
+
basketId = calculateBasketIdParameter(data ? data.restaurantId : undefined);
|
|
540
523
|
} catch(e) {
|
|
541
524
|
console.error("getPackage: " + e);
|
|
542
525
|
}
|
|
@@ -571,7 +554,7 @@ const actions = {
|
|
|
571
554
|
changeDeliveryMethod({ commit, dispatch, rootState, state }, {deliveryType, restaurantId = null}){
|
|
572
555
|
let basketId = undefined;
|
|
573
556
|
try{
|
|
574
|
-
basketId = calculateBasketIdParameter(
|
|
557
|
+
basketId = calculateBasketIdParameter(restaurantId);
|
|
575
558
|
} catch(e) {
|
|
576
559
|
console.error(e);
|
|
577
560
|
return { type: 'error', msg: 'Basket not found' }
|
|
@@ -628,9 +611,7 @@ const actions = {
|
|
|
628
611
|
const list = (categories || state.categories);
|
|
629
612
|
let basketId = undefined;
|
|
630
613
|
try {
|
|
631
|
-
basketId = calculateBasketIdParameter(
|
|
632
|
-
!!rootState.orderiomApiPackage.auth.privateToken, restaurantId
|
|
633
|
-
);
|
|
614
|
+
basketId = calculateBasketIdParameter(restaurantId);
|
|
634
615
|
} catch(e) {
|
|
635
616
|
console.error("getProductsFromAllCategories: " + e);
|
|
636
617
|
}
|