@opprs/db-prisma 2.2.1-canary.acb3229 → 2.2.1-canary.b943669

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,36 +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,
24
25
  countLocations: () => countLocations,
26
+ countMatches: () => countMatches,
25
27
  countPlayers: () => countPlayers,
26
- countResults: () => countResults,
28
+ countRounds: () => countRounds,
29
+ countStandings: () => countStandings,
27
30
  countTournaments: () => countTournaments,
28
31
  countUsers: () => countUsers,
32
+ createEntry: () => createEntry,
29
33
  createLocation: () => createLocation,
30
- createManyResults: () => createManyResults,
34
+ createManyEntries: () => createManyEntries,
35
+ createManyMatches: () => createManyMatches,
36
+ createManyRounds: () => createManyRounds,
37
+ createManyStandings: () => createManyStandings,
38
+ createMatch: () => createMatch,
31
39
  createPlayer: () => createPlayer,
32
- createResult: () => createResult,
40
+ createRound: () => createRound,
41
+ createStanding: () => createStanding,
33
42
  createTournament: () => createTournament,
34
43
  createUser: () => createUser,
35
44
  createUserWithPlayer: () => createUserWithPlayer,
45
+ deleteEntriesByMatch: () => deleteEntriesByMatch,
46
+ deleteEntry: () => deleteEntry,
36
47
  deleteLocation: () => deleteLocation,
48
+ deleteMatch: () => deleteMatch,
49
+ deleteMatchesByRound: () => deleteMatchesByRound,
50
+ deleteMatchesByTournament: () => deleteMatchesByTournament,
37
51
  deletePlayer: () => deletePlayer,
38
- deleteResult: () => deleteResult,
39
- deleteResultsByTournament: () => deleteResultsByTournament,
52
+ deleteRound: () => deleteRound,
53
+ deleteRoundsByTournament: () => deleteRoundsByTournament,
54
+ deleteStanding: () => deleteStanding,
55
+ deleteStandingsByTournament: () => deleteStandingsByTournament,
40
56
  deleteTournament: () => deleteTournament,
41
57
  deleteUser: () => deleteUser,
42
58
  disconnect: () => disconnect,
59
+ findEntries: () => findEntries,
60
+ findEntryById: () => findEntryById,
61
+ findEntryByMatchAndPlayer: () => findEntryByMatchAndPlayer,
43
62
  findLocationByExternalId: () => findLocationByExternalId,
44
63
  findLocationById: () => findLocationById,
45
64
  findLocations: () => findLocations,
65
+ findMatchById: () => findMatchById,
66
+ findMatches: () => findMatches,
46
67
  findPlayerByExternalId: () => findPlayerByExternalId,
47
68
  findPlayerById: () => findPlayerById,
48
69
  findPlayerByPlayerNumber: () => findPlayerByPlayerNumber,
49
70
  findPlayerByUserEmail: () => findPlayerByUserEmail,
50
71
  findPlayers: () => findPlayers,
51
- findResultById: () => findResultById,
52
- findResultByPlayerAndTournament: () => findResultByPlayerAndTournament,
53
- findResults: () => findResults,
72
+ findRoundById: () => findRoundById,
73
+ findRoundByTournamentAndNumber: () => findRoundByTournamentAndNumber,
74
+ findRounds: () => findRounds,
75
+ findStandingById: () => findStandingById,
76
+ findStandingByPlayerAndTournament: () => findStandingByPlayerAndTournament,
77
+ findStandings: () => findStandings,
54
78
  findTournamentByExternalId: () => findTournamentByExternalId,
55
79
  findTournamentById: () => findTournamentById,
56
80
  findTournaments: () => findTournaments,
@@ -58,18 +82,34 @@ __export(index_exports, {
58
82
  findUserById: () => findUserById,
59
83
  findUsers: () => findUsers,
60
84
  generateUniquePlayerNumber: () => generateUniquePlayerNumber,
85
+ getFinalsRounds: () => getFinalsRounds,
86
+ getFinalsStandings: () => getFinalsStandings,
61
87
  getLocationWithTournaments: () => getLocationWithTournaments,
62
88
  getMajorTournaments: () => getMajorTournaments,
63
- getPlayerResults: () => getPlayerResults,
89
+ getMatchEntries: () => getMatchEntries,
90
+ getMatchWithEntries: () => getMatchWithEntries,
91
+ getMergedStandings: () => getMergedStandings,
92
+ getPlayerEntries: () => getPlayerEntries,
93
+ getPlayerEntryStats: () => getPlayerEntryStats,
94
+ getPlayerStandings: () => getPlayerStandings,
64
95
  getPlayerStats: () => getPlayerStats,
65
96
  getPlayerTopFinishes: () => getPlayerTopFinishes,
97
+ getPlayerTournamentEntries: () => getPlayerTournamentEntries,
98
+ getPlayerTournamentMatches: () => getPlayerTournamentMatches,
66
99
  getPlayerWithResults: () => getPlayerWithResults,
100
+ getQualifyingRounds: () => getQualifyingRounds,
101
+ getQualifyingStandings: () => getQualifyingStandings,
67
102
  getRatedPlayers: () => getRatedPlayers,
68
103
  getRecentTournaments: () => getRecentTournaments,
104
+ getRoundMatches: () => getRoundMatches,
105
+ getRoundWithMatches: () => getRoundWithMatches,
69
106
  getTopPlayersByRanking: () => getTopPlayersByRanking,
70
107
  getTopPlayersByRating: () => getTopPlayersByRating,
71
- getTournamentResults: () => getTournamentResults,
108
+ getTournamentMatches: () => getTournamentMatches,
109
+ getTournamentRounds: () => getTournamentRounds,
110
+ getTournamentStandings: () => getTournamentStandings,
72
111
  getTournamentStats: () => getTournamentStats,
112
+ getTournamentWithMatches: () => getTournamentWithMatches,
73
113
  getTournamentWithResults: () => getTournamentWithResults,
74
114
  getTournamentsByBoosterType: () => getTournamentsByBoosterType,
75
115
  getTournamentsByDateRange: () => getTournamentsByDateRange,
@@ -83,11 +123,14 @@ __export(index_exports, {
83
123
  searchPlayers: () => searchPlayers,
84
124
  searchTournaments: () => searchTournaments,
85
125
  testConnection: () => testConnection,
126
+ updateEntry: () => updateEntry,
86
127
  updateLocation: () => updateLocation,
128
+ updateMatch: () => updateMatch,
87
129
  updatePlayer: () => updatePlayer,
88
130
  updatePlayerRating: () => updatePlayerRating,
89
- updateResult: () => updateResult,
90
- updateResultPoints: () => updateResultPoints,
131
+ updateRound: () => updateRound,
132
+ updateStanding: () => updateStanding,
133
+ updateStandingPoints: () => updateStandingPoints,
91
134
  updateTournament: () => updateTournament,
92
135
  updateUser: () => updateUser,
93
136
  updateUserRefreshToken: () => updateUserRefreshToken
@@ -243,7 +286,7 @@ async function getPlayerWithResults(id) {
243
286
  const player = await prisma.player.findUnique({
244
287
  where: { id },
245
288
  include: {
246
- tournamentResults: {
289
+ standings: {
247
290
  include: {
248
291
  tournament: true
249
292
  },
@@ -260,7 +303,7 @@ async function getPlayerWithResults(id) {
260
303
  }
261
304
  return {
262
305
  ...player,
263
- results: player.tournamentResults
306
+ results: player.standings
264
307
  };
265
308
  }
266
309
  async function searchPlayers(query, limit = 20) {
@@ -351,13 +394,33 @@ async function getTournamentWithResults(id) {
351
394
  return prisma.tournament.findUnique({
352
395
  where: { id },
353
396
  include: {
354
- results: {
397
+ standings: {
355
398
  include: {
356
399
  player: true
357
400
  },
358
- orderBy: {
359
- position: "asc"
360
- }
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" }]
361
424
  }
362
425
  }
363
426
  });
@@ -379,7 +442,7 @@ async function getTournamentStats(id) {
379
442
  if (!tournament) {
380
443
  return null;
381
444
  }
382
- const playerCount = tournament.results.length;
445
+ const playerCount = tournament.standings.length;
383
446
  if (playerCount === 0) {
384
447
  return {
385
448
  tournament,
@@ -390,9 +453,9 @@ async function getTournamentStats(id) {
390
453
  lowestPoints: 0
391
454
  };
392
455
  }
393
- const totalPoints = tournament.results.reduce((sum, r) => sum + (r.totalPoints || 0), 0);
394
- const totalEfficiency = tournament.results.reduce((sum, r) => sum + (r.efficiency || 0), 0);
395
- 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);
396
459
  return {
397
460
  tournament,
398
461
  playerCount,
@@ -403,44 +466,364 @@ async function getTournamentStats(id) {
403
466
  };
404
467
  }
405
468
 
406
- // src/results.ts
407
- async function createResult(data) {
408
- 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 = {
409
789
  ...data,
790
+ isFinals: data.isFinals ?? false,
410
791
  decayedPoints: data.decayedPoints ?? data.totalPoints ?? 0
411
792
  };
412
- return prisma.tournamentResult.create({
413
- data: resultData
793
+ return prisma.standing.create({
794
+ data: standingData
414
795
  });
415
796
  }
416
- async function createManyResults(data) {
417
- const resultsData = data.map((item) => ({
797
+ async function createManyStandings(data) {
798
+ const standingsData = data.map((item) => ({
418
799
  ...item,
800
+ isFinals: item.isFinals ?? false,
419
801
  decayedPoints: item.decayedPoints ?? item.totalPoints ?? 0
420
802
  }));
421
- return prisma.tournamentResult.createMany({
422
- data: resultsData
803
+ return prisma.standing.createMany({
804
+ data: standingsData
423
805
  });
424
806
  }
425
- async function findResultById(id, include) {
426
- return prisma.tournamentResult.findUnique({
807
+ async function findStandingById(id, include) {
808
+ return prisma.standing.findUnique({
427
809
  where: { id },
428
810
  include
429
811
  });
430
812
  }
431
- async function findResultByPlayerAndTournament(playerId, tournamentId, include) {
432
- return prisma.tournamentResult.findUnique({
813
+ async function findStandingByPlayerAndTournament(playerId, tournamentId, isFinals, include) {
814
+ return prisma.standing.findUnique({
433
815
  where: {
434
- playerId_tournamentId: {
816
+ playerId_tournamentId_isFinals: {
435
817
  playerId,
436
- tournamentId
818
+ tournamentId,
819
+ isFinals
437
820
  }
438
821
  },
439
822
  include
440
823
  });
441
824
  }
442
- async function findResults(options = {}) {
443
- return prisma.tournamentResult.findMany({
825
+ async function findStandings(options = {}) {
826
+ return prisma.standing.findMany({
444
827
  take: options.take,
445
828
  skip: options.skip,
446
829
  where: options.where,
@@ -448,45 +831,85 @@ async function findResults(options = {}) {
448
831
  include: options.include
449
832
  });
450
833
  }
451
- async function getPlayerResults(playerId, options = {}) {
452
- return findResults({
834
+ async function getPlayerStandings(playerId, options = {}) {
835
+ return findStandings({
453
836
  ...options,
454
837
  where: { playerId },
455
838
  include: { tournament: true, ...options.include },
456
839
  orderBy: { tournament: { date: "desc" } }
457
840
  });
458
841
  }
459
- async function getTournamentResults(tournamentId, options = {}) {
460
- return findResults({
842
+ async function getTournamentStandings(tournamentId, options = {}) {
843
+ return findStandings({
461
844
  ...options,
462
845
  where: { tournamentId },
463
846
  include: { player: true, ...options.include },
464
- 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" }
465
864
  });
466
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
+ }
467
890
  async function getPlayerTopFinishes(playerId, limit = 15) {
468
- return findResults({
891
+ return findStandings({
469
892
  where: { playerId },
470
893
  take: limit,
471
894
  include: { tournament: true },
472
895
  orderBy: { decayedPoints: "desc" }
473
896
  });
474
897
  }
475
- async function updateResult(id, data) {
476
- return prisma.tournamentResult.update({
898
+ async function updateStanding(id, data) {
899
+ return prisma.standing.update({
477
900
  where: { id },
478
901
  data
479
902
  });
480
903
  }
481
- async function updateResultPoints(id, linearPoints, dynamicPoints, totalPoints) {
482
- const result = await findResultById(id, {
904
+ async function updateStandingPoints(id, linearPoints, dynamicPoints, totalPoints) {
905
+ const standing = await findStandingById(id, {
483
906
  tournament: true
484
907
  });
485
- if (!result) {
486
- throw new Error(`Result with id ${id} not found`);
908
+ if (!standing) {
909
+ throw new Error(`Standing with id ${id} not found`);
487
910
  }
488
911
  const now = /* @__PURE__ */ new Date();
489
- const tournamentDate = result.tournament.date;
912
+ const tournamentDate = standing.tournament.date;
490
913
  const ageInDays = Math.floor((now.getTime() - tournamentDate.getTime()) / (1e3 * 60 * 60 * 24));
491
914
  const ageInYears = ageInDays / 365;
492
915
  let decayMultiplier = 0;
@@ -500,7 +923,7 @@ async function updateResultPoints(id, linearPoints, dynamicPoints, totalPoints)
500
923
  decayMultiplier = 0;
501
924
  }
502
925
  const decayedPoints = totalPoints * decayMultiplier;
503
- return updateResult(id, {
926
+ return updateStanding(id, {
504
927
  linearPoints,
505
928
  dynamicPoints,
506
929
  totalPoints,
@@ -509,50 +932,50 @@ async function updateResultPoints(id, linearPoints, dynamicPoints, totalPoints)
509
932
  decayedPoints
510
933
  });
511
934
  }
512
- async function deleteResult(id) {
513
- return prisma.tournamentResult.delete({
935
+ async function deleteStanding(id) {
936
+ return prisma.standing.delete({
514
937
  where: { id }
515
938
  });
516
939
  }
517
- async function deleteResultsByTournament(tournamentId) {
518
- return prisma.tournamentResult.deleteMany({
940
+ async function deleteStandingsByTournament(tournamentId) {
941
+ return prisma.standing.deleteMany({
519
942
  where: { tournamentId }
520
943
  });
521
944
  }
522
- async function countResults(where) {
523
- return prisma.tournamentResult.count({ where });
945
+ async function countStandings(where) {
946
+ return prisma.standing.count({ where });
524
947
  }
525
948
  async function getPlayerStats(playerId) {
526
- const results = await getPlayerResults(playerId);
527
- if (results.length === 0) {
949
+ const standings = await getPlayerStandings(playerId);
950
+ if (standings.length === 0) {
528
951
  return null;
529
952
  }
530
- const totalPoints = results.reduce((sum, r) => sum + (r.totalPoints || 0), 0);
531
- const totalDecayedPoints = results.reduce((sum, r) => sum + (r.decayedPoints || 0), 0);
532
- const averagePosition = results.reduce((sum, r) => sum + r.position, 0) / results.length;
533
- const averageEfficiency = results.reduce((sum, r) => sum + (r.efficiency || 0), 0) / results.length;
534
- const firstPlaceFinishes = results.filter((r) => r.position === 1).length;
535
- 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;
536
959
  return {
537
- totalEvents: results.length,
960
+ totalEvents: standings.length,
538
961
  totalPoints,
539
962
  totalDecayedPoints,
540
- averagePoints: totalPoints / results.length,
963
+ averagePoints: totalPoints / standings.length,
541
964
  averagePosition,
542
965
  averageFinish: averagePosition,
543
966
  averageEfficiency,
544
967
  firstPlaceFinishes,
545
968
  topThreeFinishes,
546
- bestFinish: Math.min(...results.map((r) => r.position)),
547
- 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))
548
971
  };
549
972
  }
550
973
  async function recalculateTimeDecay(referenceDate = /* @__PURE__ */ new Date()) {
551
- const results = await findResults({
974
+ const standings = await findStandings({
552
975
  include: { tournament: true }
553
976
  });
554
- const updates = results.map((result) => {
555
- const tournamentDate = result.tournament.date;
977
+ const updates = standings.map((standing) => {
978
+ const tournamentDate = standing.tournament.date;
556
979
  const ageInDays = Math.floor(
557
980
  (referenceDate.getTime() - tournamentDate.getTime()) / (1e3 * 60 * 60 * 24)
558
981
  );
@@ -567,9 +990,9 @@ async function recalculateTimeDecay(referenceDate = /* @__PURE__ */ new Date())
567
990
  } else {
568
991
  decayMultiplier = 0;
569
992
  }
570
- const decayedPoints = (result.totalPoints || 0) * decayMultiplier;
571
- return prisma.tournamentResult.update({
572
- where: { id: result.id },
993
+ const decayedPoints = (standing.totalPoints || 0) * decayMultiplier;
994
+ return prisma.standing.update({
995
+ where: { id: standing.id },
573
996
  data: {
574
997
  ageInDays,
575
998
  decayMultiplier,
@@ -821,36 +1244,60 @@ async function getLocationWithTournaments(id) {
821
1244
  // Annotate the CommonJS export names for ESM import in node:
822
1245
  0 && (module.exports = {
823
1246
  connect,
1247
+ countEntries,
824
1248
  countLocations,
1249
+ countMatches,
825
1250
  countPlayers,
826
- countResults,
1251
+ countRounds,
1252
+ countStandings,
827
1253
  countTournaments,
828
1254
  countUsers,
1255
+ createEntry,
829
1256
  createLocation,
830
- createManyResults,
1257
+ createManyEntries,
1258
+ createManyMatches,
1259
+ createManyRounds,
1260
+ createManyStandings,
1261
+ createMatch,
831
1262
  createPlayer,
832
- createResult,
1263
+ createRound,
1264
+ createStanding,
833
1265
  createTournament,
834
1266
  createUser,
835
1267
  createUserWithPlayer,
1268
+ deleteEntriesByMatch,
1269
+ deleteEntry,
836
1270
  deleteLocation,
1271
+ deleteMatch,
1272
+ deleteMatchesByRound,
1273
+ deleteMatchesByTournament,
837
1274
  deletePlayer,
838
- deleteResult,
839
- deleteResultsByTournament,
1275
+ deleteRound,
1276
+ deleteRoundsByTournament,
1277
+ deleteStanding,
1278
+ deleteStandingsByTournament,
840
1279
  deleteTournament,
841
1280
  deleteUser,
842
1281
  disconnect,
1282
+ findEntries,
1283
+ findEntryById,
1284
+ findEntryByMatchAndPlayer,
843
1285
  findLocationByExternalId,
844
1286
  findLocationById,
845
1287
  findLocations,
1288
+ findMatchById,
1289
+ findMatches,
846
1290
  findPlayerByExternalId,
847
1291
  findPlayerById,
848
1292
  findPlayerByPlayerNumber,
849
1293
  findPlayerByUserEmail,
850
1294
  findPlayers,
851
- findResultById,
852
- findResultByPlayerAndTournament,
853
- findResults,
1295
+ findRoundById,
1296
+ findRoundByTournamentAndNumber,
1297
+ findRounds,
1298
+ findStandingById,
1299
+ findStandingByPlayerAndTournament,
1300
+ findStandings,
854
1301
  findTournamentByExternalId,
855
1302
  findTournamentById,
856
1303
  findTournaments,
@@ -858,18 +1305,34 @@ async function getLocationWithTournaments(id) {
858
1305
  findUserById,
859
1306
  findUsers,
860
1307
  generateUniquePlayerNumber,
1308
+ getFinalsRounds,
1309
+ getFinalsStandings,
861
1310
  getLocationWithTournaments,
862
1311
  getMajorTournaments,
863
- getPlayerResults,
1312
+ getMatchEntries,
1313
+ getMatchWithEntries,
1314
+ getMergedStandings,
1315
+ getPlayerEntries,
1316
+ getPlayerEntryStats,
1317
+ getPlayerStandings,
864
1318
  getPlayerStats,
865
1319
  getPlayerTopFinishes,
1320
+ getPlayerTournamentEntries,
1321
+ getPlayerTournamentMatches,
866
1322
  getPlayerWithResults,
1323
+ getQualifyingRounds,
1324
+ getQualifyingStandings,
867
1325
  getRatedPlayers,
868
1326
  getRecentTournaments,
1327
+ getRoundMatches,
1328
+ getRoundWithMatches,
869
1329
  getTopPlayersByRanking,
870
1330
  getTopPlayersByRating,
871
- getTournamentResults,
1331
+ getTournamentMatches,
1332
+ getTournamentRounds,
1333
+ getTournamentStandings,
872
1334
  getTournamentStats,
1335
+ getTournamentWithMatches,
873
1336
  getTournamentWithResults,
874
1337
  getTournamentsByBoosterType,
875
1338
  getTournamentsByDateRange,
@@ -883,11 +1346,14 @@ async function getLocationWithTournaments(id) {
883
1346
  searchPlayers,
884
1347
  searchTournaments,
885
1348
  testConnection,
1349
+ updateEntry,
886
1350
  updateLocation,
1351
+ updateMatch,
887
1352
  updatePlayer,
888
1353
  updatePlayerRating,
889
- updateResult,
890
- updateResultPoints,
1354
+ updateRound,
1355
+ updateStanding,
1356
+ updateStandingPoints,
891
1357
  updateTournament,
892
1358
  updateUser,
893
1359
  updateUserRefreshToken