Skip to content

Commit

Permalink
updated numbers to bigint (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
thatguyinabeanie authored Nov 10, 2024
1 parent 2b3b2e8 commit 73805ee
Show file tree
Hide file tree
Showing 18 changed files with 85 additions and 133 deletions.
5 changes: 3 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"nitropack",
"Pressable",
"prettiercache",
"sluggable",
"subrouters",
"thatguyinabenaie",
"tsbuildinfo",
Expand All @@ -57,7 +58,7 @@
"name": "postgres",
"group": "postgres",
"database": "fuecoco-db-dev",
"username": "postgres",
"username": "postgres"
}
],
]
}
97 changes: 43 additions & 54 deletions apps/nextjs/src/app/server-actions/pokemon/actions.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,61 @@
"use server";

import type { FetchOptions } from "openapi-fetch";

import type { PokemonTeam } from "@battle-stadium/db/schema";
import { db } from "@battle-stadium/db";
import { pokemon, pokemonTeams } from "@battle-stadium/db/schema";

import type { paths } from "~/lib/api/openapi-v1";
import type { PokePasteMetadata, ValidatedPokemon } from "~/lib/pokemon/common";
import { BattleStadiumApiClient, defaultConfig } from "~/lib/api";

interface PostPokemonTeamBody {
pokepaste_id?: string;
profile_id: number | null;
name: string;
format_id: number;
game_id: number;
pokemon: {
species: string;
item: string;
ability: string;
tera_type: string;
nature: string;
form: string | null;
nickname?: string | null;
gender?: string;
move1: string | null;
move2: string | null;
move3: string | null;
move4: string | null;
pokemon_team_id?: number;
}[];
}

export async function getPokemonTeams(): Promise<PokemonTeam[] | undefined> {
export async function getPokemonTeams() {
return await db.query.pokemonTeams.findMany();
}

export async function postPokemonTeam(
validatedTeam: ValidatedPokemon[],
metadata: PokePasteMetadata,
options?: FetchOptions<paths["/pokemon_teams"]["post"]>,
) {
const body: PostPokemonTeamBody = {
pokepaste_id: metadata.id,
profile_id: null,
const body = {
pokepasteId: metadata.id,
profileId: null,
name: metadata.title,
format_id: 1,
game_id: 1,
pokemon: validatedTeam.map(({ pokemon }) => ({
nickname: pokemon.name,
species: pokemon.species,
item: pokemon.item,
ability: pokemon.ability,
tera_type: pokemon.teraType ?? "",
nature: pokemon.nature,
form: null,
move1: pokemon.moves[0] ?? null,
move2: pokemon.moves[1] ?? null,
move3: pokemon.moves[2] ?? null,
move4: pokemon.moves[3] ?? null,
})),
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
gameId: BigInt(1),
formatId: BigInt(1),
};

const pokemonOptions = {
...defaultConfig("postPokemonTeam"),
...options,
body,
const pokemonTeamResult = await db
.insert(pokemonTeams)
.values(body)
.returning();

if (!pokemonTeamResult.length) {
throw new Error("Failed to insert Pokemon Team");
}

const pokemonList = validatedTeam.map(({ pokemon }) => ({
pokemonTeamId: pokemonTeamResult[0]?.id,
nickname: pokemon.name,
species: pokemon.species,
item: pokemon.item,
ability: pokemon.ability,
teraType: pokemon.teraType ?? "",
nature: pokemon.nature,
form: null,
move1: pokemon.moves[0] ?? null,
move2: pokemon.moves[1] ?? null,
move3: pokemon.moves[2] ?? null,
move4: pokemon.moves[3] ?? null,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString(),
}));

const pokemonResult = await db
.insert(pokemon)
.values(pokemonList)
.returning();

return {
pokemonTeam: pokemonTeamResult[0],
pokemon: pokemonResult,
};

return BattleStadiumApiClient().POST("/pokemon_teams", pokemonOptions);
}
3 changes: 1 addition & 2 deletions packages/db/src/schemas/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export const accounts = pgTable(
imageUrl: text("image_url"),
admin: boolean().default(false).notNull(),
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
defaultProfileId: bigint("default_profile_id", { mode: "number" }),
defaultProfileId: bigint("default_profile_id", { mode: "bigint" }),
archivedAt: timestamp("archived_at", { precision: 6, mode: "string" }),
country: varchar(),
timezone: varchar(),
Expand Down
9 changes: 3 additions & 6 deletions packages/db/src/schemas/chat-messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ import { profiles } from "./profiles";
export const chatMessages = pgTable(
"chat_messages",
{
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
matchId: bigint("match_id", { mode: "number" }).notNull(),
matchId: bigint("match_id", { mode: "bigint" }).notNull(),
content: text(),
messageType: varchar("message_type"),
sentAt: timestamp("sent_at", { precision: 6, mode: "string" }),
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
accountId: bigint("account_id", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
profileId: bigint("profile_id", { mode: "number" }).notNull(),
accountId: bigint("account_id", { mode: "bigint" }),
profileId: bigint("profile_id", { mode: "bigint" }).notNull(),
},
(table) => {
return {
Expand Down
3 changes: 1 addition & 2 deletions packages/db/src/schemas/clerk-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ export const clerkUsers = pgTable(
precision: 6,
mode: "string",
}).notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
accountId: bigint("account_id", { mode: "number" }),
accountId: bigint("account_id", { mode: "bigint" }),
},
(table) => {
return {
Expand Down
3 changes: 1 addition & 2 deletions packages/db/src/schemas/formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ export const formats = pgTable(
{
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
name: varchar(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
gameId: bigint("game_id", { mode: "number" }),
gameId: bigint("game_id", { mode: "bigint" }),
createdAt: timestamp("created_at", {
precision: 6,
mode: "string",
Expand Down
12 changes: 4 additions & 8 deletions packages/db/src/schemas/match-games.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ export const matchGames = pgTable(
"match_games",
{
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
matchId: bigint("match_id", { mode: "number" }).notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
winnerId: bigint("winner_id", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
loserId: bigint("loser_id", { mode: "number" }),
matchId: bigint("match_id", { mode: "bigint" }).notNull(),
winnerId: bigint("winner_id", { mode: "bigint" }),
loserId: bigint("loser_id", { mode: "bigint" }),
createdAt: timestamp("created_at", {
precision: 6,
mode: "string",
Expand All @@ -33,8 +30,7 @@ export const matchGames = pgTable(
gameNumber: integer("game_number").default(1).notNull(),
endedAt: timestamp("ended_at", { precision: 6, mode: "string" }),
startedAt: timestamp("started_at", { precision: 6, mode: "string" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
reporterProfileId: bigint("reporter_profile_id", { mode: "number" }),
reporterProfileId: bigint("reporter_profile_id", { mode: "bigint" }),
},
(table) => {
return {
Expand Down
24 changes: 8 additions & 16 deletions packages/db/src/schemas/matches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,11 @@ export const matches = pgTable(
"matches",
{
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
roundId: bigint("round_id", { mode: "number" }).notNull(),
roundId: bigint("round_id", { mode: "bigint" }).notNull(),
tableNumber: integer("table_number"),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
playerOneId: bigint("player_one_id", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
playerTwoId: bigint("player_two_id", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
winnerId: bigint("winner_id", { mode: "number" }),
playerOneId: bigint("player_one_id", { mode: "bigint" }),
playerTwoId: bigint("player_two_id", { mode: "bigint" }),
winnerId: bigint("winner_id", { mode: "bigint" }),
createdAt: timestamp("created_at", {
precision: 6,
mode: "string",
Expand All @@ -45,16 +41,12 @@ export const matches = pgTable(
precision: 6,
mode: "string",
}),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
loserId: bigint("loser_id", { mode: "number" }),
loserId: bigint("loser_id", { mode: "bigint" }),
endedAt: timestamp("ended_at", { precision: 6, mode: "string" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
tournamentId: bigint("tournament_id", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
phaseId: bigint("phase_id", { mode: "number" }),
tournamentId: bigint("tournament_id", { mode: "bigint" }),
phaseId: bigint("phase_id", { mode: "bigint" }),
bye: boolean().default(false).notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
resetById: bigint("reset_by_id", { mode: "number" }),
resetById: bigint("reset_by_id", { mode: "bigint" }),
},
(table) => {
return {
Expand Down
6 changes: 2 additions & 4 deletions packages/db/src/schemas/organization-staff-members.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ export const organizationStaffMembers = pgTable(
"organization_staff_members",
{
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
organizationId: bigint("organization_id", { mode: "number" }).notNull(),
organizationId: bigint("organization_id", { mode: "bigint" }).notNull(),
createdAt: timestamp("created_at", {
precision: 6,
mode: "string",
Expand All @@ -24,8 +23,7 @@ export const organizationStaffMembers = pgTable(
precision: 6,
mode: "string",
}).notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
accountId: bigint("account_id", { mode: "number" }),
accountId: bigint("account_id", { mode: "bigint" }),
},
(table) => {
return {
Expand Down
6 changes: 2 additions & 4 deletions packages/db/src/schemas/organizations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ export const organizations = pgTable(
partner: boolean().default(false).notNull(),
hidden: boolean().default(false).notNull(),
slug: varchar(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
limitlessOrgId: bigint("limitless_org_id", { mode: "number" }),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
ownerId: bigint("owner_id", { mode: "number" }),
limitlessOrgId: bigint("limitless_org_id", { mode: "bigint" }),
ownerId: bigint("owner_id", { mode: "bigint" }),
},
(table) => {
return {
Expand Down
6 changes: 2 additions & 4 deletions packages/db/src/schemas/phase-players.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ export const phasePlayers = pgTable(
"phase_players",
{
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
playerId: bigint("player_id", { mode: "number" }).notNull(),
playerId: bigint("player_id", { mode: "bigint" }).notNull(),
phaseType: varchar("phase_type").notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
phaseId: bigint("phase_id", { mode: "number" }).notNull(),
phaseId: bigint("phase_id", { mode: "bigint" }).notNull(),
createdAt: timestamp("created_at", {
precision: 6,
mode: "string",
Expand Down
3 changes: 1 addition & 2 deletions packages/db/src/schemas/phases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export const phases = pgTable(
startedAt: timestamp("started_at", { precision: 6, mode: "string" }),
endedAt: timestamp("ended_at", { precision: 6, mode: "string" }),
order: integer().default(0).notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
currentRoundId: bigint("current_round_id", { mode: "number" }),
currentRoundId: bigint("current_round_id", { mode: "bigint" }),
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(table): Record<string, any> => {
Expand Down
9 changes: 3 additions & 6 deletions packages/db/src/schemas/pokemon-teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,11 @@ export const pokemonTeams = pgTable(
}).notNull(),
published: boolean().default(true).notNull(),
name: varchar(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
formatId: bigint("format_id", { mode: "number" }).notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
gameId: bigint("game_id", { mode: "number" }).notNull(),
formatId: bigint("format_id", { mode: "bigint" }).notNull(),
gameId: bigint("game_id", { mode: "bigint" }).notNull(),
archivedAt: timestamp("archived_at", { precision: 6, mode: "string" }),
pokepasteId: varchar("pokepaste_id"),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
profileId: bigint("profile_id", { mode: "number" }),
profileId: bigint("profile_id", { mode: "bigint" }),
},
(table) => {
return {
Expand Down
5 changes: 2 additions & 3 deletions packages/db/src/schemas/pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ export const pokemon = pgTable(
mode: "string",
}).notNull(),
nickname: varchar(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
pokemonTeamId: bigint("pokemon_team_id", { mode: "number" })
.default(0)
pokemonTeamId: bigint("pokemon_team_id", { mode: "bigint" })
.default(BigInt(0))
.notNull(),
form: varchar(),
position: integer().default(0).notNull(),
Expand Down
3 changes: 1 addition & 2 deletions packages/db/src/schemas/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export const profiles = pgTable(
}).notNull(),
imageUrl: varchar("image_url"),
slug: varchar(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
accountId: bigint("account_id", { mode: "number" }),
accountId: bigint("account_id", { mode: "bigint" }),
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
archivedAt: timestamp("archived_at", { precision: 6, mode: "string" }),
default: boolean().default(false).notNull(),
Expand Down
3 changes: 1 addition & 2 deletions packages/db/src/schemas/rounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ export const rounds = pgTable(
"rounds",
{
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
phaseId: bigint("phase_id", { mode: "number" }).notNull(),
phaseId: bigint("phase_id", { mode: "bigint" }).notNull(),
createdAt: timestamp("created_at", {
precision: 6,
mode: "string",
Expand Down
6 changes: 2 additions & 4 deletions packages/db/src/schemas/tournaments-formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ export const tournamentFormats = pgTable(
"tournament_formats",
{
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
tournamentId: bigint("tournament_id", { mode: "number" }).notNull(),
// You can use { mode: "bigint" } if numbers are exceeding js number limitations
formatId: bigint("format_id", { mode: "number" }).notNull(),
tournamentId: bigint("tournament_id", { mode: "bigint" }).notNull(),
formatId: bigint("format_id", { mode: "bigint" }).notNull(),
createdAt: timestamp("created_at", {
precision: 6,
mode: "string",
Expand Down
Loading

1 comment on commit 73805ee

@vercel
Copy link

@vercel vercel bot commented on 73805ee Nov 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.