turf-common 1.2.1-beta.35 → 1.2.1-beta.36

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.
@@ -10,17 +10,19 @@ export interface IGetAvailabilityByTurf {
10
10
  [dateCode: string]: IAvailabilityData;
11
11
  }
12
12
  export interface ITurfAvailabilityDetails {
13
- [pitchId: string]: {
14
- bookingId?: number;
15
- status?: BookingDetailsStatus;
16
- price: number;
17
- priceSlot?: string;
18
- };
13
+ [pitchId: string]: ITurfAvailabilityDetail;
14
+ }
15
+ export interface ITurfAvailabilityDetail {
16
+ price: number;
17
+ bookingId?: number;
18
+ status?: BookingDetailsStatus;
19
+ priceSlot?: string;
19
20
  }
20
21
  export interface IAvailabilityData {
21
- [timeSlot: string]: {
22
- available: number[];
23
- notavailable: number[];
24
- details: ITurfAvailabilityDetails;
25
- };
22
+ [timeSlot: string]: ITurfAvailabilityBooking;
23
+ }
24
+ export interface ITurfAvailabilityBooking {
25
+ available: number[];
26
+ notavailable: number[];
27
+ details: ITurfAvailabilityDetails;
26
28
  }
@@ -0,0 +1,39 @@
1
+ import { IGetAvailabilityByTurf } from "../@type";
2
+ interface ITurfAvailability {
3
+ data: IGetAvailabilityByTurf;
4
+ dateCodes: string[];
5
+ timeSlotCodesDateWise: Record<string, string[]>;
6
+ getTotalAvailablePrice(): number;
7
+ getTotalNonAvailablePrice(): number;
8
+ getTotalAvailableHours(): number;
9
+ getTotalNonAvailableHours(): number;
10
+ getSlots(): {
11
+ fromDate: number;
12
+ toDate: number;
13
+ from: string;
14
+ to: string;
15
+ weekdays: number[];
16
+ }[];
17
+ getPitchIds(): number[];
18
+ }
19
+ export declare class TurfAvailability implements ITurfAvailability {
20
+ data: IGetAvailabilityByTurf;
21
+ dateCodes: string[];
22
+ timeSlotCodesDateWise: Record<string, string[]>;
23
+ constructor(data: IGetAvailabilityByTurf);
24
+ getTotalAvailablePrice(): number;
25
+ getTotalNonAvailablePrice(): number;
26
+ getTotalAvailableHours(): number;
27
+ getTotalNonAvailableHours(): number;
28
+ getSlots(): {
29
+ fromDate: number;
30
+ toDate: number;
31
+ from: string;
32
+ to: string;
33
+ weekdays: number[];
34
+ }[];
35
+ getPitchIds(): number[];
36
+ static fromJson(json: IGetAvailabilityByTurf): TurfAvailability;
37
+ static toJson(turfAvailability: TurfAvailability): IGetAvailabilityByTurf;
38
+ }
39
+ export {};
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TurfAvailability = void 0;
4
+ var booking_code_model_1 = require("./booking-code-model");
5
+ var TurfAvailability = /** @class */ (function () {
6
+ function TurfAvailability(data) {
7
+ var _this = this;
8
+ this.data = data;
9
+ this.dateCodes = Object.keys(data).sort();
10
+ this.timeSlotCodesDateWise = {};
11
+ Object.entries(data).forEach(function (_a) {
12
+ var key = _a[0], value = _a[1];
13
+ _this.timeSlotCodesDateWise[key] = Object.keys(value).sort();
14
+ });
15
+ }
16
+ TurfAvailability.prototype.getTotalAvailablePrice = function () {
17
+ var totalCost = 0;
18
+ Object.entries(this.data).forEach(function (_a) {
19
+ var dateCode = _a[0], detailsTimeSlotCodeWise = _a[1];
20
+ Object.entries(detailsTimeSlotCodeWise).forEach(function (_a) {
21
+ var timeCode = _a[0], detailsPitchWise = _a[1];
22
+ Object.entries(detailsPitchWise.details).forEach(function (_a) {
23
+ var pitchCode = _a[0], details = _a[1];
24
+ if (!details.bookingId) {
25
+ totalCost += details.price;
26
+ }
27
+ });
28
+ });
29
+ });
30
+ return totalCost;
31
+ };
32
+ TurfAvailability.prototype.getTotalNonAvailablePrice = function () {
33
+ var totalCost = 0;
34
+ Object.entries(this.data).forEach(function (_a) {
35
+ var dateCode = _a[0], detailsTimeSlotCodeWise = _a[1];
36
+ Object.entries(detailsTimeSlotCodeWise).forEach(function (_a) {
37
+ var timeCode = _a[0], detailsPitchWise = _a[1];
38
+ Object.entries(detailsPitchWise.details).forEach(function (_a) {
39
+ var pitchCode = _a[0], details = _a[1];
40
+ if (details.bookingId !== undefined) {
41
+ totalCost += details.price;
42
+ }
43
+ });
44
+ });
45
+ });
46
+ return totalCost;
47
+ };
48
+ TurfAvailability.prototype.getTotalAvailableHours = function () {
49
+ var totalMinutes = 0;
50
+ Object.entries(this.data).forEach(function (_a) {
51
+ var dateCode = _a[0], detailsTimeSlotCodeWise = _a[1];
52
+ Object.entries(detailsTimeSlotCodeWise).forEach(function (_a) {
53
+ var timeCode = _a[0], detailsPitchWise = _a[1];
54
+ Object.entries(detailsPitchWise.details).forEach(function (_a) {
55
+ var pitchCode = _a[0], details = _a[1];
56
+ pitchCode = pitchCode.padStart(2, "0");
57
+ if (!details.bookingId) {
58
+ totalMinutes += new booking_code_model_1.BookingCode("0000".concat(dateCode).concat(timeCode).concat(pitchCode)).getTotalTime("minute");
59
+ }
60
+ });
61
+ });
62
+ });
63
+ return totalMinutes / 60;
64
+ };
65
+ TurfAvailability.prototype.getTotalNonAvailableHours = function () {
66
+ var totalMinutes = 0;
67
+ Object.entries(this.data).forEach(function (_a) {
68
+ var dateCode = _a[0], detailsTimeSlotCodeWise = _a[1];
69
+ Object.entries(detailsTimeSlotCodeWise).forEach(function (_a) {
70
+ var timeCode = _a[0], detailsPitchWise = _a[1];
71
+ Object.entries(detailsPitchWise.details).forEach(function (_a) {
72
+ var pitchCode = _a[0], details = _a[1];
73
+ pitchCode = pitchCode.padStart(2, "0");
74
+ if (details.bookingId !== undefined) {
75
+ totalMinutes += new booking_code_model_1.BookingCode("0000".concat(dateCode).concat(timeCode).concat(pitchCode)).getTotalTime("minute");
76
+ }
77
+ });
78
+ });
79
+ });
80
+ return totalMinutes / 60;
81
+ };
82
+ TurfAvailability.prototype.getSlots = function () {
83
+ this.dateCodes.sort(function (a, b) { return a.localeCompare(b); });
84
+ var fromDate = this.dateCodes[0];
85
+ var toDate = this.dateCodes[this.dateCodes.length - 1];
86
+ var fromDateTimeSlots = this.timeSlotCodesDateWise[fromDate];
87
+ var toDateTimeSlots = this.timeSlotCodesDateWise[toDate];
88
+ fromDateTimeSlots.sort(function (a, b) { return a.localeCompare(b); });
89
+ toDateTimeSlots.sort(function (a, b) { return a.localeCompare(b); });
90
+ var fromTime = fromDateTimeSlots[0].substring(0, 4);
91
+ var toTime = toDateTimeSlots[toDateTimeSlots.length - 1].substring(4, 8);
92
+ return [
93
+ {
94
+ fromDate: parseInt(fromDate, 10),
95
+ toDate: parseInt(toDate, 10),
96
+ from: fromTime,
97
+ to: toTime,
98
+ weekdays: [1, 2, 3, 4, 5, 6, 7],
99
+ },
100
+ ];
101
+ };
102
+ TurfAvailability.prototype.getPitchIds = function () {
103
+ var pitchIds = new Set();
104
+ var slots = this.getSlots();
105
+ if (this.data[slots[0].fromDate.toString()]) {
106
+ Object.entries(this.data[slots[0].fromDate.toString()]).forEach(function (_a) {
107
+ var timeCode = _a[0], detailsPitchWise = _a[1];
108
+ Object.keys(detailsPitchWise.details).forEach(function (pitchCode) {
109
+ pitchIds.add(parseInt(pitchCode, 10));
110
+ });
111
+ });
112
+ }
113
+ var pitchIdList = Array.from(pitchIds).sort(function (a, b) { return a - b; });
114
+ return pitchIdList;
115
+ };
116
+ TurfAvailability.fromJson = function (json) {
117
+ var data = {};
118
+ Object.entries(json).forEach(function (_a) {
119
+ var dateCode = _a[0], value = _a[1];
120
+ var dateData = {};
121
+ Object.entries(value).forEach(function (_a) {
122
+ var timeCode = _a[0], value = _a[1];
123
+ var timeSlotData = {};
124
+ Object.entries(value.details).forEach(function (_a) {
125
+ var pitchCode = _a[0], value = _a[1];
126
+ timeSlotData[pitchCode] = new TurfAvailabilityDetail({
127
+ price: value.price,
128
+ bookingId: value.bookingId,
129
+ status: value.status,
130
+ priceSlot: value.priceSlot,
131
+ });
132
+ });
133
+ dateData[timeCode] = new TurfAvailabilityBooking({
134
+ available: value.available,
135
+ notavailable: value.notavailable,
136
+ details: timeSlotData,
137
+ });
138
+ });
139
+ data[dateCode] = dateData;
140
+ });
141
+ return new TurfAvailability(data);
142
+ };
143
+ TurfAvailability.toJson = function (turfAvailability) {
144
+ var data = {};
145
+ Object.entries(turfAvailability.data).forEach(function (_a) {
146
+ var dateCode = _a[0], value = _a[1];
147
+ var dateData = {};
148
+ Object.entries(value).forEach(function (_a) {
149
+ var timeCode = _a[0], value = _a[1];
150
+ var timeSlotData = {};
151
+ Object.entries(value.details).forEach(function (_a) {
152
+ var pitchCode = _a[0], value = _a[1];
153
+ timeSlotData[pitchCode] = {
154
+ price: value.price,
155
+ bookingId: value.bookingId,
156
+ status: value.status,
157
+ priceSlot: value.priceSlot,
158
+ };
159
+ });
160
+ dateData[timeCode] = {
161
+ available: value.available,
162
+ notavailable: value.notavailable,
163
+ details: timeSlotData,
164
+ };
165
+ });
166
+ data[dateCode] = dateData;
167
+ });
168
+ return data;
169
+ };
170
+ return TurfAvailability;
171
+ }());
172
+ exports.TurfAvailability = TurfAvailability;
173
+ var TurfAvailabilityDetail = /** @class */ (function () {
174
+ function TurfAvailabilityDetail(_a) {
175
+ var price = _a.price, bookingId = _a.bookingId, status = _a.status, priceSlot = _a.priceSlot;
176
+ this.price = price;
177
+ this.bookingId = bookingId;
178
+ this.status = status;
179
+ this.priceSlot = priceSlot;
180
+ }
181
+ return TurfAvailabilityDetail;
182
+ }());
183
+ var TurfAvailabilityBooking = /** @class */ (function () {
184
+ function TurfAvailabilityBooking(_a) {
185
+ var available = _a.available, notavailable = _a.notavailable, details = _a.details;
186
+ this.available = available;
187
+ this.notavailable = notavailable;
188
+ this.details = details;
189
+ }
190
+ return TurfAvailabilityBooking;
191
+ }());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turf-common",
3
- "version": "1.2.1-beta.35",
3
+ "version": "1.2.1-beta.36",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",