orderiom-api-package 0.4.2 → 0.4.4
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/modules/product.js +58 -9
package/package.json
CHANGED
package/src/modules/product.js
CHANGED
|
@@ -143,15 +143,23 @@ const mutations = {
|
|
|
143
143
|
}
|
|
144
144
|
};
|
|
145
145
|
const actions = {
|
|
146
|
-
getCategories({ commit, dispatch }, restaurantId) {
|
|
146
|
+
getCategories({ commit, dispatch, rootState }, restaurantId) {
|
|
147
|
+
let basketId = undefined;
|
|
148
|
+
try {
|
|
149
|
+
basketId = calculateBasketIdParameter(
|
|
150
|
+
!!rootState.orderiomApiPackage.auth.privateToken, restaurantId
|
|
151
|
+
);
|
|
152
|
+
} catch(e) {
|
|
153
|
+
console.error("getCategories: " + e);
|
|
154
|
+
}
|
|
147
155
|
return $http
|
|
148
|
-
.get("api/restaurant/category", { params: { restaurantId: restaurantId } })
|
|
156
|
+
.get("api/restaurant/category", { params: { restaurantId: restaurantId, basketId: basketId } })
|
|
149
157
|
.then((res) => {
|
|
150
158
|
let categories = res.data.data;
|
|
151
159
|
//TODO: why calling an api write after another while we can do it together?
|
|
152
160
|
//TODO: this api call returns empty on restaurant refresh
|
|
153
161
|
$http
|
|
154
|
-
.get("api/restaurant/category", { params: { restaurantId: restaurantId, extra: 1 } })
|
|
162
|
+
.get("api/restaurant/category", { params: { restaurantId: restaurantId, extra: 1, basketId: basketId } })
|
|
155
163
|
.then((res) => {
|
|
156
164
|
if (res.data.data.length) {
|
|
157
165
|
categories = [...categories, ...res.data.data];
|
|
@@ -189,12 +197,21 @@ const actions = {
|
|
|
189
197
|
},
|
|
190
198
|
getProducts({ commit, state, rootState }, data) {
|
|
191
199
|
commit("setSelectedCategory", data.category);
|
|
192
|
-
|
|
200
|
+
let basketId = undefined;
|
|
201
|
+
try {
|
|
202
|
+
basketId = calculateBasketIdParameter(
|
|
203
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
204
|
+
data ? data.restaurantId : undefined
|
|
205
|
+
);
|
|
206
|
+
} catch(e) {
|
|
207
|
+
console.error("getProducts: " + e);
|
|
208
|
+
}
|
|
193
209
|
return $http.get("api/restaurant/products", {
|
|
194
210
|
params: {
|
|
195
211
|
categoryId: data.category.id,
|
|
196
212
|
restaurantId: data.restaurantId,
|
|
197
213
|
delivery_time: state.deliveryTime || undefined,
|
|
214
|
+
basketId: basketId
|
|
198
215
|
}
|
|
199
216
|
}).then(res => {
|
|
200
217
|
res.data.data.forEach(productInCategory => {
|
|
@@ -234,10 +251,19 @@ const actions = {
|
|
|
234
251
|
commit('finishFetchingBasket')
|
|
235
252
|
});
|
|
236
253
|
},
|
|
237
|
-
getAttributeItems({ commit }, data) {
|
|
254
|
+
getAttributeItems({ commit, state, rootState }, data) {
|
|
255
|
+
let basketId = undefined;
|
|
256
|
+
try {
|
|
257
|
+
basketId = calculateBasketIdParameter(
|
|
258
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
259
|
+
data ? data.restaurantId : undefined
|
|
260
|
+
);
|
|
261
|
+
} catch(e) {
|
|
262
|
+
console.error("getAttributeItems: " + e);
|
|
263
|
+
}
|
|
238
264
|
return $http.get('api/restaurant/category-attributes-items', {
|
|
239
265
|
params: {
|
|
240
|
-
restaurantId: data.restaurantId, categoryId: data.category.id,
|
|
266
|
+
restaurantId: data.restaurantId, categoryId: data.category.id, basketId: basketId
|
|
241
267
|
}
|
|
242
268
|
}).then((result) => {
|
|
243
269
|
commit('setAttributeItems', result.data.data)
|
|
@@ -245,14 +271,29 @@ const actions = {
|
|
|
245
271
|
commonErrorCallback()
|
|
246
272
|
);
|
|
247
273
|
},
|
|
248
|
-
getPackage({ commit }, data) {
|
|
274
|
+
getPackage({ commit, state, rootState }, data) {
|
|
275
|
+
let basketId = undefined;
|
|
276
|
+
try {
|
|
277
|
+
basketId = calculateBasketIdParameter(
|
|
278
|
+
!!rootState.orderiomApiPackage.auth.privateToken,
|
|
279
|
+
data ? data.restaurantId : undefined
|
|
280
|
+
);
|
|
281
|
+
} catch(e) {
|
|
282
|
+
console.error("getPackage: " + e);
|
|
283
|
+
}
|
|
249
284
|
return $http.get('api/restaurant/product-packages', {
|
|
250
285
|
params: {
|
|
251
286
|
productId: data.productId,
|
|
252
|
-
restaurantId: data.restaurantId
|
|
287
|
+
restaurantId: data.restaurantId,
|
|
288
|
+
basketId: basketId
|
|
253
289
|
}
|
|
254
290
|
}).then((result) => {
|
|
255
291
|
commit('setProductPackage', result.data.data)
|
|
292
|
+
return {
|
|
293
|
+
type: 'success',
|
|
294
|
+
msg: '',
|
|
295
|
+
data: result.data.data
|
|
296
|
+
}
|
|
256
297
|
}).catch(
|
|
257
298
|
commonErrorCallback()
|
|
258
299
|
);
|
|
@@ -313,13 +354,21 @@ const actions = {
|
|
|
313
354
|
},
|
|
314
355
|
getProductsFromAllCategories({ commit, state, rootState }, {categories = null, restaurantId = null}) {
|
|
315
356
|
const list = (categories || state.categories);
|
|
316
|
-
|
|
357
|
+
let basketId = undefined;
|
|
358
|
+
try {
|
|
359
|
+
basketId = calculateBasketIdParameter(
|
|
360
|
+
!!rootState.orderiomApiPackage.auth.privateToken, restaurantId
|
|
361
|
+
);
|
|
362
|
+
} catch(e) {
|
|
363
|
+
console.error("getProductsFromAllCategories: " + e);
|
|
364
|
+
}
|
|
317
365
|
// TODO: It is recommended to use a new api instead of multiple api calls inside a loop.
|
|
318
366
|
return Promise.all(list.map(category =>
|
|
319
367
|
$http.get("api/restaurant/products", {
|
|
320
368
|
params: {
|
|
321
369
|
categoryId: category.id,
|
|
322
370
|
restaurantId: restaurantId || restaurantIdEnv,
|
|
371
|
+
basketId: basketId
|
|
323
372
|
}
|
|
324
373
|
})
|
|
325
374
|
)).then(resArray => ({
|