turf-common 1.4.2-beta.23 → 1.4.2-beta.25

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.
@@ -28,7 +28,7 @@ export declare class TurfAvailability implements ITurfAvailability {
28
28
  pitchCodes: string[];
29
29
  weekDays: number[];
30
30
  apiRequestModel?: IGetAvailabilityByTurfRequest;
31
- constructor(data: IGetAvailabilityByTurf);
31
+ constructor(data: IGetAvailabilityByTurf, apiRequestModel?: IGetAvailabilityByTurfRequest | null);
32
32
  getTotalAvailablePrice(): number;
33
33
  getTotalNonAvailablePrice(): number;
34
34
  getTotalAvailableHours(): number;
@@ -46,6 +46,13 @@ export declare class TurfAvailability implements ITurfAvailability {
46
46
  getTotalTime(): number;
47
47
  getCode(): string;
48
48
  getEventCode(): string;
49
+ parseEventCode(eventCode: string): {
50
+ fromDateCode: string;
51
+ toDateCode: string;
52
+ fromTimeCode: string;
53
+ toTimeCode: string;
54
+ weekDay: number;
55
+ }[];
49
56
  parse(): void;
50
57
  static parse(eventCode: string): {
51
58
  pitchCodes: string[];
@@ -4,9 +4,13 @@ exports.TurfAvailability = void 0;
4
4
  var _utils_1 = require("../@utils");
5
5
  var booking_code_model_1 = require("./booking-code-model");
6
6
  var TurfAvailability = /** @class */ (function () {
7
- function TurfAvailability(data) {
7
+ function TurfAvailability(data, apiRequestModel) {
8
8
  var _this = this;
9
+ if (apiRequestModel === void 0) { apiRequestModel = null; }
9
10
  this.data = data;
11
+ if (apiRequestModel) {
12
+ this.apiRequestModel = apiRequestModel;
13
+ }
10
14
  this.dateCodes = Object.keys(data).sort();
11
15
  this.timeSlotCodesDateWise = {};
12
16
  Object.entries(data).forEach(function (_a) {
@@ -189,6 +193,42 @@ var TurfAvailability = /** @class */ (function () {
189
193
  }
190
194
  return "";
191
195
  };
196
+ TurfAvailability.prototype.parseEventCode = function (eventCode) {
197
+ var eventCodes = eventCode.split("#");
198
+ var dateCodeRange = eventCodes[1];
199
+ var weekdayTimeSlots = eventCodes[2].split(",");
200
+ var timeSlotsByWeekday = {};
201
+ for (var _i = 0, weekdayTimeSlots_1 = weekdayTimeSlots; _i < weekdayTimeSlots_1.length; _i++) {
202
+ var weekdayTimeSlot = weekdayTimeSlots_1[_i];
203
+ var weekday = parseInt(weekdayTimeSlot.slice(0, 1));
204
+ if (!timeSlotsByWeekday[weekday]) {
205
+ timeSlotsByWeekday[weekday] = [];
206
+ }
207
+ timeSlotsByWeekday[weekday].push(weekdayTimeSlot.slice(1));
208
+ }
209
+ var weekdays = Array.from(new Set(weekdayTimeSlots.map(function (timeSlot) { return parseInt(timeSlot.slice(0, 1)); })));
210
+ var dateCodes = [];
211
+ for (var _a = 0, weekdays_1 = weekdays; _a < weekdays_1.length; _a++) {
212
+ var weekday = weekdays_1[_a];
213
+ dateCodes.push.apply(dateCodes, booking_code_model_1.BookingCode.getDateCodesByWeek(Number(dateCodeRange.slice(0, 6)), Number(dateCodeRange.slice(7, 13)), weekday));
214
+ }
215
+ var data = [];
216
+ for (var _b = 0, dateCodes_1 = dateCodes; _b < dateCodes_1.length; _b++) {
217
+ var dateCode = dateCodes_1[_b];
218
+ var dateCodeWeekday = booking_code_model_1.BookingCode.getWeekday(Number(dateCode));
219
+ for (var _c = 0, _d = timeSlotsByWeekday[dateCodeWeekday] || []; _c < _d.length; _c++) {
220
+ var timeslot = _d[_c];
221
+ data.push({
222
+ fromDateCode: dateCode,
223
+ toDateCode: dateCode,
224
+ fromTimeCode: timeslot.slice(0, 4),
225
+ toTimeCode: timeslot.slice(4, 8),
226
+ weekDay: dateCodeWeekday,
227
+ });
228
+ }
229
+ }
230
+ return data;
231
+ };
192
232
  TurfAvailability.prototype.parse = function () {
193
233
  if (!Object.keys(this.data).length)
194
234
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turf-common",
3
- "version": "1.4.2-beta.23",
3
+ "version": "1.4.2-beta.25",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",