@pisell/pisellos 3.0.31 → 3.0.33
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/modules/Date/index.d.ts +2 -0
- package/dist/modules/Date/index.js +70 -34
- package/dist/modules/Rules/index.js +1 -1
- package/dist/modules/Schedule/types.d.ts +1 -0
- package/dist/modules/Schedule/utils.js +1 -1
- package/dist/solution/BookingByStep/index.d.ts +26 -5
- package/dist/solution/BookingByStep/index.js +358 -27
- package/dist/solution/BookingByStep/utils/resources.d.ts +40 -3
- package/dist/solution/BookingByStep/utils/resources.js +100 -1
- package/dist/solution/BookingByStep/utils/timeslots.d.ts +25 -0
- package/dist/solution/BookingByStep/utils/timeslots.js +209 -0
- package/lib/modules/Date/index.d.ts +2 -0
- package/lib/modules/Date/index.js +23 -10
- package/lib/modules/Rules/index.js +2 -2
- package/lib/modules/Schedule/types.d.ts +1 -0
- package/lib/modules/Schedule/utils.js +1 -1
- package/lib/solution/BookingByStep/index.d.ts +26 -5
- package/lib/solution/BookingByStep/index.js +280 -34
- package/lib/solution/BookingByStep/utils/resources.d.ts +40 -3
- package/lib/solution/BookingByStep/utils/resources.js +73 -2
- package/lib/solution/BookingByStep/utils/timeslots.d.ts +25 -0
- package/lib/solution/BookingByStep/utils/timeslots.js +159 -0
- package/package.json +1 -1
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/solution/BookingByStep/utils/timeslots.ts
|
|
30
|
+
var timeslots_exports = {};
|
|
31
|
+
__export(timeslots_exports, {
|
|
32
|
+
calculateResourceAvailableTime: () => calculateResourceAvailableTime,
|
|
33
|
+
findFastestAvailableResource: () => findFastestAvailableResource
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(timeslots_exports);
|
|
36
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
37
|
+
function calculateResourceAvailableTime({
|
|
38
|
+
resource,
|
|
39
|
+
timeSlots,
|
|
40
|
+
currentCapacity = 1
|
|
41
|
+
}) {
|
|
42
|
+
const matchingTimes = resource.times.filter((time) => {
|
|
43
|
+
return (0, import_dayjs.default)(time.start_at).isSame((0, import_dayjs.default)(timeSlots.start_at), "day");
|
|
44
|
+
});
|
|
45
|
+
if (matchingTimes.length === 0)
|
|
46
|
+
return 0;
|
|
47
|
+
const overlaps = [];
|
|
48
|
+
for (const time of matchingTimes) {
|
|
49
|
+
const overlapStart = (0, import_dayjs.default)(time.start_at).isAfter((0, import_dayjs.default)(timeSlots.start_at)) ? (0, import_dayjs.default)(time.start_at) : (0, import_dayjs.default)(timeSlots.start_at);
|
|
50
|
+
const overlapEnd = (0, import_dayjs.default)(time.end_at).isBefore((0, import_dayjs.default)(timeSlots.end_at)) ? (0, import_dayjs.default)(time.end_at) : (0, import_dayjs.default)(timeSlots.end_at);
|
|
51
|
+
if (overlapStart.isBefore(overlapEnd)) {
|
|
52
|
+
overlaps.push({ start: overlapStart, end: overlapEnd });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (overlaps.length === 0)
|
|
56
|
+
return 0;
|
|
57
|
+
overlaps.sort((a, b) => a.start.diff(b.start));
|
|
58
|
+
const merged = [];
|
|
59
|
+
let current = overlaps[0];
|
|
60
|
+
for (let i = 1; i < overlaps.length; i++) {
|
|
61
|
+
const next = overlaps[i];
|
|
62
|
+
if (current.end.isSameOrAfter(next.start)) {
|
|
63
|
+
current.end = current.end.isAfter(next.end) ? current.end : next.end;
|
|
64
|
+
} else {
|
|
65
|
+
merged.push(current);
|
|
66
|
+
current = next;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
merged.push(current);
|
|
70
|
+
let totalAvailableMinutes = 0;
|
|
71
|
+
for (const segment of merged) {
|
|
72
|
+
totalAvailableMinutes += segment.end.diff(segment.start, "minute");
|
|
73
|
+
}
|
|
74
|
+
return totalAvailableMinutes;
|
|
75
|
+
}
|
|
76
|
+
function findFastestAvailableResource({
|
|
77
|
+
resources,
|
|
78
|
+
currentCapacity = 1,
|
|
79
|
+
countMap = {}
|
|
80
|
+
}) {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
const currentTime = (0, import_dayjs.default)();
|
|
83
|
+
let fastestTime = null;
|
|
84
|
+
let fastestResources = [];
|
|
85
|
+
for (const resource of resources) {
|
|
86
|
+
const todayTimes = resource.times.filter((time) => {
|
|
87
|
+
return (0, import_dayjs.default)(time.start_at).isSame(currentTime, "day");
|
|
88
|
+
});
|
|
89
|
+
if (todayTimes.length === 0)
|
|
90
|
+
continue;
|
|
91
|
+
todayTimes.sort((a, b) => {
|
|
92
|
+
return (0, import_dayjs.default)(a.start_at).diff((0, import_dayjs.default)(b.start_at));
|
|
93
|
+
});
|
|
94
|
+
for (const time of todayTimes) {
|
|
95
|
+
const startTime = (0, import_dayjs.default)(time.start_at);
|
|
96
|
+
if (startTime.isBefore(currentTime))
|
|
97
|
+
continue;
|
|
98
|
+
if (resource.resourceType === "single") {
|
|
99
|
+
const hasBooking = (_a = time.event_list) == null ? void 0 : _a.some((event) => {
|
|
100
|
+
return (0, import_dayjs.default)(event.start_at).isSame(startTime);
|
|
101
|
+
});
|
|
102
|
+
if (!hasBooking) {
|
|
103
|
+
if (!fastestTime || startTime.isSame(fastestTime)) {
|
|
104
|
+
fastestTime = startTime;
|
|
105
|
+
fastestResources.push(resource);
|
|
106
|
+
} else if (startTime.isBefore(fastestTime)) {
|
|
107
|
+
fastestTime = startTime;
|
|
108
|
+
fastestResources = [resource];
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
} else {
|
|
113
|
+
const totalCapacity = resource.capacity || 0;
|
|
114
|
+
const usedCapacity = ((_b = time.event_list) == null ? void 0 : _b.reduce((sum, event) => {
|
|
115
|
+
return (0, import_dayjs.default)(event.start_at).isSame(startTime) ? sum + (event.pax || 0) : sum;
|
|
116
|
+
}, 0)) || 0;
|
|
117
|
+
const remainingCapacity = totalCapacity - usedCapacity;
|
|
118
|
+
if (remainingCapacity >= (countMap[resource.id] || 0) + currentCapacity) {
|
|
119
|
+
if (!fastestTime || startTime.isSame(fastestTime)) {
|
|
120
|
+
fastestTime = startTime;
|
|
121
|
+
fastestResources.push(resource);
|
|
122
|
+
} else if (startTime.isBefore(fastestTime)) {
|
|
123
|
+
fastestTime = startTime;
|
|
124
|
+
fastestResources = [resource];
|
|
125
|
+
}
|
|
126
|
+
break;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (!fastestTime || fastestResources.length === 0)
|
|
132
|
+
return null;
|
|
133
|
+
if (fastestResources.length === 1)
|
|
134
|
+
return fastestResources[0];
|
|
135
|
+
let maxIdleTime = 0;
|
|
136
|
+
let selectedResource = null;
|
|
137
|
+
for (const resource of fastestResources) {
|
|
138
|
+
const idleTime = calculateResourceAvailableTime({
|
|
139
|
+
resource,
|
|
140
|
+
timeSlots: {
|
|
141
|
+
start_time: fastestTime.format("HH:mm"),
|
|
142
|
+
end_time: fastestTime.format("HH:mm"),
|
|
143
|
+
start_at: fastestTime,
|
|
144
|
+
end_at: fastestTime
|
|
145
|
+
},
|
|
146
|
+
currentCapacity: (countMap[resource.id] || 0) + currentCapacity
|
|
147
|
+
});
|
|
148
|
+
if (idleTime > maxIdleTime) {
|
|
149
|
+
maxIdleTime = idleTime;
|
|
150
|
+
selectedResource = resource;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return selectedResource;
|
|
154
|
+
}
|
|
155
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
156
|
+
0 && (module.exports = {
|
|
157
|
+
calculateResourceAvailableTime,
|
|
158
|
+
findFastestAvailableResource
|
|
159
|
+
});
|