orderiom-api-package 0.3.2 → 0.3.5
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 +6 -6
- package/src/modules/auth.js +1 -1
- package/src/modules/manager.js +0 -1
- package/src/modules/order.js +18 -7
- package/src/modules/product.js +14 -14
- package/src/modules/restaurant.js +6 -6
package/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const restaurantIdEnv = process.env.VUE_APP_RESTAURANT_ID ? parseInt(process.env.VUE_APP_RESTAURANT_ID) : null;
|
|
2
2
|
|
|
3
3
|
export function commonErrorCallback(unknownErrorMessage = 'Something went wrong'){
|
|
4
4
|
return error => {
|
|
@@ -21,7 +21,7 @@ export function commonErrorCallback(unknownErrorMessage = 'Something went wrong'
|
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export function calculateBasketIdParameter(isLogin) {
|
|
24
|
+
export function calculateBasketIdParameter(isLogin, restaurantId) {
|
|
25
25
|
if(isLogin) return undefined;
|
|
26
26
|
// localStorage might fail
|
|
27
27
|
let baskets = [];
|
|
@@ -31,14 +31,14 @@ export function calculateBasketIdParameter(isLogin) {
|
|
|
31
31
|
console.error(e);
|
|
32
32
|
throw new Error('Basket not found');
|
|
33
33
|
}
|
|
34
|
-
const foundBasket = baskets.find(basket => Number(basket.restaurantId) === restaurantId);
|
|
34
|
+
const foundBasket = baskets.find(basket => Number(basket.restaurantId) === (restaurantId || restaurantIdEnv));
|
|
35
35
|
if(!foundBasket){
|
|
36
36
|
throw new Error('Basket not found');
|
|
37
37
|
}
|
|
38
38
|
return foundBasket.basketId;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export function updateBasket({commit, basketId, res, isOutsideProduct}){
|
|
41
|
+
export function updateBasket({commit, basketId, res, isOutsideProduct, restaurantId}){
|
|
42
42
|
const basketInfo = res.data.data;
|
|
43
43
|
commit(`${isOutsideProduct ? 'product/' : ''}setBasketInfo`, basketInfo);
|
|
44
44
|
|
|
@@ -58,10 +58,10 @@ export function updateBasket({commit, basketId, res, isOutsideProduct}){
|
|
|
58
58
|
|
|
59
59
|
if (parseInt(basketInfo.id) !== parseInt(basketId)) {
|
|
60
60
|
const baskets = JSON.parse(localStorage.getItem('basket'));
|
|
61
|
-
const basketIndex = baskets.findIndex(basket => parseInt(basket.restaurantId) === restaurantId);
|
|
61
|
+
const basketIndex = baskets.findIndex(basket => parseInt(basket.restaurantId) === (restaurantId || restaurantIdEnv));
|
|
62
62
|
if (basketIndex > -1) baskets.splice(basketIndex, 1);
|
|
63
63
|
baskets.push({
|
|
64
|
-
restaurantId,
|
|
64
|
+
restaurantId: (restaurantId || restaurantIdEnv),
|
|
65
65
|
basketId: basketInfo.id,
|
|
66
66
|
});
|
|
67
67
|
localStorage.setItem('basket', JSON.stringify(baskets));
|
package/src/modules/auth.js
CHANGED
package/src/modules/manager.js
CHANGED
package/src/modules/order.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import {commonErrorCallback, calculateBasketIdParameter,
|
|
2
|
+
import {commonErrorCallback, calculateBasketIdParameter, restaurantIdEnv, updateBasket} from '../common';
|
|
3
3
|
|
|
4
4
|
const state = () => ({
|
|
5
5
|
productOrder: null,
|
|
@@ -105,11 +105,11 @@ const actions = {
|
|
|
105
105
|
.post("api/order/create-basket", data)
|
|
106
106
|
.then(async res => {
|
|
107
107
|
basketData.push({
|
|
108
|
-
restaurantId:
|
|
108
|
+
restaurantId: restaurantIdEnv,
|
|
109
109
|
basketId: res.data.data.id,
|
|
110
110
|
});
|
|
111
111
|
localStorage.setItem("basket", JSON.stringify(basketData));
|
|
112
|
-
const result = await dispatch('product/getBasket',
|
|
112
|
+
const result = await dispatch('product/getBasket', restaurantIdEnv, { root: true }) ;
|
|
113
113
|
return {
|
|
114
114
|
type: result ? 'success' : 'error',
|
|
115
115
|
msg: result ? 'Basket created' : 'There was an error in fetching the basket info',
|
|
@@ -506,7 +506,7 @@ const actions = {
|
|
|
506
506
|
getShippingPrice({ commit, rootState }, data) {
|
|
507
507
|
let basketId = undefined;
|
|
508
508
|
try{
|
|
509
|
-
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken);
|
|
509
|
+
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken, data.restaurantId);
|
|
510
510
|
} catch(e) {
|
|
511
511
|
console.error(e);
|
|
512
512
|
return { type: 'error', msg: 'Basket not found' }
|
|
@@ -525,9 +525,20 @@ const actions = {
|
|
|
525
525
|
})
|
|
526
526
|
.then((res) => {
|
|
527
527
|
commit('setshippingPrice', res.data.data.shippingPrice.toString());
|
|
528
|
+
commit('product/setshippingPrice', res.data.data.shippingPrice.toString(),{root: true});
|
|
529
|
+
if(res.data.data.totalPrice){
|
|
530
|
+
const value = Number(res.data.data.totalPrice).toFixed(2);
|
|
531
|
+
commit('setTotalPrice', value);
|
|
532
|
+
commit('product/SetTotalPrice', value, {root: true});
|
|
533
|
+
}
|
|
534
|
+
if(res.data.data.totalWithDiscount){
|
|
535
|
+
const value = Number(res.data.data.totalWithDiscount).toFixed(2);
|
|
536
|
+
commit('product/setTotalWithDiscount', value, {root: true});
|
|
537
|
+
}
|
|
538
|
+
|
|
528
539
|
return {
|
|
529
540
|
type: 'success',
|
|
530
|
-
msg: '
|
|
541
|
+
msg: ''
|
|
531
542
|
}
|
|
532
543
|
})
|
|
533
544
|
.catch(
|
|
@@ -697,7 +708,7 @@ const actions = {
|
|
|
697
708
|
editCartProductExtraInfo({rootState, commit}, data){
|
|
698
709
|
let basketId = undefined;
|
|
699
710
|
try{
|
|
700
|
-
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken);
|
|
711
|
+
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken, data.restaurantId);
|
|
701
712
|
} catch(e) {
|
|
702
713
|
console.error(e);
|
|
703
714
|
return {type: 'error', msg: 'Basket not found'};
|
|
@@ -707,7 +718,7 @@ const actions = {
|
|
|
707
718
|
basketId,
|
|
708
719
|
...data
|
|
709
720
|
}).then(res =>
|
|
710
|
-
updateBasket({commit, basketId, res, isOutsideProduct: true})
|
|
721
|
+
updateBasket({commit, basketId, res, isOutsideProduct: true, restaurantId: data.restaurantId})
|
|
711
722
|
).catch(err => {
|
|
712
723
|
console.error(err);
|
|
713
724
|
return false;
|
package/src/modules/product.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import Vue from 'vue';
|
|
3
|
-
import {commonErrorCallback, calculateBasketIdParameter,
|
|
3
|
+
import {commonErrorCallback, calculateBasketIdParameter, updateBasket, restaurantIdEnv} from '../common';
|
|
4
4
|
|
|
5
5
|
const state = () => ({
|
|
6
6
|
selectedTime: null,
|
|
@@ -212,7 +212,7 @@ const actions = {
|
|
|
212
212
|
|
|
213
213
|
let basketId = undefined;
|
|
214
214
|
try{
|
|
215
|
-
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken);
|
|
215
|
+
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken, data.restaurantId);
|
|
216
216
|
} catch(e) {
|
|
217
217
|
console.error(e);
|
|
218
218
|
return { type: 'error', msg: 'Basket not found' }
|
|
@@ -257,10 +257,10 @@ const actions = {
|
|
|
257
257
|
commonErrorCallback()
|
|
258
258
|
);
|
|
259
259
|
},
|
|
260
|
-
getBasket({ commit, rootState }) {
|
|
260
|
+
getBasket({ commit, rootState }, data) {
|
|
261
261
|
let basketId = undefined;
|
|
262
262
|
try{
|
|
263
|
-
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken);
|
|
263
|
+
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken, data?.restaurantId);
|
|
264
264
|
} catch(e) {
|
|
265
265
|
console.error(e);
|
|
266
266
|
return false;
|
|
@@ -270,10 +270,10 @@ const actions = {
|
|
|
270
270
|
return axios.get('api/basket', {
|
|
271
271
|
params: {
|
|
272
272
|
basketId,
|
|
273
|
-
restaurantId
|
|
273
|
+
restaurantId: restaurantIdEnv
|
|
274
274
|
}
|
|
275
275
|
}).then(res =>
|
|
276
|
-
updateBasket({commit, basketId, res, isOutsideProduct: false})
|
|
276
|
+
updateBasket({commit, basketId, res, isOutsideProduct: false, restaurantId: data?.restaurantId})
|
|
277
277
|
).catch(error => {
|
|
278
278
|
console.error(error);
|
|
279
279
|
return false;
|
|
@@ -316,10 +316,10 @@ const actions = {
|
|
|
316
316
|
commonErrorCallback()
|
|
317
317
|
);
|
|
318
318
|
},
|
|
319
|
-
changeDeliveryMethod({ commit, dispatch, rootState, state }, deliveryType){
|
|
319
|
+
changeDeliveryMethod({ commit, dispatch, rootState, state }, deliveryType, restaurantId = null){
|
|
320
320
|
let basketId = undefined;
|
|
321
321
|
try{
|
|
322
|
-
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken);
|
|
322
|
+
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken, restaurantId);
|
|
323
323
|
} catch(e) {
|
|
324
324
|
console.error(e);
|
|
325
325
|
return { type: 'error', msg: 'Basket not found' }
|
|
@@ -331,15 +331,15 @@ const actions = {
|
|
|
331
331
|
return axios.post('api/basket/change-delivery-method', {
|
|
332
332
|
deliveryType,
|
|
333
333
|
basketId,
|
|
334
|
-
restaurantId:
|
|
334
|
+
restaurantId: basketId ? undefined : (restaurantId || restaurantIdEnv)
|
|
335
335
|
}).then(async res => {
|
|
336
336
|
if(res.data.message.type !== 'success'){
|
|
337
337
|
return { type: 'error', msg: 'There was an error in updating the delivery type' }
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
-
dispatch('getCategories', restaurantId);
|
|
340
|
+
dispatch('getCategories', (restaurantId || restaurantIdEnv));
|
|
341
341
|
|
|
342
|
-
const result = await dispatch("getBasket", restaurantId);
|
|
342
|
+
const result = await dispatch("getBasket", (restaurantId || restaurantIdEnv));
|
|
343
343
|
|
|
344
344
|
return {
|
|
345
345
|
type: result ? 'success' : 'error',
|
|
@@ -358,10 +358,10 @@ const actions = {
|
|
|
358
358
|
commit('finishChangingDeliveryType');
|
|
359
359
|
});
|
|
360
360
|
},
|
|
361
|
-
getProductsFromAllCategories({ commit, state, rootState }, categories = null) {
|
|
361
|
+
getProductsFromAllCategories({ commit, state, rootState }, categories = null, restaurantId = null) {
|
|
362
362
|
let basketId = undefined;
|
|
363
363
|
try{
|
|
364
|
-
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken);
|
|
364
|
+
basketId = calculateBasketIdParameter(!!rootState.orderiomApiPackage.auth.privateToken, restaurantId);
|
|
365
365
|
} catch(e) {
|
|
366
366
|
console.error(e);
|
|
367
367
|
return { type: 'error', msg: 'Basket not found', data: [] }
|
|
@@ -374,7 +374,7 @@ const actions = {
|
|
|
374
374
|
axios.get("api/restaurant/products", {
|
|
375
375
|
params: {
|
|
376
376
|
categoryId: category.id,
|
|
377
|
-
restaurantId,
|
|
377
|
+
restaurantId: restaurantId || restaurantIdEnv,
|
|
378
378
|
basketId
|
|
379
379
|
}
|
|
380
380
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
|
-
import { commonErrorCallback,
|
|
2
|
+
import { commonErrorCallback, restaurantIdEnv } from '../common';
|
|
3
3
|
|
|
4
4
|
const state = () => ({
|
|
5
5
|
restaurantInfo: {},
|
|
@@ -145,7 +145,7 @@ const actions = {
|
|
|
145
145
|
addReservedTables({ commit }, data) {
|
|
146
146
|
return axios
|
|
147
147
|
.post("api/restaurant/reserve-table", {
|
|
148
|
-
restaurantId:
|
|
148
|
+
restaurantId: restaurantIdEnv,
|
|
149
149
|
people: data.people,
|
|
150
150
|
date: data.date,
|
|
151
151
|
time: data.time,
|
|
@@ -180,7 +180,7 @@ const actions = {
|
|
|
180
180
|
commit('startFetchingBlogs');
|
|
181
181
|
return axios.get('/api/blogs/by-tag', {
|
|
182
182
|
params: {
|
|
183
|
-
restaurantId,
|
|
183
|
+
restaurantId: restaurantIdEnv,
|
|
184
184
|
tagId
|
|
185
185
|
}
|
|
186
186
|
}).then(res => {
|
|
@@ -212,7 +212,7 @@ const actions = {
|
|
|
212
212
|
})
|
|
213
213
|
},
|
|
214
214
|
getBlogBySlug({ commit }, blogSlug) {
|
|
215
|
-
return axios.get('api/blogs/show/slug', { params: {blogSlug, restaurantId}}).then(res => {
|
|
215
|
+
return axios.get('api/blogs/show/slug', { params: {blogSlug, restaurantId: restaurantIdEnv}}).then(res => {
|
|
216
216
|
commit('setBlog', res.data.data);
|
|
217
217
|
return { type: 'success', msg: 'ok' }
|
|
218
218
|
}).catch(error => {
|
|
@@ -220,9 +220,9 @@ const actions = {
|
|
|
220
220
|
return commonErrorCallback()(error);
|
|
221
221
|
})
|
|
222
222
|
},
|
|
223
|
-
getTestimonials({ commit },
|
|
223
|
+
getTestimonials({ commit }, data) {
|
|
224
224
|
return axios.get('api/testimonials', {
|
|
225
|
-
params:
|
|
225
|
+
params: data
|
|
226
226
|
}).then(res => {
|
|
227
227
|
commit('setTestimonials', res.data.data)
|
|
228
228
|
return {
|