@escapenavigator/utils 1.8.6 → 1.8.8
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.
|
@@ -7,6 +7,7 @@ function getWeekdayNumber(date) {
|
|
|
7
7
|
}
|
|
8
8
|
function validatePromocode({ promocode, players, questroomId, timeZone, orderDate, hasCertificates, otherPromocodes, isInside, type, }) {
|
|
9
9
|
const errors = [];
|
|
10
|
+
console.log(otherPromocodes);
|
|
10
11
|
const orderDateInTimeZone = type === 'order' && new Date(new Date(orderDate).toLocaleString('en-US', { timeZone }));
|
|
11
12
|
const currentDate = type === 'order' && orderDateInTimeZone.toISOString().split('T')[0];
|
|
12
13
|
const orderDayOfWeek = type === 'order' && getWeekdayNumber(orderDateInTimeZone);
|
|
@@ -15,10 +16,13 @@ function validatePromocode({ promocode, players, questroomId, timeZone, orderDat
|
|
|
15
16
|
const today = new Date(new Date().toLocaleString('en-US', { timeZone }));
|
|
16
17
|
const todayDate = today.toISOString().split('T')[0];
|
|
17
18
|
if (type === 'certificate' && !promocode.availableForCertificates) {
|
|
18
|
-
errors.push(
|
|
19
|
+
errors.push("The promocode can't be applied for certificates.");
|
|
20
|
+
}
|
|
21
|
+
if (otherPromocodes?.some((p) => p.code === promocode.code)) {
|
|
22
|
+
errors.push('Promocode already applied');
|
|
19
23
|
}
|
|
20
24
|
if (type === 'order' && !promocode.availableForBookings) {
|
|
21
|
-
errors.push(
|
|
25
|
+
errors.push("The promocode can't be applied for certificates.");
|
|
22
26
|
}
|
|
23
27
|
if (promocode.inside && !isInside) {
|
|
24
28
|
errors.push('The promocode can be applied by phone.');
|
|
@@ -59,7 +63,9 @@ function validatePromocode({ promocode, players, questroomId, timeZone, orderDat
|
|
|
59
63
|
if (type === 'order' && promocode.availableTo && currentHour > promocode.availableTo) {
|
|
60
64
|
errors.push(`The promocode is only available until ${promocode.availableTo}.`);
|
|
61
65
|
}
|
|
62
|
-
if (type === 'order' &&
|
|
66
|
+
if (type === 'order' &&
|
|
67
|
+
promocode.availableDays &&
|
|
68
|
+
!promocode.availableDays.includes(orderDayOfWeek)) {
|
|
63
69
|
errors.push('The promocode is not valid for the selected day.');
|
|
64
70
|
}
|
|
65
71
|
if (promocode.minPlayers && players < promocode.minPlayers) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@escapenavigator/utils",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.8",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"test": "jest"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@escapenavigator/types": "^1.8.
|
|
17
|
+
"@escapenavigator/types": "^1.8.8",
|
|
18
18
|
"axios": "^0.21.4",
|
|
19
19
|
"class-transformer": "^0.5.1",
|
|
20
20
|
"class-validator": "^0.13.2",
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"node_modules"
|
|
56
56
|
]
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "6a1384ff43ada195fc09b9f21bceb260146a2f50"
|
|
59
59
|
}
|