@eventconnectors/ndtrc_model 1.0.0 → 1.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eventconnectors/ndtrc_model",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "jest"
@@ -11,7 +11,7 @@
11
11
  "xmlbuilder": "^15.1.1"
12
12
  },
13
13
  "devDependencies": {
14
- "jest": "^29.0.0"
14
+ "jest": "^29.7.0"
15
15
  },
16
16
  "private": false,
17
17
  "author": "wwwappz",
@@ -1,240 +1,249 @@
1
1
  // Calendar.js
2
2
 
3
- const moment = require('moment');
3
+ const moment = require("moment");
4
4
 
5
5
  class Calendar {
6
- constructor() {
7
- this.singleDates = [];
8
- this.patternDates = [];
9
-
10
- this.opens = [];
11
- this.closeds = [];
12
- this.soldouts = [];
13
- this.cancelleds = [];
14
-
15
- this.excludeholidays = false;
16
- this.cancelled = false;
17
- this.soldout = false;
18
-
19
- }
20
-
21
- static CalendarType = {
22
- NONE: 'NONE',
23
- ALWAYSOPEN: 'ALWAYSOPEN',
24
- ONREQUEST: 'ONREQUEST',
25
- OPENINGTIMES: 'OPENINGTIMES',
26
- PATTERNDATES: 'PATTERNDATES',
27
- SINGLEDATES: 'SINGLEDATES'
28
- };
29
-
30
- cleanupData() {
31
- this.singleDates.forEach(singleDate => {
32
- if (singleDate.when) {
33
- singleDate.when = singleDate.when.filter(when => when.isValid());
34
- }
35
- });
36
-
37
- this.patternDates.forEach(patternDate => {
38
- patternDate.opens.forEach(open => {
39
- open.whens = open.whens.filter(when => when.isValid());
40
- });
41
-
42
- if (patternDate.opens.length && !patternDate.recurrencyType) {
43
- patternDate.recurrencyType = PatternDate.RecurrencyType.WEEKLY;
44
- }
45
- });
46
-
47
- ['opens', 'closeds', 'cancelleds', 'soldouts'].forEach(prop => {
48
- this[prop].forEach(exceptionDate => {
49
- exceptionDate.whens = exceptionDate.whens.filter(when => when.isValid());
50
- });
51
- });
52
- }
53
-
54
- determineCalendarType() {
55
- if (this.calendarType !== null) return;
56
-
57
- if (this.alwaysopen) {
58
- this.calendarType = Calendar.CalendarType.ALWAYSOPEN;
59
- } else if (this.onrequest) {
60
- this.calendarType = Calendar.CalendarType.ONREQUEST;
61
- } else if (this.singleDates.length > 0) {
62
- this.calendarType = Calendar.CalendarType.SINGLEDATES;
63
- } else if (this.patternDates.length > 0) {
64
- const firstPattern = this.patternDates[0];
65
- if (!firstPattern.enddate && !firstPattern.startdate) {
66
- this.calendarType = Calendar.CalendarType.OPENINGTIMES;
67
- } else {
68
- this.calendarType = Calendar.CalendarType.PATTERNDATES;
69
- }
70
- } else {
71
- this.calendarType = Calendar.CalendarType.NONE;
72
- }
73
- }
6
+ constructor() {
7
+ this.singleDates = [];
8
+ this.patternDates = [];
9
+
10
+ this.opens = [];
11
+ this.closeds = [];
12
+ this.soldouts = [];
13
+ this.cancelleds = [];
14
+
15
+ this.excludeholidays = false;
16
+ this.cancelled = false;
17
+ this.soldout = false;
18
+ }
19
+
20
+ static CalendarType = {
21
+ NONE: "NONE",
22
+ ALWAYSOPEN: "ALWAYSOPEN",
23
+ ONREQUEST: "ONREQUEST",
24
+ OPENINGTIMES: "OPENINGTIMES",
25
+ PATTERNDATES: "PATTERNDATES",
26
+ SINGLEDATES: "SINGLEDATES",
27
+ };
28
+
29
+ cleanupData() {
30
+ this.singleDates.forEach((singleDate) => {
31
+ if (singleDate.when) {
32
+ singleDate.when = singleDate.when.filter((when) => when.isValid());
33
+ }
34
+ });
35
+
36
+ this.patternDates.forEach((patternDate) => {
37
+ patternDate.opens.forEach((open) => {
38
+ open.whens = open.whens.filter((when) => when.isValid());
39
+ });
40
+
41
+ if (patternDate.opens.length && !patternDate.recurrencyType) {
42
+ patternDate.recurrencyType = PatternDate.RecurrencyType.WEEKLY;
43
+ }
44
+ });
45
+
46
+ ["opens", "closeds", "cancelleds", "soldouts"].forEach((prop) => {
47
+ this[prop].forEach((exceptionDate) => {
48
+ exceptionDate.whens = exceptionDate.whens.filter((when) =>
49
+ when.isValid()
50
+ );
51
+ });
52
+ });
53
+ }
54
+
55
+ determineCalendarType() {
56
+ if (this.calendarType !== null) return;
57
+
58
+ if (this.alwaysopen) {
59
+ this.calendarType = Calendar.CalendarType.ALWAYSOPEN;
60
+ } else if (this.onrequest) {
61
+ this.calendarType = Calendar.CalendarType.ONREQUEST;
62
+ } else if (this.singleDates.length > 0) {
63
+ this.calendarType = Calendar.CalendarType.SINGLEDATES;
64
+ } else if (this.patternDates.length > 0) {
65
+ const firstPattern = this.patternDates[0];
66
+ if (!firstPattern.enddate && !firstPattern.startdate) {
67
+ this.calendarType = Calendar.CalendarType.OPENINGTIMES;
68
+ } else {
69
+ this.calendarType = Calendar.CalendarType.PATTERNDATES;
70
+ }
71
+ } else {
72
+ this.calendarType = Calendar.CalendarType.NONE;
73
+ }
74
+ }
74
75
  }
75
76
 
76
77
  class SingleDate {
77
- constructor(date = null, when = []) {
78
- this.date = date ? moment(date) : null;
79
- this.when = when;
80
- }
78
+ constructor(date = null, when = []) {
79
+ this.date = date ? moment(date) : null;
80
+ this.when = when;
81
+ }
81
82
 
82
- equals(other) {
83
- if (this === other) return true;
84
- if (!(other instanceof SingleDate)) return false;
83
+ equals(other) {
84
+ if (this === other) return true;
85
+ if (!(other instanceof SingleDate)) return false;
85
86
 
86
- if (!this.date.isSame(other.date)) return false;
87
- if (this.when.length !== other.when.length) return false;
87
+ if (!this.date.isSame(other.date)) return false;
88
+ if (this.when.length !== other.when.length) return false;
88
89
 
89
- return this.when.every((when, index) => when.equals(other.when[index]));
90
- }
90
+ return this.when.every((when, index) => when.equals(other.when[index]));
91
+ }
91
92
  }
92
93
 
93
94
  class PatternDate {
94
- constructor() {
95
- this.startdate = null;
96
- this.enddate = null;
97
- this.recurrencyType = null;
98
-
99
- this.occurrence = null;
100
- this.recurrence = null;
101
- this.opens = [];
102
- }
103
-
104
- static RecurrencyType = {
105
- DAILY: 'daily',
106
- WEEKLY: 'weekly',
107
- MONTHLY_SIMPLE: 'monthlySimple',
108
- MONTHLY_COMPLEX: 'monthlyComplex',
109
- YEARLY: 'yearly'
110
- };
111
-
112
- equals(other) {
113
- if (this === other) return true;
114
- if (!(other instanceof PatternDate)) return false;
115
-
116
- const datesEqual = (!this.startdate && !other.startdate) || this.startdate.isSame(other.startdate);
117
- const endDatesEqual = (!this.enddate && !other.enddate) || this.enddate.isSame(other.enddate);
118
-
119
- return datesEqual &&
120
- endDatesEqual &&
121
- this.recurrencyType === other.recurrencyType &&
122
- this.occurrence === other.occurrence &&
123
- this.recurrence === other.recurrence &&
124
- this.opensEquals(other.opens);
125
- }
126
-
127
- opensEquals(otherOpens) {
128
- if (this.opens.length !== otherOpens.length) return false;
129
- return this.opens.every((open, index) => open.equals(otherOpens[index]));
130
- }
95
+ constructor() {
96
+ this.startdate = null;
97
+ this.enddate = null;
98
+ this.recurrencyType = null;
99
+
100
+ this.occurrence = null;
101
+ this.recurrence = null;
102
+ this.opens = [];
103
+ }
104
+
105
+ static RecurrencyType = {
106
+ DAILY: "daily",
107
+ WEEKLY: "weekly",
108
+ MONTHLY_SIMPLE: "monthlySimple",
109
+ MONTHLY_COMPLEX: "monthlyComplex",
110
+ YEARLY: "yearly",
111
+ };
112
+
113
+ equals(other) {
114
+ if (this === other) return true;
115
+ if (!(other instanceof PatternDate)) return false;
116
+
117
+ const datesEqual =
118
+ (!this.startdate && !other.startdate) ||
119
+ this.startdate.isSame(other.startdate);
120
+ const endDatesEqual =
121
+ (!this.enddate && !other.enddate) || this.enddate.isSame(other.enddate);
122
+
123
+ return (
124
+ datesEqual &&
125
+ endDatesEqual &&
126
+ this.recurrencyType === other.recurrencyType &&
127
+ this.occurrence === other.occurrence &&
128
+ this.recurrence === other.recurrence &&
129
+ this.opensEquals(other.opens)
130
+ );
131
+ }
132
+
133
+ opensEquals(otherOpens) {
134
+ if (this.opens.length !== otherOpens.length) return false;
135
+ return this.opens.every((open, index) => open.equals(otherOpens[index]));
136
+ }
131
137
  }
132
138
 
133
139
  class Open {
134
- constructor() {
135
- this.month = null;
136
- this.weeknumber = null;
137
- this.daynumber = null;
138
- this.day = null;
139
- this.whens = [];
140
- }
141
-
142
- equals(other) {
143
- if (this === other) return true;
144
- if (!(other instanceof Open)) return false;
145
-
146
- return this.month === other.month &&
147
- this.weeknumber === other.weeknumber &&
148
- this.daynumber === other.daynumber &&
149
- this.day === other.day &&
150
- this.whensEquals(other.whens);
151
- }
152
-
153
- whensEquals(otherWhens) {
154
- if (this.whens.length !== otherWhens.length) return false;
155
- return this.whens.every((when, index) => when.equals(otherWhens[index]));
156
- }
140
+ constructor() {
141
+ this.month = null;
142
+ this.weeknumber = null;
143
+ this.daynumber = null;
144
+ this.day = null;
145
+ this.whens = [];
146
+ }
147
+
148
+ equals(other) {
149
+ if (this === other) return true;
150
+ if (!(other instanceof Open)) return false;
151
+
152
+ return (
153
+ this.month === other.month &&
154
+ this.weeknumber === other.weeknumber &&
155
+ this.daynumber === other.daynumber &&
156
+ this.day === other.day &&
157
+ this.whensEquals(other.whens)
158
+ );
159
+ }
160
+
161
+ whensEquals(otherWhens) {
162
+ if (this.whens.length !== otherWhens.length) return false;
163
+ return this.whens.every((when, index) => when.equals(otherWhens[index]));
164
+ }
157
165
  }
158
166
 
159
167
  class When {
160
- constructor(timestart = null, status = null) {
161
- this.timestart = timestart;
162
-
163
- this.status = status;
164
- this.statustranslations = [];
165
- this.extrainformations = [];
166
- }
167
-
168
- equals(other) {
169
- if (this === other) return true;
170
- if (!(other instanceof When)) return false;
171
-
172
- return this.timestart === other.timestart && this.timeend === other.timeend;
173
- }
174
-
175
- isValid() {
176
- return this.isTimeValid(this.timestart) || this.isTimeValid(this.timeend);
177
- }
178
-
179
- isTimeValid(time) {
180
- return time && time.trim().length > 0;
181
- }
182
-
183
- static Status = {
184
- NORMAL: 'normal',
185
- CANCELLED: 'cancelled',
186
- SOLDOUT: 'soldout',
187
- MOVEDTO: 'movedto',
188
- PREMIERE: 'premiere',
189
- REPRISE: 'reprise'
190
- };
168
+ constructor(timestart = null, timeend = null, status = null, valid=null) {
169
+ this.timestart = timestart;
170
+ this.valid = valid;
171
+ this.timeend = timeend;
172
+ this.status = status;
173
+ this.statustranslations = [];
174
+ this.extrainformations = [];
175
+ }
176
+
177
+ equals(other) {
178
+ if (this === other) return true;
179
+ if (!(other instanceof When)) return false;
180
+
181
+ return this.timestart === other.timestart && this.timeend === other.timeend;
182
+ }
183
+
184
+ isValid() {
185
+ return this.isTimeValid(this.timestart) || this.isTimeValid(this.timeend);
186
+ }
187
+
188
+ isTimeValid(time) {
189
+ return time && time.trim().length > 0;
190
+ }
191
+
192
+ static Status = {
193
+ NORMAL: "normal",
194
+ CANCELLED: "cancelled",
195
+ SOLDOUT: "soldout",
196
+ MOVEDTO: "movedto",
197
+ PREMIERE: "premiere",
198
+ REPRISE: "reprise",
199
+ };
191
200
  }
192
201
 
193
202
  class StatusTranslation {
194
- constructor(lang = null, text = null) {
195
- this.lang = lang;
196
- this.text = text;
197
- }
203
+ constructor(lang = null, text = null) {
204
+ this.lang = lang;
205
+ this.text = text;
206
+ }
198
207
  }
199
208
 
200
209
  class ExtraInformation {
201
- constructor(lang = null, text = null) {
202
- this.lang = lang;
203
- this.text = text;
204
- }
210
+ constructor(lang = null, text = null) {
211
+ this.lang = lang;
212
+ this.text = text;
213
+ }
205
214
  }
206
215
 
207
216
  class ExceptionDate {
208
- constructor(date = null, whens = []) {
209
- this.date = date ? moment(date) : null;
210
- this.whens = whens;
211
- }
217
+ constructor(date = null, whens = []) {
218
+ this.date = date ? moment(date) : null;
219
+ this.whens = whens;
220
+ }
212
221
  }
213
222
 
214
223
  class Comment {
215
- constructor(label = null, commentTranslations = []) {
216
- this.label = label;
217
- this.commentTranslations = commentTranslations;
218
- }
224
+ constructor(label = null, commentTranslations = []) {
225
+ this.label = label;
226
+ this.commentTranslations = commentTranslations;
227
+ }
219
228
  }
220
229
 
221
230
  class CommentTranslation {
222
- constructor(label = null, lang = null) {
223
- this.label = label;
224
- this.lang = lang;
225
- }
231
+ constructor(label = null, lang = null) {
232
+ this.label = label;
233
+ this.lang = lang;
234
+ }
226
235
  }
227
236
 
228
237
  // Export the classes
229
238
  module.exports = {
230
- Calendar,
231
- SingleDate,
232
- PatternDate,
233
- Open,
234
- When,
235
- StatusTranslation,
236
- ExtraInformation,
237
- ExceptionDate,
238
- Comment,
239
- CommentTranslation
240
- };
239
+ Calendar,
240
+ SingleDate,
241
+ PatternDate,
242
+ Open,
243
+ When,
244
+ StatusTranslation,
245
+ ExtraInformation,
246
+ ExceptionDate,
247
+ Comment,
248
+ CommentTranslation,
249
+ };