@opprs/db-prisma 2.2.1-canary.840995 → 2.2.1-canary.9b5fc07

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,22 +21,28 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
23
  connect: () => connect,
24
+ countLocations: () => countLocations,
24
25
  countPlayers: () => countPlayers,
25
26
  countResults: () => countResults,
26
27
  countTournaments: () => countTournaments,
27
28
  countUsers: () => countUsers,
29
+ createLocation: () => createLocation,
28
30
  createManyResults: () => createManyResults,
29
31
  createPlayer: () => createPlayer,
30
32
  createResult: () => createResult,
31
33
  createTournament: () => createTournament,
32
34
  createUser: () => createUser,
33
35
  createUserWithPlayer: () => createUserWithPlayer,
36
+ deleteLocation: () => deleteLocation,
34
37
  deletePlayer: () => deletePlayer,
35
38
  deleteResult: () => deleteResult,
36
39
  deleteResultsByTournament: () => deleteResultsByTournament,
37
40
  deleteTournament: () => deleteTournament,
38
41
  deleteUser: () => deleteUser,
39
42
  disconnect: () => disconnect,
43
+ findLocationByExternalId: () => findLocationByExternalId,
44
+ findLocationById: () => findLocationById,
45
+ findLocations: () => findLocations,
40
46
  findPlayerByExternalId: () => findPlayerByExternalId,
41
47
  findPlayerById: () => findPlayerById,
42
48
  findPlayerByPlayerNumber: () => findPlayerByPlayerNumber,
@@ -52,6 +58,7 @@ __export(index_exports, {
52
58
  findUserById: () => findUserById,
53
59
  findUsers: () => findUsers,
54
60
  generateUniquePlayerNumber: () => generateUniquePlayerNumber,
61
+ getLocationWithTournaments: () => getLocationWithTournaments,
55
62
  getMajorTournaments: () => getMajorTournaments,
56
63
  getPlayerResults: () => getPlayerResults,
57
64
  getPlayerStats: () => getPlayerStats,
@@ -72,9 +79,11 @@ __export(index_exports, {
72
79
  linkPlayerToUser: () => linkPlayerToUser,
73
80
  prisma: () => prisma,
74
81
  recalculateTimeDecay: () => recalculateTimeDecay,
82
+ searchLocations: () => searchLocations,
75
83
  searchPlayers: () => searchPlayers,
76
84
  searchTournaments: () => searchTournaments,
77
85
  testConnection: () => testConnection,
86
+ updateLocation: () => updateLocation,
78
87
  updatePlayer: () => updatePlayer,
79
88
  updatePlayerRating: () => updatePlayerRating,
80
89
  updateResult: () => updateResult,
@@ -359,7 +368,7 @@ async function searchTournaments(query, limit = 20) {
359
368
  where: {
360
369
  OR: [
361
370
  { name: { contains: query, mode: "insensitive" } },
362
- { location: { contains: query, mode: "insensitive" } }
371
+ { location: { name: { contains: query, mode: "insensitive" } } }
363
372
  ]
364
373
  },
365
374
  orderBy: { date: "desc" }
@@ -743,25 +752,97 @@ async function linkPlayerToUser(userId, playerId) {
743
752
  return user;
744
753
  });
745
754
  }
755
+
756
+ // src/locations.ts
757
+ async function createLocation(data) {
758
+ return prisma.location.create({
759
+ data
760
+ });
761
+ }
762
+ async function findLocationById(id, include) {
763
+ return prisma.location.findUnique({
764
+ where: { id },
765
+ include
766
+ });
767
+ }
768
+ async function findLocationByExternalId(externalId, include) {
769
+ return prisma.location.findUnique({
770
+ where: { externalId },
771
+ include
772
+ });
773
+ }
774
+ async function findLocations(options = {}) {
775
+ return prisma.location.findMany({
776
+ take: options.take,
777
+ skip: options.skip,
778
+ where: options.where,
779
+ orderBy: options.orderBy,
780
+ include: options.include
781
+ });
782
+ }
783
+ async function searchLocations(query, limit = 20) {
784
+ return findLocations({
785
+ take: limit,
786
+ where: {
787
+ OR: [
788
+ { name: { contains: query, mode: "insensitive" } },
789
+ { city: { contains: query, mode: "insensitive" } }
790
+ ]
791
+ },
792
+ orderBy: { name: "asc" }
793
+ });
794
+ }
795
+ async function updateLocation(id, data) {
796
+ return prisma.location.update({
797
+ where: { id },
798
+ data
799
+ });
800
+ }
801
+ async function deleteLocation(id) {
802
+ return prisma.location.delete({
803
+ where: { id }
804
+ });
805
+ }
806
+ async function countLocations(where) {
807
+ return prisma.location.count({ where });
808
+ }
809
+ async function getLocationWithTournaments(id) {
810
+ return prisma.location.findUnique({
811
+ where: { id },
812
+ include: {
813
+ tournaments: {
814
+ orderBy: {
815
+ date: "desc"
816
+ }
817
+ }
818
+ }
819
+ });
820
+ }
746
821
  // Annotate the CommonJS export names for ESM import in node:
747
822
  0 && (module.exports = {
748
823
  connect,
824
+ countLocations,
749
825
  countPlayers,
750
826
  countResults,
751
827
  countTournaments,
752
828
  countUsers,
829
+ createLocation,
753
830
  createManyResults,
754
831
  createPlayer,
755
832
  createResult,
756
833
  createTournament,
757
834
  createUser,
758
835
  createUserWithPlayer,
836
+ deleteLocation,
759
837
  deletePlayer,
760
838
  deleteResult,
761
839
  deleteResultsByTournament,
762
840
  deleteTournament,
763
841
  deleteUser,
764
842
  disconnect,
843
+ findLocationByExternalId,
844
+ findLocationById,
845
+ findLocations,
765
846
  findPlayerByExternalId,
766
847
  findPlayerById,
767
848
  findPlayerByPlayerNumber,
@@ -777,6 +858,7 @@ async function linkPlayerToUser(userId, playerId) {
777
858
  findUserById,
778
859
  findUsers,
779
860
  generateUniquePlayerNumber,
861
+ getLocationWithTournaments,
780
862
  getMajorTournaments,
781
863
  getPlayerResults,
782
864
  getPlayerStats,
@@ -797,9 +879,11 @@ async function linkPlayerToUser(userId, playerId) {
797
879
  linkPlayerToUser,
798
880
  prisma,
799
881
  recalculateTimeDecay,
882
+ searchLocations,
800
883
  searchPlayers,
801
884
  searchTournaments,
802
885
  testConnection,
886
+ updateLocation,
803
887
  updatePlayer,
804
888
  updatePlayerRating,
805
889
  updateResult,
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _prisma_client_runtime_library from '@prisma/client/runtime/library';
2
2
  import * as _prisma_client from '@prisma/client';
3
- import { PrismaClient, Player, Prisma, EventBoosterType, Tournament, TournamentResult, User } from '@prisma/client';
4
- export { EventBoosterType, Player, Prisma, Role, Tournament, TournamentResult, User } from '@prisma/client';
3
+ import { PrismaClient, Player, Prisma, EventBoosterType, Tournament, TournamentResult, User, Location } from '@prisma/client';
4
+ export { EventBoosterType, Location, Player, Prisma, Role, Tournament, TournamentResult, User } from '@prisma/client';
5
5
 
6
6
  declare const prisma: PrismaClient<_prisma_client.Prisma.PrismaClientOptions, never, _prisma_client_runtime_library.DefaultArgs>;
7
7
  /**
@@ -119,8 +119,10 @@ declare function getPlayerWithResults(id: string): Promise<{
119
119
  createdAt: Date;
120
120
  updatedAt: Date;
121
121
  externalId: string | null;
122
- location: string | null;
122
+ description: string | null;
123
123
  date: Date;
124
+ locationId: string | null;
125
+ organizerId: string | null;
124
126
  tgpConfig: Prisma.JsonValue | null;
125
127
  eventBooster: _prisma_client.$Enums.EventBoosterType;
126
128
  allowsOptOut: boolean;
@@ -155,8 +157,10 @@ declare function getPlayerWithResults(id: string): Promise<{
155
157
  createdAt: Date;
156
158
  updatedAt: Date;
157
159
  externalId: string | null;
158
- location: string | null;
160
+ description: string | null;
159
161
  date: Date;
162
+ locationId: string | null;
163
+ organizerId: string | null;
160
164
  tgpConfig: Prisma.JsonValue | null;
161
165
  eventBooster: _prisma_client.$Enums.EventBoosterType;
162
166
  allowsOptOut: boolean;
@@ -221,8 +225,10 @@ declare function isValidPlayerNumber(playerNumber: number): boolean;
221
225
  interface CreateTournamentInput {
222
226
  externalId?: string;
223
227
  name: string;
224
- location?: string;
228
+ description?: string;
225
229
  date: Date;
230
+ locationId?: string;
231
+ organizerId?: string;
226
232
  tgpConfig?: Prisma.InputJsonValue;
227
233
  eventBooster?: EventBoosterType;
228
234
  allowsOptOut?: boolean;
@@ -239,8 +245,10 @@ interface CreateTournamentInput {
239
245
  */
240
246
  interface UpdateTournamentInput {
241
247
  name?: string;
242
- location?: string;
248
+ description?: string | null;
243
249
  date?: Date;
250
+ locationId?: string | null;
251
+ organizerId?: string | null;
244
252
  tgpConfig?: Prisma.InputJsonValue;
245
253
  eventBooster?: EventBoosterType;
246
254
  allowsOptOut?: boolean;
@@ -348,8 +356,10 @@ declare function getTournamentWithResults(id: string): Promise<({
348
356
  createdAt: Date;
349
357
  updatedAt: Date;
350
358
  externalId: string | null;
351
- location: string | null;
359
+ description: string | null;
352
360
  date: Date;
361
+ locationId: string | null;
362
+ organizerId: string | null;
353
363
  tgpConfig: Prisma.JsonValue | null;
354
364
  eventBooster: _prisma_client.$Enums.EventBoosterType;
355
365
  allowsOptOut: boolean;
@@ -362,7 +372,7 @@ declare function getTournamentWithResults(id: string): Promise<({
362
372
  firstPlaceValue: number | null;
363
373
  }) | null>;
364
374
  /**
365
- * Searches tournaments by name or location
375
+ * Searches tournaments by name or location name
366
376
  */
367
377
  declare function searchTournaments(query: string, limit?: number): Promise<Tournament[]>;
368
378
  /**
@@ -408,8 +418,10 @@ declare function getTournamentStats(id: string): Promise<{
408
418
  createdAt: Date;
409
419
  updatedAt: Date;
410
420
  externalId: string | null;
411
- location: string | null;
421
+ description: string | null;
412
422
  date: Date;
423
+ locationId: string | null;
424
+ organizerId: string | null;
413
425
  tgpConfig: Prisma.JsonValue | null;
414
426
  eventBooster: _prisma_client.$Enums.EventBoosterType;
415
427
  allowsOptOut: boolean;
@@ -569,6 +581,9 @@ interface CreateUserInput {
569
581
  passwordHash: string;
570
582
  playerId?: string;
571
583
  role?: 'USER' | 'ADMIN';
584
+ tosAcceptedAt?: Date;
585
+ privacyPolicyAcceptedAt?: Date;
586
+ codeOfConductAcceptedAt?: Date;
572
587
  }
573
588
  /**
574
589
  * Input for updating a user
@@ -589,6 +604,9 @@ interface UserWithPlayer {
589
604
  role: 'USER' | 'ADMIN';
590
605
  createdAt: Date;
591
606
  updatedAt: Date;
607
+ tosAcceptedAt: Date | null;
608
+ privacyPolicyAcceptedAt: Date | null;
609
+ codeOfConductAcceptedAt: Date | null;
592
610
  player: {
593
611
  id: string;
594
612
  playerNumber: number;
@@ -662,6 +680,106 @@ declare function findUsers(params: {
662
680
  */
663
681
  declare function linkPlayerToUser(userId: string, playerId: string | null): Promise<UserWithPlayer>;
664
682
 
683
+ /**
684
+ * Input for creating a new location
685
+ */
686
+ interface CreateLocationInput {
687
+ externalId?: string;
688
+ name: string;
689
+ address?: string;
690
+ city?: string;
691
+ state?: string;
692
+ country?: string;
693
+ }
694
+ /**
695
+ * Input for updating a location
696
+ */
697
+ interface UpdateLocationInput {
698
+ name?: string;
699
+ address?: string | null;
700
+ city?: string | null;
701
+ state?: string | null;
702
+ country?: string | null;
703
+ }
704
+ /**
705
+ * Options for querying locations
706
+ */
707
+ interface FindLocationsOptions {
708
+ take?: number;
709
+ skip?: number;
710
+ orderBy?: Prisma.LocationOrderByWithRelationInput;
711
+ where?: Prisma.LocationWhereInput;
712
+ include?: Prisma.LocationInclude;
713
+ }
714
+ /**
715
+ * Creates a new location
716
+ */
717
+ declare function createLocation(data: CreateLocationInput): Promise<Location>;
718
+ /**
719
+ * Finds a location by ID
720
+ */
721
+ declare function findLocationById(id: string, include?: Prisma.LocationInclude): Promise<Location | null>;
722
+ /**
723
+ * Finds a location by external ID
724
+ */
725
+ declare function findLocationByExternalId(externalId: string, include?: Prisma.LocationInclude): Promise<Location | null>;
726
+ /**
727
+ * Finds multiple locations with optional filters
728
+ */
729
+ declare function findLocations(options?: FindLocationsOptions): Promise<Location[]>;
730
+ /**
731
+ * Searches locations by name or city
732
+ */
733
+ declare function searchLocations(query: string, limit?: number): Promise<Location[]>;
734
+ /**
735
+ * Updates a location
736
+ */
737
+ declare function updateLocation(id: string, data: UpdateLocationInput): Promise<Location>;
738
+ /**
739
+ * Deletes a location
740
+ */
741
+ declare function deleteLocation(id: string): Promise<Location>;
742
+ /**
743
+ * Counts total locations
744
+ */
745
+ declare function countLocations(where?: Prisma.LocationWhereInput): Promise<number>;
746
+ /**
747
+ * Gets location with its tournaments
748
+ */
749
+ declare function getLocationWithTournaments(id: string): Promise<({
750
+ tournaments: {
751
+ name: string;
752
+ id: string;
753
+ createdAt: Date;
754
+ updatedAt: Date;
755
+ externalId: string | null;
756
+ description: string | null;
757
+ date: Date;
758
+ locationId: string | null;
759
+ organizerId: string | null;
760
+ tgpConfig: Prisma.JsonValue | null;
761
+ eventBooster: _prisma_client.$Enums.EventBoosterType;
762
+ allowsOptOut: boolean;
763
+ baseValue: number | null;
764
+ tvaRating: number | null;
765
+ tvaRanking: number | null;
766
+ totalTVA: number | null;
767
+ tgp: number | null;
768
+ eventBoosterMultiplier: number | null;
769
+ firstPlaceValue: number | null;
770
+ }[];
771
+ } & {
772
+ name: string;
773
+ id: string;
774
+ createdAt: Date;
775
+ updatedAt: Date;
776
+ externalId: string | null;
777
+ address: string | null;
778
+ city: string | null;
779
+ state: string | null;
780
+ country: string | null;
781
+ }) | null>;
782
+
665
783
  /**
666
784
  * Re-export Prisma generated types
667
785
  */
@@ -721,4 +839,4 @@ interface ConnectionStatus {
721
839
  error?: string;
722
840
  }
723
841
 
724
- export { type ConnectionStatus, type CreatePlayerInput, type CreateResultInput, type CreateTournamentInput, type CreateUserInput, type FindPlayersOptions, type FindResultsOptions, type FindTournamentsOptions, type PlayerStatistics, type PlayerWithResults, type TournamentResultWithTournament, type TournamentStatistics, type UpdatePlayerInput, type UpdateResultInput, type UpdateTournamentInput, type UpdateUserInput, type UserWithPlayer, connect, countPlayers, countResults, countTournaments, countUsers, createManyResults, createPlayer, createResult, createTournament, createUser, createUserWithPlayer, deletePlayer, deleteResult, deleteResultsByTournament, deleteTournament, deleteUser, disconnect, findPlayerByExternalId, findPlayerById, findPlayerByPlayerNumber, findPlayerByUserEmail, findPlayers, findResultById, findResultByPlayerAndTournament, findResults, findTournamentByExternalId, findTournamentById, findTournaments, findUserByEmail, findUserById, findUsers, generateUniquePlayerNumber, getMajorTournaments, getPlayerResults, getPlayerStats, getPlayerTopFinishes, getPlayerWithResults, getRatedPlayers, getRecentTournaments, getTopPlayersByRanking, getTopPlayersByRating, getTournamentResults, getTournamentStats, getTournamentWithResults, getTournamentsByBoosterType, getTournamentsByDateRange, getUserByEmailWithPlayer, getUserWithPlayer, isValidPlayerNumber, linkPlayerToUser, prisma, recalculateTimeDecay, searchPlayers, searchTournaments, testConnection, updatePlayer, updatePlayerRating, updateResult, updateResultPoints, updateTournament, updateUser, updateUserRefreshToken };
842
+ export { type ConnectionStatus, type CreateLocationInput, type CreatePlayerInput, type CreateResultInput, type CreateTournamentInput, type CreateUserInput, type FindLocationsOptions, type FindPlayersOptions, type FindResultsOptions, type FindTournamentsOptions, type PlayerStatistics, type PlayerWithResults, type TournamentResultWithTournament, type TournamentStatistics, type UpdateLocationInput, type UpdatePlayerInput, type UpdateResultInput, type UpdateTournamentInput, type UpdateUserInput, type UserWithPlayer, connect, countLocations, countPlayers, countResults, countTournaments, countUsers, createLocation, createManyResults, createPlayer, createResult, createTournament, createUser, createUserWithPlayer, deleteLocation, deletePlayer, deleteResult, deleteResultsByTournament, deleteTournament, deleteUser, disconnect, findLocationByExternalId, findLocationById, findLocations, findPlayerByExternalId, findPlayerById, findPlayerByPlayerNumber, findPlayerByUserEmail, findPlayers, findResultById, findResultByPlayerAndTournament, findResults, findTournamentByExternalId, findTournamentById, findTournaments, findUserByEmail, findUserById, findUsers, generateUniquePlayerNumber, getLocationWithTournaments, getMajorTournaments, getPlayerResults, getPlayerStats, getPlayerTopFinishes, getPlayerWithResults, getRatedPlayers, getRecentTournaments, getTopPlayersByRanking, getTopPlayersByRating, getTournamentResults, getTournamentStats, getTournamentWithResults, getTournamentsByBoosterType, getTournamentsByDateRange, getUserByEmailWithPlayer, getUserWithPlayer, isValidPlayerNumber, linkPlayerToUser, prisma, recalculateTimeDecay, searchLocations, searchPlayers, searchTournaments, testConnection, updateLocation, updatePlayer, updatePlayerRating, updateResult, updateResultPoints, updateTournament, updateUser, updateUserRefreshToken };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _prisma_client_runtime_library from '@prisma/client/runtime/library';
2
2
  import * as _prisma_client from '@prisma/client';
3
- import { PrismaClient, Player, Prisma, EventBoosterType, Tournament, TournamentResult, User } from '@prisma/client';
4
- export { EventBoosterType, Player, Prisma, Role, Tournament, TournamentResult, User } from '@prisma/client';
3
+ import { PrismaClient, Player, Prisma, EventBoosterType, Tournament, TournamentResult, User, Location } from '@prisma/client';
4
+ export { EventBoosterType, Location, Player, Prisma, Role, Tournament, TournamentResult, User } from '@prisma/client';
5
5
 
6
6
  declare const prisma: PrismaClient<_prisma_client.Prisma.PrismaClientOptions, never, _prisma_client_runtime_library.DefaultArgs>;
7
7
  /**
@@ -119,8 +119,10 @@ declare function getPlayerWithResults(id: string): Promise<{
119
119
  createdAt: Date;
120
120
  updatedAt: Date;
121
121
  externalId: string | null;
122
- location: string | null;
122
+ description: string | null;
123
123
  date: Date;
124
+ locationId: string | null;
125
+ organizerId: string | null;
124
126
  tgpConfig: Prisma.JsonValue | null;
125
127
  eventBooster: _prisma_client.$Enums.EventBoosterType;
126
128
  allowsOptOut: boolean;
@@ -155,8 +157,10 @@ declare function getPlayerWithResults(id: string): Promise<{
155
157
  createdAt: Date;
156
158
  updatedAt: Date;
157
159
  externalId: string | null;
158
- location: string | null;
160
+ description: string | null;
159
161
  date: Date;
162
+ locationId: string | null;
163
+ organizerId: string | null;
160
164
  tgpConfig: Prisma.JsonValue | null;
161
165
  eventBooster: _prisma_client.$Enums.EventBoosterType;
162
166
  allowsOptOut: boolean;
@@ -221,8 +225,10 @@ declare function isValidPlayerNumber(playerNumber: number): boolean;
221
225
  interface CreateTournamentInput {
222
226
  externalId?: string;
223
227
  name: string;
224
- location?: string;
228
+ description?: string;
225
229
  date: Date;
230
+ locationId?: string;
231
+ organizerId?: string;
226
232
  tgpConfig?: Prisma.InputJsonValue;
227
233
  eventBooster?: EventBoosterType;
228
234
  allowsOptOut?: boolean;
@@ -239,8 +245,10 @@ interface CreateTournamentInput {
239
245
  */
240
246
  interface UpdateTournamentInput {
241
247
  name?: string;
242
- location?: string;
248
+ description?: string | null;
243
249
  date?: Date;
250
+ locationId?: string | null;
251
+ organizerId?: string | null;
244
252
  tgpConfig?: Prisma.InputJsonValue;
245
253
  eventBooster?: EventBoosterType;
246
254
  allowsOptOut?: boolean;
@@ -348,8 +356,10 @@ declare function getTournamentWithResults(id: string): Promise<({
348
356
  createdAt: Date;
349
357
  updatedAt: Date;
350
358
  externalId: string | null;
351
- location: string | null;
359
+ description: string | null;
352
360
  date: Date;
361
+ locationId: string | null;
362
+ organizerId: string | null;
353
363
  tgpConfig: Prisma.JsonValue | null;
354
364
  eventBooster: _prisma_client.$Enums.EventBoosterType;
355
365
  allowsOptOut: boolean;
@@ -362,7 +372,7 @@ declare function getTournamentWithResults(id: string): Promise<({
362
372
  firstPlaceValue: number | null;
363
373
  }) | null>;
364
374
  /**
365
- * Searches tournaments by name or location
375
+ * Searches tournaments by name or location name
366
376
  */
367
377
  declare function searchTournaments(query: string, limit?: number): Promise<Tournament[]>;
368
378
  /**
@@ -408,8 +418,10 @@ declare function getTournamentStats(id: string): Promise<{
408
418
  createdAt: Date;
409
419
  updatedAt: Date;
410
420
  externalId: string | null;
411
- location: string | null;
421
+ description: string | null;
412
422
  date: Date;
423
+ locationId: string | null;
424
+ organizerId: string | null;
413
425
  tgpConfig: Prisma.JsonValue | null;
414
426
  eventBooster: _prisma_client.$Enums.EventBoosterType;
415
427
  allowsOptOut: boolean;
@@ -569,6 +581,9 @@ interface CreateUserInput {
569
581
  passwordHash: string;
570
582
  playerId?: string;
571
583
  role?: 'USER' | 'ADMIN';
584
+ tosAcceptedAt?: Date;
585
+ privacyPolicyAcceptedAt?: Date;
586
+ codeOfConductAcceptedAt?: Date;
572
587
  }
573
588
  /**
574
589
  * Input for updating a user
@@ -589,6 +604,9 @@ interface UserWithPlayer {
589
604
  role: 'USER' | 'ADMIN';
590
605
  createdAt: Date;
591
606
  updatedAt: Date;
607
+ tosAcceptedAt: Date | null;
608
+ privacyPolicyAcceptedAt: Date | null;
609
+ codeOfConductAcceptedAt: Date | null;
592
610
  player: {
593
611
  id: string;
594
612
  playerNumber: number;
@@ -662,6 +680,106 @@ declare function findUsers(params: {
662
680
  */
663
681
  declare function linkPlayerToUser(userId: string, playerId: string | null): Promise<UserWithPlayer>;
664
682
 
683
+ /**
684
+ * Input for creating a new location
685
+ */
686
+ interface CreateLocationInput {
687
+ externalId?: string;
688
+ name: string;
689
+ address?: string;
690
+ city?: string;
691
+ state?: string;
692
+ country?: string;
693
+ }
694
+ /**
695
+ * Input for updating a location
696
+ */
697
+ interface UpdateLocationInput {
698
+ name?: string;
699
+ address?: string | null;
700
+ city?: string | null;
701
+ state?: string | null;
702
+ country?: string | null;
703
+ }
704
+ /**
705
+ * Options for querying locations
706
+ */
707
+ interface FindLocationsOptions {
708
+ take?: number;
709
+ skip?: number;
710
+ orderBy?: Prisma.LocationOrderByWithRelationInput;
711
+ where?: Prisma.LocationWhereInput;
712
+ include?: Prisma.LocationInclude;
713
+ }
714
+ /**
715
+ * Creates a new location
716
+ */
717
+ declare function createLocation(data: CreateLocationInput): Promise<Location>;
718
+ /**
719
+ * Finds a location by ID
720
+ */
721
+ declare function findLocationById(id: string, include?: Prisma.LocationInclude): Promise<Location | null>;
722
+ /**
723
+ * Finds a location by external ID
724
+ */
725
+ declare function findLocationByExternalId(externalId: string, include?: Prisma.LocationInclude): Promise<Location | null>;
726
+ /**
727
+ * Finds multiple locations with optional filters
728
+ */
729
+ declare function findLocations(options?: FindLocationsOptions): Promise<Location[]>;
730
+ /**
731
+ * Searches locations by name or city
732
+ */
733
+ declare function searchLocations(query: string, limit?: number): Promise<Location[]>;
734
+ /**
735
+ * Updates a location
736
+ */
737
+ declare function updateLocation(id: string, data: UpdateLocationInput): Promise<Location>;
738
+ /**
739
+ * Deletes a location
740
+ */
741
+ declare function deleteLocation(id: string): Promise<Location>;
742
+ /**
743
+ * Counts total locations
744
+ */
745
+ declare function countLocations(where?: Prisma.LocationWhereInput): Promise<number>;
746
+ /**
747
+ * Gets location with its tournaments
748
+ */
749
+ declare function getLocationWithTournaments(id: string): Promise<({
750
+ tournaments: {
751
+ name: string;
752
+ id: string;
753
+ createdAt: Date;
754
+ updatedAt: Date;
755
+ externalId: string | null;
756
+ description: string | null;
757
+ date: Date;
758
+ locationId: string | null;
759
+ organizerId: string | null;
760
+ tgpConfig: Prisma.JsonValue | null;
761
+ eventBooster: _prisma_client.$Enums.EventBoosterType;
762
+ allowsOptOut: boolean;
763
+ baseValue: number | null;
764
+ tvaRating: number | null;
765
+ tvaRanking: number | null;
766
+ totalTVA: number | null;
767
+ tgp: number | null;
768
+ eventBoosterMultiplier: number | null;
769
+ firstPlaceValue: number | null;
770
+ }[];
771
+ } & {
772
+ name: string;
773
+ id: string;
774
+ createdAt: Date;
775
+ updatedAt: Date;
776
+ externalId: string | null;
777
+ address: string | null;
778
+ city: string | null;
779
+ state: string | null;
780
+ country: string | null;
781
+ }) | null>;
782
+
665
783
  /**
666
784
  * Re-export Prisma generated types
667
785
  */
@@ -721,4 +839,4 @@ interface ConnectionStatus {
721
839
  error?: string;
722
840
  }
723
841
 
724
- export { type ConnectionStatus, type CreatePlayerInput, type CreateResultInput, type CreateTournamentInput, type CreateUserInput, type FindPlayersOptions, type FindResultsOptions, type FindTournamentsOptions, type PlayerStatistics, type PlayerWithResults, type TournamentResultWithTournament, type TournamentStatistics, type UpdatePlayerInput, type UpdateResultInput, type UpdateTournamentInput, type UpdateUserInput, type UserWithPlayer, connect, countPlayers, countResults, countTournaments, countUsers, createManyResults, createPlayer, createResult, createTournament, createUser, createUserWithPlayer, deletePlayer, deleteResult, deleteResultsByTournament, deleteTournament, deleteUser, disconnect, findPlayerByExternalId, findPlayerById, findPlayerByPlayerNumber, findPlayerByUserEmail, findPlayers, findResultById, findResultByPlayerAndTournament, findResults, findTournamentByExternalId, findTournamentById, findTournaments, findUserByEmail, findUserById, findUsers, generateUniquePlayerNumber, getMajorTournaments, getPlayerResults, getPlayerStats, getPlayerTopFinishes, getPlayerWithResults, getRatedPlayers, getRecentTournaments, getTopPlayersByRanking, getTopPlayersByRating, getTournamentResults, getTournamentStats, getTournamentWithResults, getTournamentsByBoosterType, getTournamentsByDateRange, getUserByEmailWithPlayer, getUserWithPlayer, isValidPlayerNumber, linkPlayerToUser, prisma, recalculateTimeDecay, searchPlayers, searchTournaments, testConnection, updatePlayer, updatePlayerRating, updateResult, updateResultPoints, updateTournament, updateUser, updateUserRefreshToken };
842
+ export { type ConnectionStatus, type CreateLocationInput, type CreatePlayerInput, type CreateResultInput, type CreateTournamentInput, type CreateUserInput, type FindLocationsOptions, type FindPlayersOptions, type FindResultsOptions, type FindTournamentsOptions, type PlayerStatistics, type PlayerWithResults, type TournamentResultWithTournament, type TournamentStatistics, type UpdateLocationInput, type UpdatePlayerInput, type UpdateResultInput, type UpdateTournamentInput, type UpdateUserInput, type UserWithPlayer, connect, countLocations, countPlayers, countResults, countTournaments, countUsers, createLocation, createManyResults, createPlayer, createResult, createTournament, createUser, createUserWithPlayer, deleteLocation, deletePlayer, deleteResult, deleteResultsByTournament, deleteTournament, deleteUser, disconnect, findLocationByExternalId, findLocationById, findLocations, findPlayerByExternalId, findPlayerById, findPlayerByPlayerNumber, findPlayerByUserEmail, findPlayers, findResultById, findResultByPlayerAndTournament, findResults, findTournamentByExternalId, findTournamentById, findTournaments, findUserByEmail, findUserById, findUsers, generateUniquePlayerNumber, getLocationWithTournaments, getMajorTournaments, getPlayerResults, getPlayerStats, getPlayerTopFinishes, getPlayerWithResults, getRatedPlayers, getRecentTournaments, getTopPlayersByRanking, getTopPlayersByRating, getTournamentResults, getTournamentStats, getTournamentWithResults, getTournamentsByBoosterType, getTournamentsByDateRange, getUserByEmailWithPlayer, getUserWithPlayer, isValidPlayerNumber, linkPlayerToUser, prisma, recalculateTimeDecay, searchLocations, searchPlayers, searchTournaments, testConnection, updateLocation, updatePlayer, updatePlayerRating, updateResult, updateResultPoints, updateTournament, updateUser, updateUserRefreshToken };
package/dist/index.js CHANGED
@@ -272,7 +272,7 @@ async function searchTournaments(query, limit = 20) {
272
272
  where: {
273
273
  OR: [
274
274
  { name: { contains: query, mode: "insensitive" } },
275
- { location: { contains: query, mode: "insensitive" } }
275
+ { location: { name: { contains: query, mode: "insensitive" } } }
276
276
  ]
277
277
  },
278
278
  orderBy: { date: "desc" }
@@ -656,24 +656,96 @@ async function linkPlayerToUser(userId, playerId) {
656
656
  return user;
657
657
  });
658
658
  }
659
+
660
+ // src/locations.ts
661
+ async function createLocation(data) {
662
+ return prisma.location.create({
663
+ data
664
+ });
665
+ }
666
+ async function findLocationById(id, include) {
667
+ return prisma.location.findUnique({
668
+ where: { id },
669
+ include
670
+ });
671
+ }
672
+ async function findLocationByExternalId(externalId, include) {
673
+ return prisma.location.findUnique({
674
+ where: { externalId },
675
+ include
676
+ });
677
+ }
678
+ async function findLocations(options = {}) {
679
+ return prisma.location.findMany({
680
+ take: options.take,
681
+ skip: options.skip,
682
+ where: options.where,
683
+ orderBy: options.orderBy,
684
+ include: options.include
685
+ });
686
+ }
687
+ async function searchLocations(query, limit = 20) {
688
+ return findLocations({
689
+ take: limit,
690
+ where: {
691
+ OR: [
692
+ { name: { contains: query, mode: "insensitive" } },
693
+ { city: { contains: query, mode: "insensitive" } }
694
+ ]
695
+ },
696
+ orderBy: { name: "asc" }
697
+ });
698
+ }
699
+ async function updateLocation(id, data) {
700
+ return prisma.location.update({
701
+ where: { id },
702
+ data
703
+ });
704
+ }
705
+ async function deleteLocation(id) {
706
+ return prisma.location.delete({
707
+ where: { id }
708
+ });
709
+ }
710
+ async function countLocations(where) {
711
+ return prisma.location.count({ where });
712
+ }
713
+ async function getLocationWithTournaments(id) {
714
+ return prisma.location.findUnique({
715
+ where: { id },
716
+ include: {
717
+ tournaments: {
718
+ orderBy: {
719
+ date: "desc"
720
+ }
721
+ }
722
+ }
723
+ });
724
+ }
659
725
  export {
660
726
  connect,
727
+ countLocations,
661
728
  countPlayers,
662
729
  countResults,
663
730
  countTournaments,
664
731
  countUsers,
732
+ createLocation,
665
733
  createManyResults,
666
734
  createPlayer,
667
735
  createResult,
668
736
  createTournament,
669
737
  createUser,
670
738
  createUserWithPlayer,
739
+ deleteLocation,
671
740
  deletePlayer,
672
741
  deleteResult,
673
742
  deleteResultsByTournament,
674
743
  deleteTournament,
675
744
  deleteUser,
676
745
  disconnect,
746
+ findLocationByExternalId,
747
+ findLocationById,
748
+ findLocations,
677
749
  findPlayerByExternalId,
678
750
  findPlayerById,
679
751
  findPlayerByPlayerNumber,
@@ -689,6 +761,7 @@ export {
689
761
  findUserById,
690
762
  findUsers,
691
763
  generateUniquePlayerNumber,
764
+ getLocationWithTournaments,
692
765
  getMajorTournaments,
693
766
  getPlayerResults,
694
767
  getPlayerStats,
@@ -709,9 +782,11 @@ export {
709
782
  linkPlayerToUser,
710
783
  prisma,
711
784
  recalculateTimeDecay,
785
+ searchLocations,
712
786
  searchPlayers,
713
787
  searchTournaments,
714
788
  testConnection,
789
+ updateLocation,
715
790
  updatePlayer,
716
791
  updatePlayerRating,
717
792
  updateResult,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opprs/db-prisma",
3
- "version": "2.2.1-canary.840995",
3
+ "version": "2.2.1-canary.9b5fc07",
4
4
  "description": "Database backend for OPPR (Open Pinball Player Ranking System) using Prisma and PostgreSQL",
5
5
  "keywords": [
6
6
  "oppr",
@@ -56,7 +56,7 @@
56
56
  "vitest": "^4.0.16"
57
57
  },
58
58
  "peerDependencies": {
59
- "@opprs/core": "^2.2.1-canary.0840995"
59
+ "@opprs/core": "^2.2.1-canary.9b5fc07"
60
60
  },
61
61
  "engines": {
62
62
  "node": ">=20.9.0"
@@ -0,0 +1,45 @@
1
+ -- CreateTable
2
+ CREATE TABLE "Location" (
3
+ "id" TEXT NOT NULL,
4
+ "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
5
+ "updatedAt" TIMESTAMP(3) NOT NULL,
6
+ "externalId" TEXT,
7
+ "name" TEXT NOT NULL,
8
+ "address" TEXT,
9
+ "city" TEXT,
10
+ "state" TEXT,
11
+ "country" TEXT,
12
+
13
+ CONSTRAINT "Location_pkey" PRIMARY KEY ("id")
14
+ );
15
+
16
+ -- CreateIndex
17
+ CREATE UNIQUE INDEX "Location_externalId_key" ON "Location"("externalId");
18
+
19
+ -- CreateIndex
20
+ CREATE INDEX "Location_externalId_idx" ON "Location"("externalId");
21
+
22
+ -- CreateIndex
23
+ CREATE INDEX "Location_name_idx" ON "Location"("name");
24
+
25
+ -- CreateIndex
26
+ CREATE INDEX "Location_city_idx" ON "Location"("city");
27
+
28
+ -- AlterTable: Add new columns to Tournament
29
+ ALTER TABLE "Tournament" ADD COLUMN "description" VARCHAR(2000);
30
+ ALTER TABLE "Tournament" ADD COLUMN "locationId" TEXT;
31
+ ALTER TABLE "Tournament" ADD COLUMN "organizerId" TEXT;
32
+
33
+ -- DropColumn: Remove old location string column (replaced by Location relation)
34
+ ALTER TABLE "Tournament" DROP COLUMN IF EXISTS "location";
35
+
36
+ -- CreateIndex for new Tournament columns
37
+ CREATE INDEX "Tournament_locationId_idx" ON "Tournament"("locationId");
38
+
39
+ CREATE INDEX "Tournament_organizerId_idx" ON "Tournament"("organizerId");
40
+
41
+ -- AddForeignKey: Tournament -> Location
42
+ ALTER TABLE "Tournament" ADD CONSTRAINT "Tournament_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "Location"("id") ON DELETE SET NULL ON UPDATE CASCADE;
43
+
44
+ -- AddForeignKey: Tournament -> Player (organizer)
45
+ ALTER TABLE "Tournament" ADD CONSTRAINT "Tournament_organizerId_fkey" FOREIGN KEY ("organizerId") REFERENCES "Player"("id") ON DELETE SET NULL ON UPDATE CASCADE;
@@ -0,0 +1,19 @@
1
+ /*
2
+ Warnings:
3
+
4
+ - You are about to drop the column `email` on the `Player` table. All the data in the column will be lost.
5
+
6
+ */
7
+ -- DropIndex
8
+ DROP INDEX "Player_email_idx";
9
+
10
+ -- DropIndex
11
+ DROP INDEX "Player_email_key";
12
+
13
+ -- AlterTable
14
+ ALTER TABLE "Player" DROP COLUMN "email";
15
+
16
+ -- AlterTable
17
+ ALTER TABLE "User" ADD COLUMN "codeOfConductAcceptedAt" TIMESTAMP(3),
18
+ ADD COLUMN "privacyPolicyAcceptedAt" TIMESTAMP(3),
19
+ ADD COLUMN "tosAcceptedAt" TIMESTAMP(3);
@@ -33,8 +33,9 @@ model Player {
33
33
  lastEventDate DateTime?
34
34
 
35
35
  // Relations
36
- tournamentResults TournamentResult[]
37
- user User?
36
+ tournamentResults TournamentResult[]
37
+ user User?
38
+ organizedTournaments Tournament[] @relation("OrganizedTournaments")
38
39
 
39
40
  @@index([externalId])
40
41
  @@index([playerNumber])
@@ -51,9 +52,17 @@ model Tournament {
51
52
  // Tournament identification
52
53
  externalId String? @unique // External ID from OPPR or other systems
53
54
  name String
54
- location String?
55
+ description String? @db.VarChar(2000)
55
56
  date DateTime
56
57
 
58
+ // Location relation
59
+ locationId String?
60
+ location Location? @relation(fields: [locationId], references: [id], onDelete: SetNull)
61
+
62
+ // Organizer relation
63
+ organizerId String?
64
+ organizer Player? @relation("OrganizedTournaments", fields: [organizerId], references: [id], onDelete: SetNull)
65
+
57
66
  // Tournament configuration (stored as JSON)
58
67
  // Contains TGPConfig structure from OPPR
59
68
  tgpConfig Json?
@@ -77,6 +86,8 @@ model Tournament {
77
86
  @@index([date])
78
87
  @@index([eventBooster])
79
88
  @@index([externalId])
89
+ @@index([locationId])
90
+ @@index([organizerId])
80
91
  }
81
92
 
82
93
  // Tournament Result - junction table linking players to tournaments
@@ -149,5 +160,31 @@ model User {
149
160
  // Session management (for token revocation)
150
161
  refreshTokenHash String?
151
162
 
163
+ // Policy acceptance timestamps (null = not accepted)
164
+ tosAcceptedAt DateTime?
165
+ privacyPolicyAcceptedAt DateTime?
166
+ codeOfConductAcceptedAt DateTime?
167
+
152
168
  @@index([email])
153
169
  }
170
+
171
+ // Location model - represents a venue where tournaments are held
172
+ model Location {
173
+ id String @id @default(cuid())
174
+ createdAt DateTime @default(now())
175
+ updatedAt DateTime @updatedAt
176
+
177
+ externalId String? @unique
178
+ name String
179
+ address String?
180
+ city String?
181
+ state String?
182
+ country String?
183
+
184
+ // Relations
185
+ tournaments Tournament[]
186
+
187
+ @@index([externalId])
188
+ @@index([name])
189
+ @@index([city])
190
+ }
package/prisma/seed.ts CHANGED
@@ -149,13 +149,71 @@ async function main() {
149
149
 
150
150
  console.log(`✓ Created admin user (admin@example.com / ${adminPassword})`);
151
151
 
152
+ // Create sample locations (using upsert for idempotency)
153
+ console.log('Creating locations...');
154
+
155
+ const location1 = await prisma.location.upsert({
156
+ where: { externalId: 'location-1' },
157
+ update: {
158
+ name: 'Las Vegas Convention Center',
159
+ city: 'Las Vegas',
160
+ state: 'NV',
161
+ country: 'USA',
162
+ },
163
+ create: {
164
+ externalId: 'location-1',
165
+ name: 'Las Vegas Convention Center',
166
+ city: 'Las Vegas',
167
+ state: 'NV',
168
+ country: 'USA',
169
+ },
170
+ });
171
+
172
+ const location2 = await prisma.location.upsert({
173
+ where: { externalId: 'location-2' },
174
+ update: {
175
+ name: 'Ground Kontrol',
176
+ address: '115 NW 5th Ave',
177
+ city: 'Portland',
178
+ state: 'OR',
179
+ country: 'USA',
180
+ },
181
+ create: {
182
+ externalId: 'location-2',
183
+ name: 'Ground Kontrol',
184
+ address: '115 NW 5th Ave',
185
+ city: 'Portland',
186
+ state: 'OR',
187
+ country: 'USA',
188
+ },
189
+ });
190
+
191
+ const location3 = await prisma.location.upsert({
192
+ where: { externalId: 'location-3' },
193
+ update: {
194
+ name: 'Add-a-Ball Amusements',
195
+ city: 'Seattle',
196
+ state: 'WA',
197
+ country: 'USA',
198
+ },
199
+ create: {
200
+ externalId: 'location-3',
201
+ name: 'Add-a-Ball Amusements',
202
+ city: 'Seattle',
203
+ state: 'WA',
204
+ country: 'USA',
205
+ },
206
+ });
207
+
208
+ console.log(`✓ Created ${await prisma.location.count()} locations`);
209
+
152
210
  // Create sample tournaments (using upsert for idempotency)
153
211
  console.log('Creating tournaments...');
154
212
 
155
213
  const tournament1Data = {
156
214
  externalId: 'tournament-1',
157
215
  name: 'World Pinball Championship 2024',
158
- location: 'Las Vegas, NV',
216
+ locationId: location1.id,
159
217
  date: new Date('2024-03-15'),
160
218
  eventBooster: EventBoosterType.MAJOR,
161
219
  allowsOptOut: false,
@@ -191,7 +249,7 @@ async function main() {
191
249
  const tournament2Data = {
192
250
  externalId: 'tournament-2',
193
251
  name: 'Spring Classics 2024',
194
- location: 'Portland, OR',
252
+ locationId: location2.id,
195
253
  date: new Date('2024-04-20'),
196
254
  eventBooster: EventBoosterType.CERTIFIED,
197
255
  allowsOptOut: true,
@@ -225,7 +283,7 @@ async function main() {
225
283
  const tournament3Data = {
226
284
  externalId: 'tournament-3',
227
285
  name: 'Monthly League Finals',
228
- location: 'Seattle, WA',
286
+ locationId: location3.id,
229
287
  date: new Date('2024-05-10'),
230
288
  eventBooster: EventBoosterType.NONE,
231
289
  allowsOptOut: false,
@@ -428,6 +486,7 @@ async function main() {
428
486
  console.log('Summary:');
429
487
  console.log(` - ${await prisma.player.count()} players`);
430
488
  console.log(` - ${await prisma.user.count()} users`);
489
+ console.log(` - ${await prisma.location.count()} locations`);
431
490
  console.log(` - ${await prisma.tournament.count()} tournaments`);
432
491
  console.log(` - ${await prisma.tournamentResult.count()} tournament results`);
433
492
  }