@escapenavigator/utils 1.9.38 → 1.9.40
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/dist/serialize-slot.js +2 -0
- package/dist/validate-promocode.js +11 -8
- package/package.json +3 -3
package/dist/serialize-slot.js
CHANGED
|
@@ -16,6 +16,7 @@ const serializeSlotOrderData = (order) => order && {
|
|
|
16
16
|
confirmed: order.confirmed,
|
|
17
17
|
total: order.total,
|
|
18
18
|
payed: order.payed,
|
|
19
|
+
slotDiscount: order.slotDiscount,
|
|
19
20
|
code: order.code,
|
|
20
21
|
clientName: (0, get_full_name_1.getFullName)(order.client),
|
|
21
22
|
};
|
|
@@ -26,6 +27,7 @@ const serializeSlot = ({ slot, order }) => {
|
|
|
26
27
|
id: slot.id,
|
|
27
28
|
questroomId: slot.questroomId,
|
|
28
29
|
hold: slot.hold,
|
|
30
|
+
old: slot.old,
|
|
29
31
|
date: slot.date,
|
|
30
32
|
discount: slot.discount,
|
|
31
33
|
onlyPhone: slot.onlyPhone,
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.validatePromocode = void 0;
|
|
4
|
+
const date_fns_1 = require("date-fns");
|
|
5
|
+
const date_fns_tz_1 = require("date-fns-tz");
|
|
4
6
|
function getWeekdayNumber(date) {
|
|
5
7
|
const day = new Date(date).getDay();
|
|
6
8
|
return (day === 0 ? 7 : day) - 1;
|
|
7
9
|
}
|
|
8
10
|
function validatePromocode({ promocode, players, questroomId, timeZone, orderDate, hasCertificates, otherPromocodes, isInside, type, }) {
|
|
9
11
|
const errors = [];
|
|
10
|
-
const orderDateInTimeZone = type === 'order' &&
|
|
11
|
-
const currentDate = type === 'order' &&
|
|
12
|
+
const orderDateInTimeZone = type === 'order' && (0, date_fns_tz_1.utcToZonedTime)(new Date(orderDate).toISOString(), timeZone);
|
|
13
|
+
const currentDate = type === 'order' && (0, date_fns_1.format)(orderDateInTimeZone, 'yyyy-MM-dd');
|
|
12
14
|
const orderDayOfWeek = type === 'order' && getWeekdayNumber(orderDateInTimeZone);
|
|
13
|
-
const localOrderTime = type === 'order' &&
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
const localOrderTime = type === 'order' && (0, date_fns_1.format)(orderDateInTimeZone, 'HH:mm');
|
|
16
|
+
const todayDate = (0, date_fns_1.format)((0, date_fns_tz_1.utcToZonedTime)(new Date(), timeZone), 'yyyy-MM-dd');
|
|
17
|
+
console.log({
|
|
18
|
+
currentDate, orderDayOfWeek, localOrderTime, orderDate, timeZone,
|
|
19
|
+
});
|
|
17
20
|
if (type === 'certificate' && !promocode.availableForCertificates) {
|
|
18
21
|
errors.push("The promocode can't be applied for certificates.");
|
|
19
22
|
}
|
|
@@ -56,10 +59,10 @@ function validatePromocode({ promocode, players, questroomId, timeZone, orderDat
|
|
|
56
59
|
if (!promocode.allQuestrooms && !promocode.questroomsIds?.includes(questroomId)) {
|
|
57
60
|
errors.push('The promocode is not valid for the selected escape room.');
|
|
58
61
|
}
|
|
59
|
-
if (type === 'order' && promocode.availableFrom &&
|
|
62
|
+
if (type === 'order' && promocode.availableFrom && localOrderTime < promocode.availableFrom) {
|
|
60
63
|
errors.push(`The promocode is available from ${promocode.availableFrom}.`);
|
|
61
64
|
}
|
|
62
|
-
if (type === 'order' && promocode.availableTo &&
|
|
65
|
+
if (type === 'order' && promocode.availableTo && localOrderTime > promocode.availableTo) {
|
|
63
66
|
errors.push(`The promocode is only available until ${promocode.availableTo}.`);
|
|
64
67
|
}
|
|
65
68
|
if (type === 'order' &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@escapenavigator/utils",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.40",
|
|
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.9.
|
|
17
|
+
"@escapenavigator/types": "^1.9.38",
|
|
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": "3292197490e3df9bc3410ba0b0e45214b1023a37"
|
|
59
59
|
}
|