tods-competition-factory 1.8.7 → 1.8.8

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/index.mjs CHANGED
@@ -945,6 +945,10 @@ const INVALID_OBJECT = {
945
945
  message: "Invalid object",
946
946
  code: "ERR_INVALID_OBJECT"
947
947
  };
948
+ const INVALID_GENDER = {
949
+ message: "Invalid gender",
950
+ code: "ERR_INVALID_GENDER"
951
+ };
948
952
  const INVALID_CATEGORY = {
949
953
  message: "Invalid category",
950
954
  code: "ERR_INVALID_CATEGORY"
@@ -1062,6 +1066,7 @@ const errorConditionConstants = {
1062
1066
  INVALID_ENTRIES,
1063
1067
  INVALID_EVENT_TYPE,
1064
1068
  INVALID_GAME_SCORES,
1069
+ INVALID_GENDER,
1065
1070
  INVALID_MATCHUP_FORMAT,
1066
1071
  INVALID_MATCHUP_STATUS,
1067
1072
  INVALID_MATCHUP_STATUS_BYE,
@@ -2375,7 +2380,7 @@ const matchUpFormatCode = {
2375
2380
  };
2376
2381
 
2377
2382
  function factoryVersion() {
2378
- return "1.8.7";
2383
+ return "1.8.8";
2379
2384
  }
2380
2385
 
2381
2386
  function getObjectTieFormat(obj) {
@@ -2938,6 +2943,11 @@ function validateCollectionDefinition({
2938
2943
  }
2939
2944
  if (checkGender && referenceGender && gender && [GenderEnum.Male, GenderEnum.Female].includes(referenceGender) && referenceGender !== gender) {
2940
2945
  errors.push(`Invalid gender: ${gender}`);
2946
+ return decorateResult({
2947
+ context: { referenceGender, gender },
2948
+ result: { error: INVALID_GENDER },
2949
+ stack
2950
+ });
2941
2951
  }
2942
2952
  if (checkCategory && referenceCategory && category) {
2943
2953
  const result = categoryCanContain({
@@ -42317,8 +42327,8 @@ function getAvoidanceConflicts({ isRoundRobin, groupedParticipants }) {
42317
42327
  function getSwapOptions({
42318
42328
  positionedParticipants,
42319
42329
  potentialDrawPositions,
42320
- avoidanceConflicts,
42321
42330
  drawPositionGroups,
42331
+ avoidanceConflicts,
42322
42332
  isRoundRobin
42323
42333
  }) {
42324
42334
  return avoidanceConflicts.map((conflict) => {
@@ -53798,15 +53808,79 @@ function setTournamentStatus({ tournamentRecord, status }) {
53798
53808
 
53799
53809
  function addOnlineResource({
53800
53810
  tournamentRecord,
53801
- onlineResource
53811
+ onlineResource,
53812
+ organisationId,
53813
+ participantId,
53814
+ personId,
53815
+ courtId,
53816
+ venueId
53802
53817
  }) {
53803
53818
  if (!tournamentRecord)
53804
53819
  return { error: MISSING_TOURNAMENT_RECORD };
53805
- if (!onlineResource)
53820
+ if (!isObject(onlineResource))
53806
53821
  return { error: MISSING_VALUE };
53807
- if (!tournamentRecord.onlineResources)
53808
- tournamentRecord.onlineResources = [];
53809
- tournamentRecord.onlineResources.push(onlineResource);
53822
+ if (intersection(Object.keys(onlineResource), [
53823
+ "resourceSubType",
53824
+ "resourceType",
53825
+ "identifier"
53826
+ ]).length !== 3)
53827
+ return decorateResult({
53828
+ result: { error: INVALID_OBJECT },
53829
+ context: { onlineResource }
53830
+ });
53831
+ if (organisationId) {
53832
+ if (tournamentRecord.parentOrganisation?.parentOrganisationId !== organisationId) {
53833
+ return decorateResult({ result: { error: NOT_FOUND } });
53834
+ }
53835
+ if (!tournamentRecord.parentOrganisation.onlineResources)
53836
+ tournamentRecord.parentOrganisation.onlineResources = [];
53837
+ tournamentRecord.parentOrganisation.onlineResources.push(onlineResource);
53838
+ } else if (participantId || personId) {
53839
+ const participant = (tournamentRecord.participants ?? []).find(
53840
+ (p) => personId && p.person?.personId === personId || p.participantId === participantId
53841
+ );
53842
+ if (!participant) {
53843
+ if (personId) {
53844
+ return decorateResult({ result: { error: NOT_FOUND } });
53845
+ } else {
53846
+ return decorateResult({ result: { error: PARTICIPANT_NOT_FOUND } });
53847
+ }
53848
+ }
53849
+ if (personId) {
53850
+ if (participant.person?.personId !== personId) {
53851
+ return decorateResult({ result: { error: INVALID_PARTICIPANT } });
53852
+ }
53853
+ if (!participant.person.onlineResources)
53854
+ participant.person.onlineResources = [];
53855
+ participant.person.onlineResources.push(onlineResource);
53856
+ } else {
53857
+ if (!participant.onlineResources)
53858
+ participant.onlineResources = [];
53859
+ participant.onlineResources.push(onlineResource);
53860
+ }
53861
+ } else if (courtId) {
53862
+ const court = (tournamentRecord.venues ?? []).filter((v) => !venueId || v.venueId === venueId).flatMap(
53863
+ (v) => (v.courts ?? []).filter((c) => c.courtId === courtId)
53864
+ )?.[0];
53865
+ if (!court)
53866
+ return decorateResult({ result: { error: COURT_NOT_FOUND } });
53867
+ if (!court.onlineResources)
53868
+ court.onlineResources = [];
53869
+ court.onlineResources.push(onlineResource);
53870
+ } else if (venueId) {
53871
+ const venue = (tournamentRecord.venues ?? []).find(
53872
+ (v) => v.venueId === venueId
53873
+ );
53874
+ if (!venue)
53875
+ return decorateResult({ result: { error: VENUE_NOT_FOUND } });
53876
+ if (!venue.onlineResources)
53877
+ venue.onlineResources = [];
53878
+ venue.onlineResources.push(onlineResource);
53879
+ } else {
53880
+ if (!tournamentRecord.onlineResources)
53881
+ tournamentRecord.onlineResources = [];
53882
+ tournamentRecord.onlineResources.push(onlineResource);
53883
+ }
53810
53884
  return { ...SUCCESS };
53811
53885
  }
53812
53886