@opprs/db-prisma 2.2.1-canary.95863bb → 2.2.1-canary.9b82ab1

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.cjs CHANGED
@@ -21,30 +21,60 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  connect: () => connect,
24
+ countEntries: () => countEntries,
25
+ countLocations: () => countLocations,
26
+ countMatches: () => countMatches,
24
27
  countPlayers: () => countPlayers,
25
- countResults: () => countResults,
28
+ countRounds: () => countRounds,
29
+ countStandings: () => countStandings,
26
30
  countTournaments: () => countTournaments,
27
31
  countUsers: () => countUsers,
28
- createManyResults: () => createManyResults,
32
+ createEntry: () => createEntry,
33
+ createLocation: () => createLocation,
34
+ createManyEntries: () => createManyEntries,
35
+ createManyMatches: () => createManyMatches,
36
+ createManyRounds: () => createManyRounds,
37
+ createManyStandings: () => createManyStandings,
38
+ createMatch: () => createMatch,
29
39
  createPlayer: () => createPlayer,
30
- createResult: () => createResult,
40
+ createRound: () => createRound,
41
+ createStanding: () => createStanding,
31
42
  createTournament: () => createTournament,
32
43
  createUser: () => createUser,
33
44
  createUserWithPlayer: () => createUserWithPlayer,
45
+ deleteEntriesByMatch: () => deleteEntriesByMatch,
46
+ deleteEntry: () => deleteEntry,
47
+ deleteLocation: () => deleteLocation,
48
+ deleteMatch: () => deleteMatch,
49
+ deleteMatchesByRound: () => deleteMatchesByRound,
50
+ deleteMatchesByTournament: () => deleteMatchesByTournament,
34
51
  deletePlayer: () => deletePlayer,
35
- deleteResult: () => deleteResult,
36
- deleteResultsByTournament: () => deleteResultsByTournament,
52
+ deleteRound: () => deleteRound,
53
+ deleteRoundsByTournament: () => deleteRoundsByTournament,
54
+ deleteStanding: () => deleteStanding,
55
+ deleteStandingsByTournament: () => deleteStandingsByTournament,
37
56
  deleteTournament: () => deleteTournament,
38
57
  deleteUser: () => deleteUser,
39
58
  disconnect: () => disconnect,
59
+ findEntries: () => findEntries,
60
+ findEntryById: () => findEntryById,
61
+ findEntryByMatchAndPlayer: () => findEntryByMatchAndPlayer,
62
+ findLocationByExternalId: () => findLocationByExternalId,
63
+ findLocationById: () => findLocationById,
64
+ findLocations: () => findLocations,
65
+ findMatchById: () => findMatchById,
66
+ findMatches: () => findMatches,
40
67
  findPlayerByExternalId: () => findPlayerByExternalId,
41
68
  findPlayerById: () => findPlayerById,
42
69
  findPlayerByPlayerNumber: () => findPlayerByPlayerNumber,
43
70
  findPlayerByUserEmail: () => findPlayerByUserEmail,
44
71
  findPlayers: () => findPlayers,
45
- findResultById: () => findResultById,
46
- findResultByPlayerAndTournament: () => findResultByPlayerAndTournament,
47
- findResults: () => findResults,
72
+ findRoundById: () => findRoundById,
73
+ findRoundByTournamentAndNumber: () => findRoundByTournamentAndNumber,
74
+ findRounds: () => findRounds,
75
+ findStandingById: () => findStandingById,
76
+ findStandingByPlayerAndTournament: () => findStandingByPlayerAndTournament,
77
+ findStandings: () => findStandings,
48
78
  findTournamentByExternalId: () => findTournamentByExternalId,
49
79
  findTournamentById: () => findTournamentById,
50
80
  findTournaments: () => findTournaments,
@@ -52,17 +82,34 @@ __export(index_exports, {
52
82
  findUserById: () => findUserById,
53
83
  findUsers: () => findUsers,
54
84
  generateUniquePlayerNumber: () => generateUniquePlayerNumber,
85
+ getFinalsRounds: () => getFinalsRounds,
86
+ getFinalsStandings: () => getFinalsStandings,
87
+ getLocationWithTournaments: () => getLocationWithTournaments,
55
88
  getMajorTournaments: () => getMajorTournaments,
56
- getPlayerResults: () => getPlayerResults,
89
+ getMatchEntries: () => getMatchEntries,
90
+ getMatchWithEntries: () => getMatchWithEntries,
91
+ getMergedStandings: () => getMergedStandings,
92
+ getPlayerEntries: () => getPlayerEntries,
93
+ getPlayerEntryStats: () => getPlayerEntryStats,
94
+ getPlayerStandings: () => getPlayerStandings,
57
95
  getPlayerStats: () => getPlayerStats,
58
96
  getPlayerTopFinishes: () => getPlayerTopFinishes,
97
+ getPlayerTournamentEntries: () => getPlayerTournamentEntries,
98
+ getPlayerTournamentMatches: () => getPlayerTournamentMatches,
59
99
  getPlayerWithResults: () => getPlayerWithResults,
100
+ getQualifyingRounds: () => getQualifyingRounds,
101
+ getQualifyingStandings: () => getQualifyingStandings,
60
102
  getRatedPlayers: () => getRatedPlayers,
61
103
  getRecentTournaments: () => getRecentTournaments,
104
+ getRoundMatches: () => getRoundMatches,
105
+ getRoundWithMatches: () => getRoundWithMatches,
62
106
  getTopPlayersByRanking: () => getTopPlayersByRanking,
63
107
  getTopPlayersByRating: () => getTopPlayersByRating,
64
- getTournamentResults: () => getTournamentResults,
108
+ getTournamentMatches: () => getTournamentMatches,
109
+ getTournamentRounds: () => getTournamentRounds,
110
+ getTournamentStandings: () => getTournamentStandings,
65
111
  getTournamentStats: () => getTournamentStats,
112
+ getTournamentWithMatches: () => getTournamentWithMatches,
66
113
  getTournamentWithResults: () => getTournamentWithResults,
67
114
  getTournamentsByBoosterType: () => getTournamentsByBoosterType,
68
115
  getTournamentsByDateRange: () => getTournamentsByDateRange,
@@ -72,13 +119,18 @@ __export(index_exports, {
72
119
  linkPlayerToUser: () => linkPlayerToUser,
73
120
  prisma: () => prisma,
74
121
  recalculateTimeDecay: () => recalculateTimeDecay,
122
+ searchLocations: () => searchLocations,
75
123
  searchPlayers: () => searchPlayers,
76
124
  searchTournaments: () => searchTournaments,
77
125
  testConnection: () => testConnection,
126
+ updateEntry: () => updateEntry,
127
+ updateLocation: () => updateLocation,
128
+ updateMatch: () => updateMatch,
78
129
  updatePlayer: () => updatePlayer,
79
130
  updatePlayerRating: () => updatePlayerRating,
80
- updateResult: () => updateResult,
81
- updateResultPoints: () => updateResultPoints,
131
+ updateRound: () => updateRound,
132
+ updateStanding: () => updateStanding,
133
+ updateStandingPoints: () => updateStandingPoints,
82
134
  updateTournament: () => updateTournament,
83
135
  updateUser: () => updateUser,
84
136
  updateUserRefreshToken: () => updateUserRefreshToken
@@ -234,7 +286,7 @@ async function getPlayerWithResults(id) {
234
286
  const player = await prisma.player.findUnique({
235
287
  where: { id },
236
288
  include: {
237
- tournamentResults: {
289
+ standings: {
238
290
  include: {
239
291
  tournament: true
240
292
  },
@@ -251,7 +303,7 @@ async function getPlayerWithResults(id) {
251
303
  }
252
304
  return {
253
305
  ...player,
254
- results: player.tournamentResults
306
+ results: player.standings
255
307
  };
256
308
  }
257
309
  async function searchPlayers(query, limit = 20) {
@@ -342,13 +394,33 @@ async function getTournamentWithResults(id) {
342
394
  return prisma.tournament.findUnique({
343
395
  where: { id },
344
396
  include: {
345
- results: {
397
+ standings: {
346
398
  include: {
347
399
  player: true
348
400
  },
349
- orderBy: {
350
- position: "asc"
351
- }
401
+ orderBy: [{ isFinals: "desc" }, { position: "asc" }]
402
+ }
403
+ }
404
+ });
405
+ }
406
+ async function getTournamentWithMatches(id) {
407
+ return prisma.tournament.findUnique({
408
+ where: { id },
409
+ include: {
410
+ rounds: {
411
+ include: {
412
+ matches: {
413
+ include: {
414
+ entries: {
415
+ include: {
416
+ player: true
417
+ }
418
+ }
419
+ },
420
+ orderBy: { number: "asc" }
421
+ }
422
+ },
423
+ orderBy: [{ isFinals: "asc" }, { number: "asc" }]
352
424
  }
353
425
  }
354
426
  });
@@ -359,7 +431,7 @@ async function searchTournaments(query, limit = 20) {
359
431
  where: {
360
432
  OR: [
361
433
  { name: { contains: query, mode: "insensitive" } },
362
- { location: { contains: query, mode: "insensitive" } }
434
+ { location: { name: { contains: query, mode: "insensitive" } } }
363
435
  ]
364
436
  },
365
437
  orderBy: { date: "desc" }
@@ -370,7 +442,7 @@ async function getTournamentStats(id) {
370
442
  if (!tournament) {
371
443
  return null;
372
444
  }
373
- const playerCount = tournament.results.length;
445
+ const playerCount = tournament.standings.length;
374
446
  if (playerCount === 0) {
375
447
  return {
376
448
  tournament,
@@ -381,9 +453,9 @@ async function getTournamentStats(id) {
381
453
  lowestPoints: 0
382
454
  };
383
455
  }
384
- const totalPoints = tournament.results.reduce((sum, r) => sum + (r.totalPoints || 0), 0);
385
- const totalEfficiency = tournament.results.reduce((sum, r) => sum + (r.efficiency || 0), 0);
386
- const allPoints = tournament.results.map((r) => r.totalPoints || 0);
456
+ const totalPoints = tournament.standings.reduce((sum, s) => sum + (s.totalPoints || 0), 0);
457
+ const totalEfficiency = tournament.standings.reduce((sum, s) => sum + (s.efficiency || 0), 0);
458
+ const allPoints = tournament.standings.map((s) => s.totalPoints || 0);
387
459
  return {
388
460
  tournament,
389
461
  playerCount,
@@ -394,44 +466,364 @@ async function getTournamentStats(id) {
394
466
  };
395
467
  }
396
468
 
397
- // src/results.ts
398
- async function createResult(data) {
399
- const resultData = {
469
+ // src/rounds.ts
470
+ async function createRound(data) {
471
+ return prisma.round.create({
472
+ data: {
473
+ ...data,
474
+ isFinals: data.isFinals ?? false
475
+ }
476
+ });
477
+ }
478
+ async function createManyRounds(data) {
479
+ const roundsData = data.map((item) => ({
480
+ ...item,
481
+ isFinals: item.isFinals ?? false
482
+ }));
483
+ return prisma.round.createMany({
484
+ data: roundsData
485
+ });
486
+ }
487
+ async function findRoundById(id, include) {
488
+ return prisma.round.findUnique({
489
+ where: { id },
490
+ include
491
+ });
492
+ }
493
+ async function findRoundByTournamentAndNumber(tournamentId, number, isFinals, include) {
494
+ return prisma.round.findUnique({
495
+ where: {
496
+ tournamentId_number_isFinals: {
497
+ tournamentId,
498
+ number,
499
+ isFinals
500
+ }
501
+ },
502
+ include
503
+ });
504
+ }
505
+ async function findRounds(options = {}) {
506
+ return prisma.round.findMany({
507
+ take: options.take,
508
+ skip: options.skip,
509
+ where: options.where,
510
+ orderBy: options.orderBy,
511
+ include: options.include
512
+ });
513
+ }
514
+ async function getTournamentRounds(tournamentId, options = {}) {
515
+ return findRounds({
516
+ ...options,
517
+ where: { tournamentId },
518
+ orderBy: options.orderBy ?? [{ isFinals: "asc" }, { number: "asc" }]
519
+ });
520
+ }
521
+ async function getQualifyingRounds(tournamentId, options = {}) {
522
+ return findRounds({
523
+ ...options,
524
+ where: { tournamentId, isFinals: false },
525
+ orderBy: options.orderBy ?? { number: "asc" }
526
+ });
527
+ }
528
+ async function getFinalsRounds(tournamentId, options = {}) {
529
+ return findRounds({
530
+ ...options,
531
+ where: { tournamentId, isFinals: true },
532
+ orderBy: options.orderBy ?? { number: "asc" }
533
+ });
534
+ }
535
+ async function updateRound(id, data) {
536
+ return prisma.round.update({
537
+ where: { id },
538
+ data
539
+ });
540
+ }
541
+ async function deleteRound(id) {
542
+ return prisma.round.delete({
543
+ where: { id }
544
+ });
545
+ }
546
+ async function deleteRoundsByTournament(tournamentId) {
547
+ return prisma.round.deleteMany({
548
+ where: { tournamentId }
549
+ });
550
+ }
551
+ async function countRounds(where) {
552
+ return prisma.round.count({ where });
553
+ }
554
+ async function getRoundWithMatches(id) {
555
+ return prisma.round.findUnique({
556
+ where: { id },
557
+ include: {
558
+ matches: {
559
+ include: {
560
+ entries: {
561
+ include: {
562
+ player: true
563
+ }
564
+ }
565
+ },
566
+ orderBy: {
567
+ number: "asc"
568
+ }
569
+ }
570
+ }
571
+ });
572
+ }
573
+
574
+ // src/matches.ts
575
+ async function createMatch(data) {
576
+ return prisma.match.create({
577
+ data
578
+ });
579
+ }
580
+ async function createManyMatches(data) {
581
+ return prisma.match.createMany({
582
+ data
583
+ });
584
+ }
585
+ async function findMatchById(id, include) {
586
+ return prisma.match.findUnique({
587
+ where: { id },
588
+ include
589
+ });
590
+ }
591
+ async function findMatches(options = {}) {
592
+ return prisma.match.findMany({
593
+ take: options.take,
594
+ skip: options.skip,
595
+ where: options.where,
596
+ orderBy: options.orderBy,
597
+ include: options.include
598
+ });
599
+ }
600
+ async function getTournamentMatches(tournamentId, options = {}) {
601
+ return findMatches({
602
+ ...options,
603
+ where: { tournamentId },
604
+ orderBy: options.orderBy ?? { number: "asc" }
605
+ });
606
+ }
607
+ async function getRoundMatches(roundId, options = {}) {
608
+ return findMatches({
609
+ ...options,
610
+ where: { roundId },
611
+ orderBy: options.orderBy ?? { number: "asc" }
612
+ });
613
+ }
614
+ async function updateMatch(id, data) {
615
+ return prisma.match.update({
616
+ where: { id },
617
+ data
618
+ });
619
+ }
620
+ async function deleteMatch(id) {
621
+ return prisma.match.delete({
622
+ where: { id }
623
+ });
624
+ }
625
+ async function deleteMatchesByTournament(tournamentId) {
626
+ return prisma.match.deleteMany({
627
+ where: { tournamentId }
628
+ });
629
+ }
630
+ async function deleteMatchesByRound(roundId) {
631
+ return prisma.match.deleteMany({
632
+ where: { roundId }
633
+ });
634
+ }
635
+ async function countMatches(where) {
636
+ return prisma.match.count({ where });
637
+ }
638
+ async function getMatchWithEntries(id) {
639
+ return prisma.match.findUnique({
640
+ where: { id },
641
+ include: {
642
+ entries: {
643
+ include: {
644
+ player: true
645
+ },
646
+ orderBy: {
647
+ position: "asc"
648
+ }
649
+ },
650
+ round: true
651
+ }
652
+ });
653
+ }
654
+ async function getPlayerTournamentMatches(playerId, tournamentId, include) {
655
+ return findMatches({
656
+ where: {
657
+ tournamentId,
658
+ entries: {
659
+ some: {
660
+ playerId
661
+ }
662
+ }
663
+ },
664
+ include: include ?? {
665
+ entries: {
666
+ include: {
667
+ player: true
668
+ }
669
+ },
670
+ round: true
671
+ },
672
+ orderBy: [{ round: { number: "asc" } }, { number: "asc" }]
673
+ });
674
+ }
675
+
676
+ // src/entries.ts
677
+ async function createEntry(data) {
678
+ return prisma.entry.create({
679
+ data
680
+ });
681
+ }
682
+ async function createManyEntries(data) {
683
+ return prisma.entry.createMany({
684
+ data
685
+ });
686
+ }
687
+ async function findEntryById(id, include) {
688
+ return prisma.entry.findUnique({
689
+ where: { id },
690
+ include
691
+ });
692
+ }
693
+ async function findEntryByMatchAndPlayer(matchId, playerId, include) {
694
+ return prisma.entry.findUnique({
695
+ where: {
696
+ matchId_playerId: {
697
+ matchId,
698
+ playerId
699
+ }
700
+ },
701
+ include
702
+ });
703
+ }
704
+ async function findEntries(options = {}) {
705
+ return prisma.entry.findMany({
706
+ take: options.take,
707
+ skip: options.skip,
708
+ where: options.where,
709
+ orderBy: options.orderBy,
710
+ include: options.include
711
+ });
712
+ }
713
+ async function getMatchEntries(matchId, options = {}) {
714
+ return findEntries({
715
+ ...options,
716
+ where: { matchId },
717
+ include: options.include ?? { player: true },
718
+ orderBy: options.orderBy ?? { position: "asc" }
719
+ });
720
+ }
721
+ async function getPlayerEntries(playerId, options = {}) {
722
+ return findEntries({
723
+ ...options,
724
+ where: { playerId },
725
+ include: options.include ?? { match: { include: { round: true, tournament: true } } }
726
+ });
727
+ }
728
+ async function getPlayerTournamentEntries(playerId, tournamentId, include) {
729
+ return findEntries({
730
+ where: {
731
+ playerId,
732
+ match: {
733
+ tournamentId
734
+ }
735
+ },
736
+ include: include ?? {
737
+ match: {
738
+ include: {
739
+ round: true,
740
+ entries: {
741
+ include: {
742
+ player: true
743
+ }
744
+ }
745
+ }
746
+ }
747
+ }
748
+ });
749
+ }
750
+ async function updateEntry(id, data) {
751
+ return prisma.entry.update({
752
+ where: { id },
753
+ data
754
+ });
755
+ }
756
+ async function deleteEntry(id) {
757
+ return prisma.entry.delete({
758
+ where: { id }
759
+ });
760
+ }
761
+ async function deleteEntriesByMatch(matchId) {
762
+ return prisma.entry.deleteMany({
763
+ where: { matchId }
764
+ });
765
+ }
766
+ async function countEntries(where) {
767
+ return prisma.entry.count({ where });
768
+ }
769
+ async function getPlayerEntryStats(playerId) {
770
+ const entries = await getPlayerEntries(playerId);
771
+ if (entries.length === 0) {
772
+ return null;
773
+ }
774
+ const wins = entries.filter((e) => e.result === "WIN").length;
775
+ const losses = entries.filter((e) => e.result === "LOSS").length;
776
+ const ties = entries.filter((e) => e.result === "TIE").length;
777
+ return {
778
+ totalMatches: entries.length,
779
+ wins,
780
+ losses,
781
+ ties,
782
+ winRate: wins / entries.length
783
+ };
784
+ }
785
+
786
+ // src/standings.ts
787
+ async function createStanding(data) {
788
+ const standingData = {
400
789
  ...data,
790
+ isFinals: data.isFinals ?? false,
401
791
  decayedPoints: data.decayedPoints ?? data.totalPoints ?? 0
402
792
  };
403
- return prisma.tournamentResult.create({
404
- data: resultData
793
+ return prisma.standing.create({
794
+ data: standingData
405
795
  });
406
796
  }
407
- async function createManyResults(data) {
408
- const resultsData = data.map((item) => ({
797
+ async function createManyStandings(data) {
798
+ const standingsData = data.map((item) => ({
409
799
  ...item,
800
+ isFinals: item.isFinals ?? false,
410
801
  decayedPoints: item.decayedPoints ?? item.totalPoints ?? 0
411
802
  }));
412
- return prisma.tournamentResult.createMany({
413
- data: resultsData
803
+ return prisma.standing.createMany({
804
+ data: standingsData
414
805
  });
415
806
  }
416
- async function findResultById(id, include) {
417
- return prisma.tournamentResult.findUnique({
807
+ async function findStandingById(id, include) {
808
+ return prisma.standing.findUnique({
418
809
  where: { id },
419
810
  include
420
811
  });
421
812
  }
422
- async function findResultByPlayerAndTournament(playerId, tournamentId, include) {
423
- return prisma.tournamentResult.findUnique({
813
+ async function findStandingByPlayerAndTournament(playerId, tournamentId, isFinals, include) {
814
+ return prisma.standing.findUnique({
424
815
  where: {
425
- playerId_tournamentId: {
816
+ playerId_tournamentId_isFinals: {
426
817
  playerId,
427
- tournamentId
818
+ tournamentId,
819
+ isFinals
428
820
  }
429
821
  },
430
822
  include
431
823
  });
432
824
  }
433
- async function findResults(options = {}) {
434
- return prisma.tournamentResult.findMany({
825
+ async function findStandings(options = {}) {
826
+ return prisma.standing.findMany({
435
827
  take: options.take,
436
828
  skip: options.skip,
437
829
  where: options.where,
@@ -439,45 +831,85 @@ async function findResults(options = {}) {
439
831
  include: options.include
440
832
  });
441
833
  }
442
- async function getPlayerResults(playerId, options = {}) {
443
- return findResults({
834
+ async function getPlayerStandings(playerId, options = {}) {
835
+ return findStandings({
444
836
  ...options,
445
837
  where: { playerId },
446
838
  include: { tournament: true, ...options.include },
447
839
  orderBy: { tournament: { date: "desc" } }
448
840
  });
449
841
  }
450
- async function getTournamentResults(tournamentId, options = {}) {
451
- return findResults({
842
+ async function getTournamentStandings(tournamentId, options = {}) {
843
+ return findStandings({
452
844
  ...options,
453
845
  where: { tournamentId },
454
846
  include: { player: true, ...options.include },
455
- orderBy: { position: "asc" }
847
+ orderBy: options.orderBy ?? { position: "asc" }
848
+ });
849
+ }
850
+ async function getQualifyingStandings(tournamentId, options = {}) {
851
+ return findStandings({
852
+ ...options,
853
+ where: { tournamentId, isFinals: false },
854
+ include: { player: true, ...options.include },
855
+ orderBy: options.orderBy ?? { position: "asc" }
856
+ });
857
+ }
858
+ async function getFinalsStandings(tournamentId, options = {}) {
859
+ return findStandings({
860
+ ...options,
861
+ where: { tournamentId, isFinals: true },
862
+ include: { player: true, ...options.include },
863
+ orderBy: options.orderBy ?? { position: "asc" }
456
864
  });
457
865
  }
866
+ async function getMergedStandings(tournamentId) {
867
+ const [finals, qualifying] = await Promise.all([
868
+ findStandings({
869
+ where: { tournamentId, isFinals: true },
870
+ orderBy: { position: "asc" },
871
+ include: { player: true }
872
+ }),
873
+ findStandings({
874
+ where: { tournamentId, isFinals: false },
875
+ orderBy: { position: "asc" },
876
+ include: { player: true }
877
+ })
878
+ ]);
879
+ const finalistIds = new Set(finals.map((s) => s.playerId));
880
+ const nonFinalists = qualifying.filter((s) => !finalistIds.has(s.playerId));
881
+ return [
882
+ ...finals.map((s) => ({ ...s, mergedPosition: s.position, isFinalist: true })),
883
+ ...nonFinalists.map((s, i) => ({
884
+ ...s,
885
+ mergedPosition: finals.length + i + 1,
886
+ isFinalist: false
887
+ }))
888
+ ];
889
+ }
458
890
  async function getPlayerTopFinishes(playerId, limit = 15) {
459
- return findResults({
891
+ return findStandings({
460
892
  where: { playerId },
461
893
  take: limit,
462
894
  include: { tournament: true },
463
895
  orderBy: { decayedPoints: "desc" }
464
896
  });
465
897
  }
466
- async function updateResult(id, data) {
467
- return prisma.tournamentResult.update({
898
+ async function updateStanding(id, data) {
899
+ return prisma.standing.update({
468
900
  where: { id },
469
901
  data
470
902
  });
471
903
  }
472
- async function updateResultPoints(id, linearPoints, dynamicPoints, totalPoints) {
473
- const result = await findResultById(id, {
904
+ async function updateStandingPoints(id, linearPoints, dynamicPoints, totalPoints) {
905
+ const standing = await findStandingById(id, {
474
906
  tournament: true
475
907
  });
476
- if (!result) {
477
- throw new Error(`Result with id ${id} not found`);
908
+ if (!standing) {
909
+ throw new Error(`Standing with id ${id} not found`);
478
910
  }
479
911
  const now = /* @__PURE__ */ new Date();
480
- const tournamentDate = result.tournament.date;
912
+ const tournamentDate = standing.tournament.date;
481
913
  const ageInDays = Math.floor((now.getTime() - tournamentDate.getTime()) / (1e3 * 60 * 60 * 24));
482
914
  const ageInYears = ageInDays / 365;
483
915
  let decayMultiplier = 0;
@@ -491,7 +923,7 @@ async function updateResultPoints(id, linearPoints, dynamicPoints, totalPoints)
491
923
  decayMultiplier = 0;
492
924
  }
493
925
  const decayedPoints = totalPoints * decayMultiplier;
494
- return updateResult(id, {
926
+ return updateStanding(id, {
495
927
  linearPoints,
496
928
  dynamicPoints,
497
929
  totalPoints,
@@ -500,50 +932,50 @@ async function updateResultPoints(id, linearPoints, dynamicPoints, totalPoints)
500
932
  decayedPoints
501
933
  });
502
934
  }
503
- async function deleteResult(id) {
504
- return prisma.tournamentResult.delete({
935
+ async function deleteStanding(id) {
936
+ return prisma.standing.delete({
505
937
  where: { id }
506
938
  });
507
939
  }
508
- async function deleteResultsByTournament(tournamentId) {
509
- return prisma.tournamentResult.deleteMany({
940
+ async function deleteStandingsByTournament(tournamentId) {
941
+ return prisma.standing.deleteMany({
510
942
  where: { tournamentId }
511
943
  });
512
944
  }
513
- async function countResults(where) {
514
- return prisma.tournamentResult.count({ where });
945
+ async function countStandings(where) {
946
+ return prisma.standing.count({ where });
515
947
  }
516
948
  async function getPlayerStats(playerId) {
517
- const results = await getPlayerResults(playerId);
518
- if (results.length === 0) {
949
+ const standings = await getPlayerStandings(playerId);
950
+ if (standings.length === 0) {
519
951
  return null;
520
952
  }
521
- const totalPoints = results.reduce((sum, r) => sum + (r.totalPoints || 0), 0);
522
- const totalDecayedPoints = results.reduce((sum, r) => sum + (r.decayedPoints || 0), 0);
523
- const averagePosition = results.reduce((sum, r) => sum + r.position, 0) / results.length;
524
- const averageEfficiency = results.reduce((sum, r) => sum + (r.efficiency || 0), 0) / results.length;
525
- const firstPlaceFinishes = results.filter((r) => r.position === 1).length;
526
- const topThreeFinishes = results.filter((r) => r.position <= 3).length;
953
+ const totalPoints = standings.reduce((sum, s) => sum + (s.totalPoints || 0), 0);
954
+ const totalDecayedPoints = standings.reduce((sum, s) => sum + (s.decayedPoints || 0), 0);
955
+ const averagePosition = standings.reduce((sum, s) => sum + s.position, 0) / standings.length;
956
+ const averageEfficiency = standings.reduce((sum, s) => sum + (s.efficiency || 0), 0) / standings.length;
957
+ const firstPlaceFinishes = standings.filter((s) => s.position === 1).length;
958
+ const topThreeFinishes = standings.filter((s) => s.position <= 3).length;
527
959
  return {
528
- totalEvents: results.length,
960
+ totalEvents: standings.length,
529
961
  totalPoints,
530
962
  totalDecayedPoints,
531
- averagePoints: totalPoints / results.length,
963
+ averagePoints: totalPoints / standings.length,
532
964
  averagePosition,
533
965
  averageFinish: averagePosition,
534
966
  averageEfficiency,
535
967
  firstPlaceFinishes,
536
968
  topThreeFinishes,
537
- bestFinish: Math.min(...results.map((r) => r.position)),
538
- highestPoints: Math.max(...results.map((r) => r.totalPoints || 0))
969
+ bestFinish: Math.min(...standings.map((s) => s.position)),
970
+ highestPoints: Math.max(...standings.map((s) => s.totalPoints || 0))
539
971
  };
540
972
  }
541
973
  async function recalculateTimeDecay(referenceDate = /* @__PURE__ */ new Date()) {
542
- const results = await findResults({
974
+ const standings = await findStandings({
543
975
  include: { tournament: true }
544
976
  });
545
- const updates = results.map((result) => {
546
- const tournamentDate = result.tournament.date;
977
+ const updates = standings.map((standing) => {
978
+ const tournamentDate = standing.tournament.date;
547
979
  const ageInDays = Math.floor(
548
980
  (referenceDate.getTime() - tournamentDate.getTime()) / (1e3 * 60 * 60 * 24)
549
981
  );
@@ -558,9 +990,9 @@ async function recalculateTimeDecay(referenceDate = /* @__PURE__ */ new Date())
558
990
  } else {
559
991
  decayMultiplier = 0;
560
992
  }
561
- const decayedPoints = (result.totalPoints || 0) * decayMultiplier;
562
- return prisma.tournamentResult.update({
563
- where: { id: result.id },
993
+ const decayedPoints = (standing.totalPoints || 0) * decayMultiplier;
994
+ return prisma.standing.update({
995
+ where: { id: standing.id },
564
996
  data: {
565
997
  ageInDays,
566
998
  decayMultiplier,
@@ -743,33 +1175,129 @@ async function linkPlayerToUser(userId, playerId) {
743
1175
  return user;
744
1176
  });
745
1177
  }
1178
+
1179
+ // src/locations.ts
1180
+ async function createLocation(data) {
1181
+ return prisma.location.create({
1182
+ data
1183
+ });
1184
+ }
1185
+ async function findLocationById(id, include) {
1186
+ return prisma.location.findUnique({
1187
+ where: { id },
1188
+ include
1189
+ });
1190
+ }
1191
+ async function findLocationByExternalId(externalId, include) {
1192
+ return prisma.location.findUnique({
1193
+ where: { externalId },
1194
+ include
1195
+ });
1196
+ }
1197
+ async function findLocations(options = {}) {
1198
+ return prisma.location.findMany({
1199
+ take: options.take,
1200
+ skip: options.skip,
1201
+ where: options.where,
1202
+ orderBy: options.orderBy,
1203
+ include: options.include
1204
+ });
1205
+ }
1206
+ async function searchLocations(query, limit = 20) {
1207
+ return findLocations({
1208
+ take: limit,
1209
+ where: {
1210
+ OR: [
1211
+ { name: { contains: query, mode: "insensitive" } },
1212
+ { city: { contains: query, mode: "insensitive" } }
1213
+ ]
1214
+ },
1215
+ orderBy: { name: "asc" }
1216
+ });
1217
+ }
1218
+ async function updateLocation(id, data) {
1219
+ return prisma.location.update({
1220
+ where: { id },
1221
+ data
1222
+ });
1223
+ }
1224
+ async function deleteLocation(id) {
1225
+ return prisma.location.delete({
1226
+ where: { id }
1227
+ });
1228
+ }
1229
+ async function countLocations(where) {
1230
+ return prisma.location.count({ where });
1231
+ }
1232
+ async function getLocationWithTournaments(id) {
1233
+ return prisma.location.findUnique({
1234
+ where: { id },
1235
+ include: {
1236
+ tournaments: {
1237
+ orderBy: {
1238
+ date: "desc"
1239
+ }
1240
+ }
1241
+ }
1242
+ });
1243
+ }
746
1244
  // Annotate the CommonJS export names for ESM import in node:
747
1245
  0 && (module.exports = {
748
1246
  connect,
1247
+ countEntries,
1248
+ countLocations,
1249
+ countMatches,
749
1250
  countPlayers,
750
- countResults,
1251
+ countRounds,
1252
+ countStandings,
751
1253
  countTournaments,
752
1254
  countUsers,
753
- createManyResults,
1255
+ createEntry,
1256
+ createLocation,
1257
+ createManyEntries,
1258
+ createManyMatches,
1259
+ createManyRounds,
1260
+ createManyStandings,
1261
+ createMatch,
754
1262
  createPlayer,
755
- createResult,
1263
+ createRound,
1264
+ createStanding,
756
1265
  createTournament,
757
1266
  createUser,
758
1267
  createUserWithPlayer,
1268
+ deleteEntriesByMatch,
1269
+ deleteEntry,
1270
+ deleteLocation,
1271
+ deleteMatch,
1272
+ deleteMatchesByRound,
1273
+ deleteMatchesByTournament,
759
1274
  deletePlayer,
760
- deleteResult,
761
- deleteResultsByTournament,
1275
+ deleteRound,
1276
+ deleteRoundsByTournament,
1277
+ deleteStanding,
1278
+ deleteStandingsByTournament,
762
1279
  deleteTournament,
763
1280
  deleteUser,
764
1281
  disconnect,
1282
+ findEntries,
1283
+ findEntryById,
1284
+ findEntryByMatchAndPlayer,
1285
+ findLocationByExternalId,
1286
+ findLocationById,
1287
+ findLocations,
1288
+ findMatchById,
1289
+ findMatches,
765
1290
  findPlayerByExternalId,
766
1291
  findPlayerById,
767
1292
  findPlayerByPlayerNumber,
768
1293
  findPlayerByUserEmail,
769
1294
  findPlayers,
770
- findResultById,
771
- findResultByPlayerAndTournament,
772
- findResults,
1295
+ findRoundById,
1296
+ findRoundByTournamentAndNumber,
1297
+ findRounds,
1298
+ findStandingById,
1299
+ findStandingByPlayerAndTournament,
1300
+ findStandings,
773
1301
  findTournamentByExternalId,
774
1302
  findTournamentById,
775
1303
  findTournaments,
@@ -777,17 +1305,34 @@ async function linkPlayerToUser(userId, playerId) {
777
1305
  findUserById,
778
1306
  findUsers,
779
1307
  generateUniquePlayerNumber,
1308
+ getFinalsRounds,
1309
+ getFinalsStandings,
1310
+ getLocationWithTournaments,
780
1311
  getMajorTournaments,
781
- getPlayerResults,
1312
+ getMatchEntries,
1313
+ getMatchWithEntries,
1314
+ getMergedStandings,
1315
+ getPlayerEntries,
1316
+ getPlayerEntryStats,
1317
+ getPlayerStandings,
782
1318
  getPlayerStats,
783
1319
  getPlayerTopFinishes,
1320
+ getPlayerTournamentEntries,
1321
+ getPlayerTournamentMatches,
784
1322
  getPlayerWithResults,
1323
+ getQualifyingRounds,
1324
+ getQualifyingStandings,
785
1325
  getRatedPlayers,
786
1326
  getRecentTournaments,
1327
+ getRoundMatches,
1328
+ getRoundWithMatches,
787
1329
  getTopPlayersByRanking,
788
1330
  getTopPlayersByRating,
789
- getTournamentResults,
1331
+ getTournamentMatches,
1332
+ getTournamentRounds,
1333
+ getTournamentStandings,
790
1334
  getTournamentStats,
1335
+ getTournamentWithMatches,
791
1336
  getTournamentWithResults,
792
1337
  getTournamentsByBoosterType,
793
1338
  getTournamentsByDateRange,
@@ -797,13 +1342,18 @@ async function linkPlayerToUser(userId, playerId) {
797
1342
  linkPlayerToUser,
798
1343
  prisma,
799
1344
  recalculateTimeDecay,
1345
+ searchLocations,
800
1346
  searchPlayers,
801
1347
  searchTournaments,
802
1348
  testConnection,
1349
+ updateEntry,
1350
+ updateLocation,
1351
+ updateMatch,
803
1352
  updatePlayer,
804
1353
  updatePlayerRating,
805
- updateResult,
806
- updateResultPoints,
1354
+ updateRound,
1355
+ updateStanding,
1356
+ updateStandingPoints,
807
1357
  updateTournament,
808
1358
  updateUser,
809
1359
  updateUserRefreshToken