@opprs/db-prisma 2.2.1-canary.5233c68 → 2.2.1-canary.5daa968

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;
@@ -662,6 +674,106 @@ declare function findUsers(params: {
662
674
  */
663
675
  declare function linkPlayerToUser(userId: string, playerId: string | null): Promise<UserWithPlayer>;
664
676
 
677
+ /**
678
+ * Input for creating a new location
679
+ */
680
+ interface CreateLocationInput {
681
+ externalId?: string;
682
+ name: string;
683
+ address?: string;
684
+ city?: string;
685
+ state?: string;
686
+ country?: string;
687
+ }
688
+ /**
689
+ * Input for updating a location
690
+ */
691
+ interface UpdateLocationInput {
692
+ name?: string;
693
+ address?: string | null;
694
+ city?: string | null;
695
+ state?: string | null;
696
+ country?: string | null;
697
+ }
698
+ /**
699
+ * Options for querying locations
700
+ */
701
+ interface FindLocationsOptions {
702
+ take?: number;
703
+ skip?: number;
704
+ orderBy?: Prisma.LocationOrderByWithRelationInput;
705
+ where?: Prisma.LocationWhereInput;
706
+ include?: Prisma.LocationInclude;
707
+ }
708
+ /**
709
+ * Creates a new location
710
+ */
711
+ declare function createLocation(data: CreateLocationInput): Promise<Location>;
712
+ /**
713
+ * Finds a location by ID
714
+ */
715
+ declare function findLocationById(id: string, include?: Prisma.LocationInclude): Promise<Location | null>;
716
+ /**
717
+ * Finds a location by external ID
718
+ */
719
+ declare function findLocationByExternalId(externalId: string, include?: Prisma.LocationInclude): Promise<Location | null>;
720
+ /**
721
+ * Finds multiple locations with optional filters
722
+ */
723
+ declare function findLocations(options?: FindLocationsOptions): Promise<Location[]>;
724
+ /**
725
+ * Searches locations by name or city
726
+ */
727
+ declare function searchLocations(query: string, limit?: number): Promise<Location[]>;
728
+ /**
729
+ * Updates a location
730
+ */
731
+ declare function updateLocation(id: string, data: UpdateLocationInput): Promise<Location>;
732
+ /**
733
+ * Deletes a location
734
+ */
735
+ declare function deleteLocation(id: string): Promise<Location>;
736
+ /**
737
+ * Counts total locations
738
+ */
739
+ declare function countLocations(where?: Prisma.LocationWhereInput): Promise<number>;
740
+ /**
741
+ * Gets location with its tournaments
742
+ */
743
+ declare function getLocationWithTournaments(id: string): Promise<({
744
+ tournaments: {
745
+ name: string;
746
+ id: string;
747
+ createdAt: Date;
748
+ updatedAt: Date;
749
+ externalId: string | null;
750
+ description: string | null;
751
+ date: Date;
752
+ locationId: string | null;
753
+ organizerId: string | null;
754
+ tgpConfig: Prisma.JsonValue | null;
755
+ eventBooster: _prisma_client.$Enums.EventBoosterType;
756
+ allowsOptOut: boolean;
757
+ baseValue: number | null;
758
+ tvaRating: number | null;
759
+ tvaRanking: number | null;
760
+ totalTVA: number | null;
761
+ tgp: number | null;
762
+ eventBoosterMultiplier: number | null;
763
+ firstPlaceValue: number | null;
764
+ }[];
765
+ } & {
766
+ name: string;
767
+ id: string;
768
+ createdAt: Date;
769
+ updatedAt: Date;
770
+ externalId: string | null;
771
+ address: string | null;
772
+ city: string | null;
773
+ state: string | null;
774
+ country: string | null;
775
+ }) | null>;
776
+
665
777
  /**
666
778
  * Re-export Prisma generated types
667
779
  */
@@ -721,4 +833,4 @@ interface ConnectionStatus {
721
833
  error?: string;
722
834
  }
723
835
 
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 };
836
+ 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;
@@ -662,6 +674,106 @@ declare function findUsers(params: {
662
674
  */
663
675
  declare function linkPlayerToUser(userId: string, playerId: string | null): Promise<UserWithPlayer>;
664
676
 
677
+ /**
678
+ * Input for creating a new location
679
+ */
680
+ interface CreateLocationInput {
681
+ externalId?: string;
682
+ name: string;
683
+ address?: string;
684
+ city?: string;
685
+ state?: string;
686
+ country?: string;
687
+ }
688
+ /**
689
+ * Input for updating a location
690
+ */
691
+ interface UpdateLocationInput {
692
+ name?: string;
693
+ address?: string | null;
694
+ city?: string | null;
695
+ state?: string | null;
696
+ country?: string | null;
697
+ }
698
+ /**
699
+ * Options for querying locations
700
+ */
701
+ interface FindLocationsOptions {
702
+ take?: number;
703
+ skip?: number;
704
+ orderBy?: Prisma.LocationOrderByWithRelationInput;
705
+ where?: Prisma.LocationWhereInput;
706
+ include?: Prisma.LocationInclude;
707
+ }
708
+ /**
709
+ * Creates a new location
710
+ */
711
+ declare function createLocation(data: CreateLocationInput): Promise<Location>;
712
+ /**
713
+ * Finds a location by ID
714
+ */
715
+ declare function findLocationById(id: string, include?: Prisma.LocationInclude): Promise<Location | null>;
716
+ /**
717
+ * Finds a location by external ID
718
+ */
719
+ declare function findLocationByExternalId(externalId: string, include?: Prisma.LocationInclude): Promise<Location | null>;
720
+ /**
721
+ * Finds multiple locations with optional filters
722
+ */
723
+ declare function findLocations(options?: FindLocationsOptions): Promise<Location[]>;
724
+ /**
725
+ * Searches locations by name or city
726
+ */
727
+ declare function searchLocations(query: string, limit?: number): Promise<Location[]>;
728
+ /**
729
+ * Updates a location
730
+ */
731
+ declare function updateLocation(id: string, data: UpdateLocationInput): Promise<Location>;
732
+ /**
733
+ * Deletes a location
734
+ */
735
+ declare function deleteLocation(id: string): Promise<Location>;
736
+ /**
737
+ * Counts total locations
738
+ */
739
+ declare function countLocations(where?: Prisma.LocationWhereInput): Promise<number>;
740
+ /**
741
+ * Gets location with its tournaments
742
+ */
743
+ declare function getLocationWithTournaments(id: string): Promise<({
744
+ tournaments: {
745
+ name: string;
746
+ id: string;
747
+ createdAt: Date;
748
+ updatedAt: Date;
749
+ externalId: string | null;
750
+ description: string | null;
751
+ date: Date;
752
+ locationId: string | null;
753
+ organizerId: string | null;
754
+ tgpConfig: Prisma.JsonValue | null;
755
+ eventBooster: _prisma_client.$Enums.EventBoosterType;
756
+ allowsOptOut: boolean;
757
+ baseValue: number | null;
758
+ tvaRating: number | null;
759
+ tvaRanking: number | null;
760
+ totalTVA: number | null;
761
+ tgp: number | null;
762
+ eventBoosterMultiplier: number | null;
763
+ firstPlaceValue: number | null;
764
+ }[];
765
+ } & {
766
+ name: string;
767
+ id: string;
768
+ createdAt: Date;
769
+ updatedAt: Date;
770
+ externalId: string | null;
771
+ address: string | null;
772
+ city: string | null;
773
+ state: string | null;
774
+ country: string | null;
775
+ }) | null>;
776
+
665
777
  /**
666
778
  * Re-export Prisma generated types
667
779
  */
@@ -721,4 +833,4 @@ interface ConnectionStatus {
721
833
  error?: string;
722
834
  }
723
835
 
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 };
836
+ 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.5233c68",
3
+ "version": "2.2.1-canary.5daa968",
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.5233c68"
59
+ "@opprs/core": "^2.2.1-canary.5daa968"
60
60
  },
61
61
  "engines": {
62
62
  "node": ">=20.9.0"
@@ -0,0 +1,23 @@
1
+ -- AlterTable
2
+ -- First add playerNumber as nullable, populate it, then make it required
3
+ ALTER TABLE "Player" ADD COLUMN "playerNumber" INTEGER;
4
+
5
+ -- Populate existing players with unique 5-digit player numbers
6
+ -- Use a sequence starting from 10000, incrementing for each existing row
7
+ WITH numbered_players AS (
8
+ SELECT id, ROW_NUMBER() OVER (ORDER BY "createdAt") + 9999 AS num
9
+ FROM "Player"
10
+ )
11
+ UPDATE "Player"
12
+ SET "playerNumber" = numbered_players.num::INTEGER
13
+ FROM numbered_players
14
+ WHERE "Player".id = numbered_players.id;
15
+
16
+ -- Make the column required and add unique constraint
17
+ ALTER TABLE "Player" ALTER COLUMN "playerNumber" SET NOT NULL;
18
+
19
+ -- CreateIndex
20
+ CREATE UNIQUE INDEX "Player_playerNumber_key" ON "Player"("playerNumber");
21
+
22
+ -- CreateIndex
23
+ CREATE INDEX "Player_playerNumber_idx" ON "Player"("playerNumber");
@@ -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;
@@ -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
@@ -151,3 +162,24 @@ model User {
151
162
 
152
163
  @@index([email])
153
164
  }
165
+
166
+ // Location model - represents a venue where tournaments are held
167
+ model Location {
168
+ id String @id @default(cuid())
169
+ createdAt DateTime @default(now())
170
+ updatedAt DateTime @updatedAt
171
+
172
+ externalId String? @unique
173
+ name String
174
+ address String?
175
+ city String?
176
+ state String?
177
+ country String?
178
+
179
+ // Relations
180
+ tournaments Tournament[]
181
+
182
+ @@index([externalId])
183
+ @@index([name])
184
+ @@index([city])
185
+ }
package/prisma/seed.ts CHANGED
@@ -13,6 +13,7 @@ async function main() {
13
13
  const playerData = [
14
14
  {
15
15
  externalId: 'player-1',
16
+ playerNumber: 10001,
16
17
  name: 'Alice Champion',
17
18
  rating: 1850,
18
19
  ratingDeviation: 50,
@@ -22,6 +23,7 @@ async function main() {
22
23
  },
23
24
  {
24
25
  externalId: 'player-2',
26
+ playerNumber: 10002,
25
27
  name: 'Bob Wizard',
26
28
  rating: 1750,
27
29
  ratingDeviation: 60,
@@ -31,6 +33,7 @@ async function main() {
31
33
  },
32
34
  {
33
35
  externalId: 'player-3',
36
+ playerNumber: 10003,
34
37
  name: 'Charlie Flipper',
35
38
  rating: 1650,
36
39
  ratingDeviation: 75,
@@ -40,6 +43,7 @@ async function main() {
40
43
  },
41
44
  {
42
45
  externalId: 'player-4',
46
+ playerNumber: 10004,
43
47
  name: 'Diana Tilt',
44
48
  rating: 1550,
45
49
  ratingDeviation: 100,
@@ -49,6 +53,7 @@ async function main() {
49
53
  },
50
54
  {
51
55
  externalId: 'player-5',
56
+ playerNumber: 10005,
52
57
  name: 'Eve Plunger',
53
58
  rating: 1300,
54
59
  ratingDeviation: 150,
@@ -144,25 +149,63 @@ async function main() {
144
149
 
145
150
  console.log(`✓ Created admin user (admin@example.com / ${adminPassword})`);
146
151
 
147
- // Create admin user
148
- console.log('Creating admin user...');
149
- const adminPassword = 'AdminPassword123!';
150
- const adminPasswordHash = await bcrypt.hash(adminPassword, BCRYPT_SALT_ROUNDS);
152
+ // Create sample locations (using upsert for idempotency)
153
+ console.log('Creating locations...');
151
154
 
152
- await prisma.user.upsert({
153
- where: { email: 'admin@example.com' },
155
+ const location1 = await prisma.location.upsert({
156
+ where: { externalId: 'location-1' },
154
157
  update: {
155
- passwordHash: adminPasswordHash,
156
- role: 'ADMIN',
158
+ name: 'Las Vegas Convention Center',
159
+ city: 'Las Vegas',
160
+ state: 'NV',
161
+ country: 'USA',
157
162
  },
158
163
  create: {
159
- email: 'admin@example.com',
160
- passwordHash: adminPasswordHash,
161
- role: 'ADMIN',
164
+ externalId: 'location-1',
165
+ name: 'Las Vegas Convention Center',
166
+ city: 'Las Vegas',
167
+ state: 'NV',
168
+ country: 'USA',
162
169
  },
163
170
  });
164
171
 
165
- console.log(`✓ Created admin user (admin@example.com / ${adminPassword})`);
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`);
166
209
 
167
210
  // Create sample tournaments (using upsert for idempotency)
168
211
  console.log('Creating tournaments...');
@@ -170,7 +213,7 @@ async function main() {
170
213
  const tournament1Data = {
171
214
  externalId: 'tournament-1',
172
215
  name: 'World Pinball Championship 2024',
173
- location: 'Las Vegas, NV',
216
+ locationId: location1.id,
174
217
  date: new Date('2024-03-15'),
175
218
  eventBooster: EventBoosterType.MAJOR,
176
219
  allowsOptOut: false,
@@ -206,7 +249,7 @@ async function main() {
206
249
  const tournament2Data = {
207
250
  externalId: 'tournament-2',
208
251
  name: 'Spring Classics 2024',
209
- location: 'Portland, OR',
252
+ locationId: location2.id,
210
253
  date: new Date('2024-04-20'),
211
254
  eventBooster: EventBoosterType.CERTIFIED,
212
255
  allowsOptOut: true,
@@ -240,7 +283,7 @@ async function main() {
240
283
  const tournament3Data = {
241
284
  externalId: 'tournament-3',
242
285
  name: 'Monthly League Finals',
243
- location: 'Seattle, WA',
286
+ locationId: location3.id,
244
287
  date: new Date('2024-05-10'),
245
288
  eventBooster: EventBoosterType.NONE,
246
289
  allowsOptOut: false,
@@ -443,6 +486,7 @@ async function main() {
443
486
  console.log('Summary:');
444
487
  console.log(` - ${await prisma.player.count()} players`);
445
488
  console.log(` - ${await prisma.user.count()} users`);
489
+ console.log(` - ${await prisma.location.count()} locations`);
446
490
  console.log(` - ${await prisma.tournament.count()} tournaments`);
447
491
  console.log(` - ${await prisma.tournamentResult.count()} tournament results`);
448
492
  }