tods-competition-factory 2.3.1 → 2.3.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.
@@ -1356,6 +1356,10 @@ declare const errorConditionConstants: {
1356
1356
  message: string;
1357
1357
  code: string;
1358
1358
  };
1359
+ BOOKING_NOT_FOUND: {
1360
+ message: string;
1361
+ code: string;
1362
+ };
1359
1363
  CANNOT_CHANGE_WINNING_SIDE: {
1360
1364
  message: string;
1361
1365
  code: string;
@@ -1388,6 +1392,10 @@ declare const errorConditionConstants: {
1388
1392
  message: string;
1389
1393
  code: string;
1390
1394
  };
1395
+ EXISTING_MATCHUPS: {
1396
+ message: string;
1397
+ code: string;
1398
+ };
1391
1399
  DRAW_DEFINITION_NOT_FOUND: {
1392
1400
  message: string;
1393
1401
  code: string;
@@ -8456,10 +8464,11 @@ type SetSchedulingProfileArgs = {
8456
8464
  };
8457
8465
  declare function setSchedulingProfile({ tournamentRecords, tournamentRecord, schedulingProfile, }: SetSchedulingProfileArgs): any;
8458
8466
 
8459
- declare function courtGridRows({ courtPrefix, minRowsCount, courtsData }: {
8467
+ declare function courtGridRows({ courtPrefix, minRowsCount, courtsData, scheduledDate }: {
8460
8468
  courtPrefix?: string | undefined;
8461
8469
  minRowsCount: any;
8462
8470
  courtsData: any;
8471
+ scheduledDate: any;
8463
8472
  }): {
8464
8473
  error: {
8465
8474
  message: string;
@@ -9448,6 +9457,31 @@ declare function findMatchUpFormatTiming({ defaultRecoveryMinutes, defaultAverag
9448
9457
  error?: undefined;
9449
9458
  };
9450
9459
 
9460
+ type AddCourtGridBookingArgs = {
9461
+ tournamentRecord: Tournament;
9462
+ disableNotice?: boolean;
9463
+ bookingType: string;
9464
+ courtOrder: number;
9465
+ scheduledDate: string;
9466
+ courtId: string;
9467
+ rowCount?: number;
9468
+ notes?: string;
9469
+ };
9470
+ declare function addCourtGridBooking(params: AddCourtGridBookingArgs): ResultType & {
9471
+ booking?: any;
9472
+ };
9473
+
9474
+ type RemoveCourtGridBookingArgs = {
9475
+ tournamentRecord: Tournament;
9476
+ disableNotice?: boolean;
9477
+ scheduledDate: string;
9478
+ courtOrder: number;
9479
+ courtId: string;
9480
+ };
9481
+ declare function removeCourtGridBooking(params: RemoveCourtGridBookingArgs): ResultType & {
9482
+ booking?: any;
9483
+ };
9484
+
9451
9485
  type AddMatchUpScheduleItemsArgs = {
9452
9486
  inContextMatchUps?: HydratedMatchUp[];
9453
9487
  drawMatchUps?: HydratedMatchUp[];
@@ -9490,6 +9524,7 @@ declare function addMatchUpResumeTime({ removePriorValues, tournamentRecord, dra
9490
9524
  resumeTime?: string;
9491
9525
  }): any;
9492
9526
 
9527
+ declare const mutate$4_addCourtGridBooking: typeof addCourtGridBooking;
9493
9528
  declare const mutate$4_addMatchUpCourtOrder: typeof addMatchUpCourtOrder;
9494
9529
  declare const mutate$4_addMatchUpEndTime: typeof addMatchUpEndTime;
9495
9530
  declare const mutate$4_addMatchUpOfficial: typeof addMatchUpOfficial;
@@ -9517,6 +9552,7 @@ declare const mutate$4_matchUpScheduleChange: typeof matchUpScheduleChange;
9517
9552
  declare const mutate$4_modifyMatchUpFormatTiming: typeof modifyMatchUpFormatTiming;
9518
9553
  declare const mutate$4_proAutoSchedule: typeof proAutoSchedule;
9519
9554
  declare const mutate$4_proConflicts: typeof proConflicts;
9555
+ declare const mutate$4_removeCourtGridBooking: typeof removeCourtGridBooking;
9520
9556
  declare const mutate$4_removeEventMatchUpFormatTiming: typeof removeEventMatchUpFormatTiming;
9521
9557
  declare const mutate$4_removeMatchUpCourtAssignment: typeof removeMatchUpCourtAssignment;
9522
9558
  declare const mutate$4_reorderUpcomingMatchUps: typeof reorderUpcomingMatchUps;
@@ -9529,6 +9565,7 @@ declare const mutate$4_toggleParticipantCheckInState: typeof toggleParticipantCh
9529
9565
  declare const mutate$4_validateSchedulingProfile: typeof validateSchedulingProfile;
9530
9566
  declare namespace mutate$4 {
9531
9567
  export {
9568
+ mutate$4_addCourtGridBooking as addCourtGridBooking,
9532
9569
  mutate$4_addMatchUpCourtOrder as addMatchUpCourtOrder,
9533
9570
  mutate$4_addMatchUpEndTime as addMatchUpEndTime,
9534
9571
  mutate$4_addMatchUpOfficial as addMatchUpOfficial,
@@ -9556,6 +9593,7 @@ declare namespace mutate$4 {
9556
9593
  mutate$4_modifyMatchUpFormatTiming as modifyMatchUpFormatTiming,
9557
9594
  mutate$4_proAutoSchedule as proAutoSchedule,
9558
9595
  mutate$4_proConflicts as proConflicts,
9596
+ mutate$4_removeCourtGridBooking as removeCourtGridBooking,
9559
9597
  mutate$4_removeEventMatchUpFormatTiming as removeEventMatchUpFormatTiming,
9560
9598
  mutate$4_removeMatchUpCourtAssignment as removeMatchUpCourtAssignment,
9561
9599
  mutate$4_reorderUpcomingMatchUps as reorderUpcomingMatchUps,
@@ -9569,6 +9607,7 @@ declare namespace mutate$4 {
9569
9607
  };
9570
9608
  }
9571
9609
 
9610
+ declare const index$7_addCourtGridBooking: typeof addCourtGridBooking;
9572
9611
  declare const index$7_addMatchUpCourtOrder: typeof addMatchUpCourtOrder;
9573
9612
  declare const index$7_addMatchUpEndTime: typeof addMatchUpEndTime;
9574
9613
  declare const index$7_addMatchUpOfficial: typeof addMatchUpOfficial;
@@ -9605,6 +9644,7 @@ declare const index$7_modifyMatchUpFormatTiming: typeof modifyMatchUpFormatTimin
9605
9644
  declare const index$7_proAutoSchedule: typeof proAutoSchedule;
9606
9645
  declare const index$7_proConflicts: typeof proConflicts;
9607
9646
  declare const index$7_publicFindCourt: typeof publicFindCourt;
9647
+ declare const index$7_removeCourtGridBooking: typeof removeCourtGridBooking;
9608
9648
  declare const index$7_removeEventMatchUpFormatTiming: typeof removeEventMatchUpFormatTiming;
9609
9649
  declare const index$7_removeMatchUpCourtAssignment: typeof removeMatchUpCourtAssignment;
9610
9650
  declare const index$7_reorderUpcomingMatchUps: typeof reorderUpcomingMatchUps;
@@ -9617,6 +9657,7 @@ declare const index$7_toggleParticipantCheckInState: typeof toggleParticipantChe
9617
9657
  declare const index$7_validateSchedulingProfile: typeof validateSchedulingProfile;
9618
9658
  declare namespace index$7 {
9619
9659
  export {
9660
+ index$7_addCourtGridBooking as addCourtGridBooking,
9620
9661
  index$7_addMatchUpCourtOrder as addMatchUpCourtOrder,
9621
9662
  index$7_addMatchUpEndTime as addMatchUpEndTime,
9622
9663
  index$7_addMatchUpOfficial as addMatchUpOfficial,
@@ -9655,6 +9696,7 @@ declare namespace index$7 {
9655
9696
  index$7_proConflicts as proConflicts,
9656
9697
  index$7_publicFindCourt as publicFindCourt,
9657
9698
  query$2 as query,
9699
+ index$7_removeCourtGridBooking as removeCourtGridBooking,
9658
9700
  index$7_removeEventMatchUpFormatTiming as removeEventMatchUpFormatTiming,
9659
9701
  index$7_removeMatchUpCourtAssignment as removeMatchUpCourtAssignment,
9660
9702
  index$7_reorderUpcomingMatchUps as reorderUpcomingMatchUps,
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  function factoryVersion() {
6
- return '2.3.1';
6
+ return '2.3.2';
7
7
  }
8
8
 
9
9
  const SINGLES_MATCHUP = 'SINGLES';
@@ -989,6 +989,14 @@ const COURT_EXISTS = {
989
989
  message: 'Court exists',
990
990
  code: 'ERR_EXISTING_COURT',
991
991
  };
992
+ const BOOKING_NOT_FOUND = {
993
+ message: 'Booking not found',
994
+ code: 'ERR_NOT_FOUND_BOOKING',
995
+ };
996
+ const EXISTING_MATCHUPS = {
997
+ message: 'Existing matchUps conflict with booking',
998
+ code: 'ERR_EXISTING_MATCHUPS',
999
+ };
992
1000
  const VENUE_EXISTS = {
993
1001
  message: 'Venue exists',
994
1002
  code: 'ERR_EXISTING_VENUE',
@@ -1152,6 +1160,7 @@ const SCORES_PRESENT = {
1152
1160
  };
1153
1161
  const errorConditionConstants = {
1154
1162
  ANACHRONISM,
1163
+ BOOKING_NOT_FOUND,
1155
1164
  CANNOT_CHANGE_WINNING_SIDE,
1156
1165
  CANNOT_MODIFY_TIEFORMAT,
1157
1166
  CANNOT_MODIFY_PARTICIPANT_TYPE,
@@ -1160,6 +1169,7 @@ const errorConditionConstants = {
1160
1169
  CATEGORY_MISMATCH,
1161
1170
  COURT_EXISTS,
1162
1171
  COURT_NOT_FOUND,
1172
+ EXISTING_MATCHUPS,
1163
1173
  DRAW_DEFINITION_NOT_FOUND,
1164
1174
  DRAW_ID_EXISTS,
1165
1175
  DRAW_POSITION_ACTIVE,
@@ -36681,7 +36691,31 @@ function getProfileRounds({ tournamentRecords, schedulingProfile, tournamentReco
36681
36691
  return { profileRounds, segmentedRounds };
36682
36692
  }
36683
36693
 
36684
- function courtGridRows({ courtPrefix = 'C|', minRowsCount, courtsData }) {
36694
+ function getCourtDateAvailability({ court, date }) {
36695
+ const targetDateAvailability = date && court.dateAvailability.find((availability) => sameDay(availability.date, date));
36696
+ const defaultAvailability = court.dateAvailability.find((availability) => !availability.date);
36697
+ return targetDateAvailability || defaultAvailability;
36698
+ }
36699
+
36700
+ function getGridBookings({ court, date }) {
36701
+ const courtDate = getCourtDateAvailability({ court, date });
36702
+ const gridBookings = new Map();
36703
+ const timeBookings = [];
36704
+ (courtDate?.bookings || []).forEach((booking) => {
36705
+ if (typeof booking.courtOrder === 'number') {
36706
+ const rowCount = booking.rowCount || 1;
36707
+ for (let i = 0; i < rowCount; i++) {
36708
+ gridBookings.set(booking.courtOrder + i, booking);
36709
+ }
36710
+ }
36711
+ else {
36712
+ timeBookings.push(booking);
36713
+ }
36714
+ });
36715
+ return { gridBookings, timeBookings };
36716
+ }
36717
+
36718
+ function courtGridRows({ courtPrefix = 'C|', minRowsCount, courtsData, scheduledDate }) {
36685
36719
  if (!Array.isArray(courtsData))
36686
36720
  return { error: INVALID_VALUES };
36687
36721
  const maxCourtOrder = courtsData?.reduce((order, court) => {
@@ -36693,7 +36727,21 @@ function courtGridRows({ courtPrefix = 'C|', minRowsCount, courtsData }) {
36693
36727
  const rowBuilder = generateRange(0, rowsCount).map((rowIndex) => ({
36694
36728
  matchUps: generateRange(0, courtsData.length).map((courtIndex) => {
36695
36729
  const courtInfo = courtsData[courtIndex];
36696
- const { courtId, venueId } = courtInfo;
36730
+ const { courtId, venueId, court } = courtInfo;
36731
+ if (scheduledDate && court) {
36732
+ const { gridBookings } = getGridBookings({
36733
+ court,
36734
+ date: scheduledDate,
36735
+ });
36736
+ if (gridBookings.has(rowIndex + 1)) {
36737
+ const booking = gridBookings.get(rowIndex + 1);
36738
+ return {
36739
+ schedule: { courtOrder: rowIndex + 1, venueId, courtId },
36740
+ isBlocked: true,
36741
+ booking,
36742
+ };
36743
+ }
36744
+ }
36697
36745
  return {
36698
36746
  schedule: {
36699
36747
  courtOrder: rowIndex + 1,
@@ -37563,8 +37611,10 @@ function competitionScheduleMatchUps(params) {
37563
37611
  venues,
37564
37612
  };
37565
37613
  if (withCourtGridRows) {
37614
+ const scheduledDate = params.matchUpFilters?.scheduledDate;
37566
37615
  const { rows, courtPrefix } = courtGridRows({
37567
37616
  minRowsCount: Math.max(minCourtGridRows || 0, dateMatchUps.length || 0),
37617
+ scheduledDate,
37568
37618
  courtsData,
37569
37619
  });
37570
37620
  result.courtPrefix = courtPrefix;
@@ -42091,12 +42141,6 @@ function generateCourts(params) {
42091
42141
  return { ...SUCCESS, courts };
42092
42142
  }
42093
42143
 
42094
- function getCourtDateAvailability({ court, date }) {
42095
- const targetDateAvailability = date && court.dateAvailability.find((availability) => sameDay(availability.date, date));
42096
- const defaultAvailability = court.dateAvailability.find((availability) => !availability.date);
42097
- return targetDateAvailability || defaultAvailability;
42098
- }
42099
-
42100
42144
  function generateTimeSlots(params) {
42101
42145
  const paramsCheck = checkRequiredParameters(params, [{ courtDate: true, _ofType: OBJECT }]);
42102
42146
  if (paramsCheck.error)
@@ -55110,7 +55154,7 @@ function proAutoSchedule({ scheduleCompletedMatchUps, tournamentRecords, schedul
55110
55154
  }
55111
55155
  }
55112
55156
  });
55113
- const availableCourts = Object.values(row).filter((c) => isObject(c) && !c.matchUpId);
55157
+ const availableCourts = Object.values(row).filter((c) => isObject(c) && !c.matchUpId && !c.isBlocked);
55114
55158
  return gridRows.concat({
55115
55159
  matchUpIds,
55116
55160
  availableCourts,
@@ -56029,8 +56073,151 @@ function setMatchUpDailyLimits(params) {
56029
56073
  return { ...SUCCESS };
56030
56074
  }
56031
56075
 
56076
+ function addCourtGridBooking(params) {
56077
+ const { tournamentRecord, disableNotice, scheduledDate, bookingType, courtOrder, rowCount = 1, courtId, notes, } = params;
56078
+ if (!tournamentRecord) {
56079
+ return decorateResult({
56080
+ result: { error: INVALID_VALUES },
56081
+ info: 'tournamentRecord is required',
56082
+ });
56083
+ }
56084
+ if (!courtId) {
56085
+ return { error: COURT_NOT_FOUND };
56086
+ }
56087
+ if (!scheduledDate) {
56088
+ return decorateResult({
56089
+ result: { error: INVALID_VALUES },
56090
+ info: 'scheduledDate is required',
56091
+ });
56092
+ }
56093
+ if (!bookingType) {
56094
+ return decorateResult({
56095
+ result: { error: INVALID_VALUES },
56096
+ info: 'bookingType is required',
56097
+ });
56098
+ }
56099
+ if (courtOrder === undefined || courtOrder === null) {
56100
+ return decorateResult({
56101
+ result: { error: INVALID_VALUES },
56102
+ info: 'courtOrder is required',
56103
+ });
56104
+ }
56105
+ if (!Number.isInteger(courtOrder) || courtOrder < 1) {
56106
+ return decorateResult({
56107
+ result: { error: INVALID_VALUES },
56108
+ info: 'courtOrder must be a positive integer',
56109
+ });
56110
+ }
56111
+ if (!Number.isInteger(rowCount) || rowCount < 1) {
56112
+ return decorateResult({
56113
+ result: { error: INVALID_VALUES },
56114
+ info: 'rowCount must be a positive integer',
56115
+ });
56116
+ }
56117
+ const { court, venue } = findCourt({ tournamentRecord, courtId });
56118
+ if (!court)
56119
+ return { error: COURT_NOT_FOUND };
56120
+ const courtDate = getCourtDateAvailability({ court, date: scheduledDate });
56121
+ if (!courtDate) {
56122
+ if (!court.dateAvailability)
56123
+ court.dateAvailability = [];
56124
+ const newAvailability = {
56125
+ date: scheduledDate,
56126
+ bookings: [],
56127
+ };
56128
+ court.dateAvailability.push(newAvailability);
56129
+ }
56130
+ const targetCourtDate = getCourtDateAvailability({ court, date: scheduledDate });
56131
+ if (targetCourtDate.bookings) {
56132
+ for (const existingBooking of targetCourtDate.bookings) {
56133
+ if (typeof existingBooking.courtOrder === 'number') {
56134
+ const existingStart = existingBooking.courtOrder;
56135
+ const existingEnd = existingStart + (existingBooking.rowCount || 1) - 1;
56136
+ const newStart = courtOrder;
56137
+ const newEnd = courtOrder + rowCount - 1;
56138
+ if (newStart <= existingEnd && newEnd >= existingStart) {
56139
+ return decorateResult({
56140
+ result: { error: EXISTING_MATCHUPS },
56141
+ info: `Booking conflicts with existing booking at rows ${existingStart}-${existingEnd}`,
56142
+ });
56143
+ }
56144
+ }
56145
+ }
56146
+ }
56147
+ const booking = {
56148
+ courtOrder,
56149
+ rowCount,
56150
+ bookingType,
56151
+ notes,
56152
+ createdAt: new Date().toISOString(),
56153
+ };
56154
+ if (!targetCourtDate.bookings)
56155
+ targetCourtDate.bookings = [];
56156
+ targetCourtDate.bookings.push(booking);
56157
+ if (!disableNotice && venue) {
56158
+ addNotice({
56159
+ payload: { venue, tournamentId: tournamentRecord.tournamentId },
56160
+ topic: MODIFY_VENUE,
56161
+ key: venue.venueId,
56162
+ });
56163
+ }
56164
+ return { ...SUCCESS, booking };
56165
+ }
56166
+
56167
+ function removeCourtGridBooking(params) {
56168
+ const { tournamentRecord, disableNotice, scheduledDate, courtOrder, courtId, } = params;
56169
+ if (!tournamentRecord) {
56170
+ return decorateResult({
56171
+ result: { error: INVALID_VALUES },
56172
+ info: 'tournamentRecord is required',
56173
+ });
56174
+ }
56175
+ if (!courtId) {
56176
+ return { error: COURT_NOT_FOUND };
56177
+ }
56178
+ if (!scheduledDate) {
56179
+ return decorateResult({
56180
+ result: { error: INVALID_VALUES },
56181
+ info: 'scheduledDate is required',
56182
+ });
56183
+ }
56184
+ if (courtOrder === undefined || courtOrder === null) {
56185
+ return decorateResult({
56186
+ result: { error: INVALID_VALUES },
56187
+ info: 'courtOrder is required',
56188
+ });
56189
+ }
56190
+ const { court, venue } = findCourt({ tournamentRecord, courtId });
56191
+ if (!court)
56192
+ return { error: COURT_NOT_FOUND };
56193
+ const courtDate = getCourtDateAvailability({ court, date: scheduledDate });
56194
+ if (!courtDate?.bookings) {
56195
+ return decorateResult({
56196
+ result: { error: BOOKING_NOT_FOUND },
56197
+ info: 'No bookings found for this date',
56198
+ });
56199
+ }
56200
+ const bookingIndex = courtDate.bookings.findIndex((b) => b.courtOrder === courtOrder);
56201
+ if (bookingIndex === -1) {
56202
+ return decorateResult({
56203
+ result: { error: BOOKING_NOT_FOUND },
56204
+ info: `No booking found at row ${courtOrder}`,
56205
+ });
56206
+ }
56207
+ const removed = courtDate.bookings.splice(bookingIndex, 1)[0];
56208
+ if (!disableNotice && venue) {
56209
+ addNotice({
56210
+ payload: { venue, tournamentId: tournamentRecord.tournamentId },
56211
+ topic: MODIFY_VENUE,
56212
+ key: venue.venueId,
56213
+ });
56214
+ }
56215
+ return { ...SUCCESS, booking: removed };
56216
+ }
56217
+
56032
56218
  var mutate$3 = {
56033
56219
  __proto__: null,
56220
+ addCourtGridBooking: addCourtGridBooking,
56034
56221
  addMatchUpCourtOrder: addMatchUpCourtOrder,
56035
56222
  addMatchUpEndTime: addMatchUpEndTime,
56036
56223
  addMatchUpOfficial: addMatchUpOfficial,
@@ -56058,6 +56245,7 @@ var mutate$3 = {
56058
56245
  modifyMatchUpFormatTiming: modifyMatchUpFormatTiming,
56059
56246
  proAutoSchedule: proAutoSchedule,
56060
56247
  proConflicts: proConflicts,
56248
+ removeCourtGridBooking: removeCourtGridBooking,
56061
56249
  removeEventMatchUpFormatTiming: removeEventMatchUpFormatTiming,
56062
56250
  removeMatchUpCourtAssignment: removeMatchUpCourtAssignment,
56063
56251
  reorderUpcomingMatchUps: reorderUpcomingMatchUps,
@@ -56072,6 +56260,7 @@ var mutate$3 = {
56072
56260
 
56073
56261
  var index$5 = {
56074
56262
  __proto__: null,
56263
+ addCourtGridBooking: addCourtGridBooking,
56075
56264
  addMatchUpCourtOrder: addMatchUpCourtOrder,
56076
56265
  addMatchUpEndTime: addMatchUpEndTime,
56077
56266
  addMatchUpOfficial: addMatchUpOfficial,
@@ -56110,6 +56299,7 @@ var index$5 = {
56110
56299
  proConflicts: proConflicts,
56111
56300
  publicFindCourt: publicFindCourt,
56112
56301
  query: query$4,
56302
+ removeCourtGridBooking: removeCourtGridBooking,
56113
56303
  removeEventMatchUpFormatTiming: removeEventMatchUpFormatTiming,
56114
56304
  removeMatchUpCourtAssignment: removeMatchUpCourtAssignment,
56115
56305
  reorderUpcomingMatchUps: reorderUpcomingMatchUps,