@darkpos/pricing 1.0.9 → 1.0.10
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/lib/order/pickEndDate.js +30 -42
- package/package.json +2 -2
package/lib/order/pickEndDate.js
CHANGED
|
@@ -1,27 +1,19 @@
|
|
|
1
1
|
module.exports = ({ settings, _, moment }) => {
|
|
2
2
|
const timezone = _.get(settings, 'localization.timezone', 'America/New_York');
|
|
3
|
-
const isInSchedule = (each, date) => {
|
|
4
|
-
const isoWeekday = moment(date).tz(timezone).isoWeekday();
|
|
5
|
-
let check = false;
|
|
6
|
-
if (each.day !== undefined && each.day !== null)
|
|
7
|
-
check = String(each.day) === String(isoWeekday === 7 ? 0 : isoWeekday);
|
|
8
3
|
|
|
9
|
-
|
|
10
|
-
check =
|
|
11
|
-
moment(date).startOf('day').tz(timezone).format('YYYYMMDD') ===
|
|
12
|
-
moment(each.date).startOf('day').tz(timezone).format('YYYYMMDD');
|
|
13
|
-
return check;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const checkStoreSchedule = date => {
|
|
4
|
+
const getClosedDays = () => {
|
|
17
5
|
const schedule = _.get(settings, 'schedule', {});
|
|
18
6
|
const { close = [] } = schedule;
|
|
19
7
|
|
|
20
|
-
if (close
|
|
8
|
+
if (!Array.isArray(close)) return [];
|
|
9
|
+
return close.map(closedDate => ({
|
|
10
|
+
isoWeekDay: moment(closedDate.date).tz(timezone).isoWeekday(),
|
|
11
|
+
date: moment(closedDate.date).tz(timezone)
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return function pickEndDate(schedule = {}) {
|
|
21
16
|
|
|
22
|
-
return true;
|
|
23
|
-
};
|
|
24
|
-
return function pickEndDate(schedule = {}, skip = 0, date = undefined) {
|
|
25
17
|
const {
|
|
26
18
|
addDays = 1,
|
|
27
19
|
hour,
|
|
@@ -30,41 +22,37 @@ module.exports = ({ settings, _, moment }) => {
|
|
|
30
22
|
cutHour,
|
|
31
23
|
cutDay = 1,
|
|
32
24
|
} = schedule;
|
|
33
|
-
let days = skip || Number(addDays);
|
|
34
25
|
|
|
35
|
-
const
|
|
36
|
-
|
|
26
|
+
const todayTZ = moment().tz(timezone);
|
|
27
|
+
let endDateTZ = todayTZ.clone();
|
|
28
|
+
|
|
29
|
+
const closedDays = getClosedDays();
|
|
37
30
|
|
|
38
31
|
if (
|
|
39
|
-
!skip &&
|
|
40
|
-
!date &&
|
|
41
32
|
cutHour &&
|
|
42
|
-
|
|
33
|
+
todayTZ.isAfter(moment(cutHour, 'hh:mm:ss').tz(timezone))
|
|
43
34
|
) {
|
|
44
|
-
|
|
45
|
-
days += cutDay;
|
|
35
|
+
endDateTZ = endDateTZ.add(cutDay, 'days')
|
|
46
36
|
}
|
|
47
37
|
|
|
48
|
-
|
|
49
|
-
console.log('check date => ', endDate.format());
|
|
38
|
+
let addDaysCounter = 0;
|
|
50
39
|
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
while (addDaysCounter < addDays) {
|
|
41
|
+
endDateTZ = endDateTZ.add(1, 'days');
|
|
42
|
+
const endDateISOWeekday = endDateTZ.isoWeekday() === 7 ? 0 : endDateTZ.isoWeekday();
|
|
43
|
+
|
|
44
|
+
if (!skipDays.includes(endDateISOWeekday) && !closedDays.some(closedDay => {
|
|
45
|
+
return closedDay.date.isSame(endDateTZ, 'day');
|
|
46
|
+
})) {
|
|
47
|
+
addDaysCounter++;
|
|
48
|
+
}
|
|
53
49
|
|
|
54
|
-
if (skipDays && skipDays.includes(isoWeekday === 7 ? 0 : isoWeekday)) {
|
|
55
|
-
console.log('check next day: in Skip days');
|
|
56
|
-
return pickEndDate(schedule, 1, endDate);
|
|
57
|
-
}
|
|
58
|
-
if (!checkStoreSchedule(endDate)) {
|
|
59
|
-
console.log('check next day: in Close days');
|
|
60
|
-
return pickEndDate(schedule, 1, endDate);
|
|
61
50
|
}
|
|
62
51
|
|
|
63
|
-
if (hour !== undefined)
|
|
64
|
-
if (minute !== undefined)
|
|
65
|
-
|
|
52
|
+
if (hour !== undefined) endDateTZ.set('hour', hour);
|
|
53
|
+
if (minute !== undefined) endDateTZ.set('minute', minute);
|
|
54
|
+
endDateTZ.set('second', 0);
|
|
66
55
|
|
|
67
|
-
|
|
68
|
-
return moment.utc(endDate).format();
|
|
56
|
+
return moment.utc(endDateTZ).format();
|
|
69
57
|
};
|
|
70
|
-
};
|
|
58
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"supertest": "^6.2.3",
|
|
36
36
|
"supervisor": "^0.12.0"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "3519de2c00b9db1618cb8c417d270227a5ddc822"
|
|
39
39
|
}
|