orderiom-api-package 0.4.12 → 0.4.13
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 +15 -0
- package/src/modules/order.js +28 -4
- package/src/modules/product.js +77 -2
package/package.json
CHANGED
package/src/common.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
|
|
3
|
+
export const weekdays = ["sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"];
|
|
4
|
+
|
|
3
5
|
export const restaurantIdEnv = process.env.VUE_APP_RESTAURANT_ID
|
|
4
6
|
? parseInt(process.env.VUE_APP_RESTAURANT_ID)
|
|
5
7
|
: window.dynamicData && window.dynamicData.VUE_APP_RESTAURANT_ID
|
|
@@ -78,6 +80,19 @@ export function updateBasket({commit, basketId, res, restaurantId}){
|
|
|
78
80
|
return true;
|
|
79
81
|
}
|
|
80
82
|
|
|
83
|
+
export function deliveryCodeToName(code) {
|
|
84
|
+
switch (code){
|
|
85
|
+
case 1:
|
|
86
|
+
return 'delivery';
|
|
87
|
+
case 2:
|
|
88
|
+
return 'pickup';
|
|
89
|
+
case 3:
|
|
90
|
+
return 'here';
|
|
91
|
+
default:
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
81
96
|
axios.defaults.baseURL = process.env.VUE_APP_BASE_API_URL || window.dynamicData.VUE_APP_BASE_API_URL;
|
|
82
97
|
axios.interceptors.request.use(config => {
|
|
83
98
|
const token = localStorage.getItem("privateToken") || localStorage.getItem("publicToken");
|
package/src/modules/order.js
CHANGED
|
@@ -816,6 +816,21 @@ const actions = {
|
|
|
816
816
|
})
|
|
817
817
|
.catch(commonErrorCallback());
|
|
818
818
|
},
|
|
819
|
+
formatDate({}, date){
|
|
820
|
+
if(!date) return null;
|
|
821
|
+
return [
|
|
822
|
+
date.getFullYear(),
|
|
823
|
+
(date.getMonth() + 1).toString().padStart(2, '0'),
|
|
824
|
+
(date.getDate()).toString().padStart(2, '0')
|
|
825
|
+
].join('-')
|
|
826
|
+
},
|
|
827
|
+
formatTime({}, date){
|
|
828
|
+
if(!date) return null;
|
|
829
|
+
return [
|
|
830
|
+
date.getHours().toString().padStart(2, '0'),
|
|
831
|
+
date.getMinutes().toString().padStart(2, '0'),
|
|
832
|
+
].join(':')
|
|
833
|
+
},
|
|
819
834
|
addDeliveryTimeToBasket({ dispatch, rootState }, data) {
|
|
820
835
|
let basketId = undefined;
|
|
821
836
|
try {
|
|
@@ -828,18 +843,27 @@ const actions = {
|
|
|
828
843
|
return { type: "error", msg: "Basket not found" };
|
|
829
844
|
}
|
|
830
845
|
|
|
846
|
+
let delivery_time = null;
|
|
847
|
+
if(data.delivery_time instanceof Date){
|
|
848
|
+
delivery_time = [
|
|
849
|
+
dispatch('formatDate', data.delivery_time),
|
|
850
|
+
dispatch('formatTime', data.delivery_time),
|
|
851
|
+
].join(' ')
|
|
852
|
+
}else if(data.date && data.time){
|
|
853
|
+
delivery_time = data.date + ' ' + data.time
|
|
854
|
+
}
|
|
855
|
+
|
|
831
856
|
return $http
|
|
832
857
|
.post("api/basket/add-delivery-time", {
|
|
833
858
|
basketId,
|
|
834
|
-
delivery_time
|
|
835
|
-
data.date && data.time ? data.date + " " + data.time : null,
|
|
859
|
+
delivery_time,
|
|
836
860
|
deliveryType: data.deliveryType,
|
|
837
861
|
duration: data.duration || undefined,
|
|
838
|
-
restaurantId,
|
|
862
|
+
restaurantId: data.restaurantId,
|
|
839
863
|
})
|
|
840
864
|
.then((res) => {
|
|
841
865
|
// console.log(res);
|
|
842
|
-
dispatch("product/getBasket", restaurantId, { root: true });
|
|
866
|
+
dispatch("product/getBasket", data.restaurantId, { root: true });
|
|
843
867
|
return {
|
|
844
868
|
type: "success",
|
|
845
869
|
msg: "ok",
|
package/src/modules/product.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {commonErrorCallback, calculateBasketIdParameter, updateBasket, restaurantIdEnv, $http} from '../common';
|
|
1
|
+
import {commonErrorCallback, calculateBasketIdParameter, updateBasket, deliveryCodeToName, weekdays, restaurantIdEnv, $http} from '../common';
|
|
2
2
|
|
|
3
3
|
const state = () => ({
|
|
4
4
|
selectedTime: null,
|
|
@@ -56,7 +56,52 @@ const getters = {
|
|
|
56
56
|
|
|
57
57
|
return subCategories
|
|
58
58
|
|
|
59
|
-
}
|
|
59
|
+
},
|
|
60
|
+
deliveryType(state){
|
|
61
|
+
return deliveryCodeToName(state.basketInfo.deliveryType);
|
|
62
|
+
},
|
|
63
|
+
deliveryTimes(state, getters){
|
|
64
|
+
if(!getters.deliveryType) return [];
|
|
65
|
+
const property = getters.deliveryType === 'delivery'
|
|
66
|
+
? 'restaurantAvailableTimes'
|
|
67
|
+
: getters.deliveryType === 'here'
|
|
68
|
+
? 'hereTimes'
|
|
69
|
+
: 'restaurantTakeawayTimes';
|
|
70
|
+
return state.restaurantInfo[property] || [];
|
|
71
|
+
},
|
|
72
|
+
disabledDates(state, getters){
|
|
73
|
+
const allowedWeekDays = Array.from(new Set(
|
|
74
|
+
getters.deliveryTimes.map(item => item.weekday)
|
|
75
|
+
)).map(item => weekdays.indexOf(item) + 1)
|
|
76
|
+
|
|
77
|
+
return {weekdays: [1, 2, 3, 4, 5, 6, 7].filter(item => !allowedWeekDays.includes(item))};
|
|
78
|
+
},
|
|
79
|
+
availableTimes(state, getters){
|
|
80
|
+
const result = {};
|
|
81
|
+
getters.deliveryTimes.forEach(range => {
|
|
82
|
+
if(!result[range.weekday]) result[range.weekday] = [];
|
|
83
|
+
const start = range.open_at.slice(0, 5).split(':').map(item => Number(item));
|
|
84
|
+
const end = range.close_at.slice(0, 5).split(':').map(item => Number(item));
|
|
85
|
+
const allowedHours = Array.from({ length: (end[0] + 1) - start[0] }, (_, index) => start[0] + index);
|
|
86
|
+
const allowedMinutes = {};
|
|
87
|
+
|
|
88
|
+
allowedHours.forEach(hour => {
|
|
89
|
+
if(hour < end[0] && hour > start[0]) allowedMinutes[hour] = {start: 0, end: 59};
|
|
90
|
+
else if (hour === start[0] && hour === end[0]) allowedMinutes[hour] = { start: start[1], end: end[1] };
|
|
91
|
+
else if (hour === start[0]) allowedMinutes[hour] = { start: start[1], end: 59 }
|
|
92
|
+
else if(hour === end[0]) allowedMinutes[hour] = { start: 0, end: end[1]}
|
|
93
|
+
else allowedMinutes[hour] = null;
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
result[range.weekday].push({
|
|
97
|
+
start,
|
|
98
|
+
end,
|
|
99
|
+
allowedHours,
|
|
100
|
+
allowedMinutes
|
|
101
|
+
})
|
|
102
|
+
});
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
60
105
|
}
|
|
61
106
|
const mutations = {
|
|
62
107
|
setSelectedDate(state, date) {
|
|
@@ -485,6 +530,36 @@ const actions = {
|
|
|
485
530
|
commonErrorCallback()
|
|
486
531
|
);
|
|
487
532
|
},
|
|
533
|
+
minDateTimeForDelivery ({ state }, deliveryType){
|
|
534
|
+
const dt = deliveryType ? deliveryType : deliveryCodeToName(state.basketInfo.deliveryType)
|
|
535
|
+
if(!dt) return null;
|
|
536
|
+
|
|
537
|
+
const result = new Date();
|
|
538
|
+
const closedToday = state.restaurantInfo ? state.restaurantInfo.closed : false;
|
|
539
|
+
const minHour =
|
|
540
|
+
result.getHours() + Number(state.restaurantInfo[`${dt}_hours`] || 0);
|
|
541
|
+
const isTomorrow = closedToday && minHour < 24;
|
|
542
|
+
result.setHours(
|
|
543
|
+
isTomorrow ? 24 : minHour,
|
|
544
|
+
isTomorrow ? 0 : result.getMinutes(),
|
|
545
|
+
0,
|
|
546
|
+
0
|
|
547
|
+
);
|
|
548
|
+
|
|
549
|
+
return result;
|
|
550
|
+
},
|
|
551
|
+
maxDateTimeForDelivery ({state}, deliveryType){
|
|
552
|
+
const dt = deliveryType ? deliveryType : deliveryCodeToName(state.basketInfo.deliveryType)
|
|
553
|
+
if(!dt) return null;
|
|
554
|
+
|
|
555
|
+
const ad = state.restaurantInfo[`${dt}_available_days`];
|
|
556
|
+
if(!ad) return null;
|
|
557
|
+
|
|
558
|
+
const result = new Date();
|
|
559
|
+
result.setHours(23, 59, 0, 0)
|
|
560
|
+
result.setDate(result.getDate() + Number(ad));
|
|
561
|
+
return result;
|
|
562
|
+
}
|
|
488
563
|
};
|
|
489
564
|
|
|
490
565
|
export default {
|