Skip to content

Commit

Permalink
cataloging
Browse files Browse the repository at this point in the history
  • Loading branch information
thatguyinabeanie committed Nov 8, 2024
1 parent fcf13f3 commit bdcdcf4
Show file tree
Hide file tree
Showing 27 changed files with 4,414 additions and 110 deletions.
Empty file added apps/nextjs/env.ts
Empty file.
20 changes: 19 additions & 1 deletion apps/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,33 @@
"@clerk/backend": "^1.15.1",
"@clerk/clerk-react": "^5.13.1",
"@clerk/nextjs": "^6.0.2",
"@t3-oss/env-nextjs": "^0.11.1",
"@t3-oss/env-nextjs": "catalog:",
"@tanstack/react-query": "catalog:",
"@trpc/client": "catalog:",
"@trpc/react-query": "catalog:",
"@trpc/server": "catalog:",
"@tsparticles/engine": "^3.5.0",
"@tsparticles/react": "^3.0.0",
"@tsparticles/slim": "^3.5.0",
"@uploadthing/react": "^7.1.0",
"@vercel/analytics": "^1.3.2",
"@vercel/functions": "^1.5.0",
"@vercel/kv": "^3.0.0",
"@vercel/speed-insights": "^1.0.14",
"cookie": "^1.0.1",
"discord-api-types": "^0.37.103",
"discord-interactions": "^4.1.0",
"discord.js": "^14.16.3",
"geist": "^1.3.1",
"jose": "^5.9.6",
"js-cookie": "^3.0.5",
"next": "^14.2.15",
"next-themes": "catalog:",
"openapi-fetch": "^0.13.0",
"openapi-typescript-helpers": "^0.0.15",
"react": "catalog:react18",
"react-dom": "catalog:react18",
"server-only": "^0.0.1",
"superjson": "2.2.1",
"zod": "catalog:"
},
Expand Down
54 changes: 54 additions & 0 deletions apps/nextjs/src/app/server-actions/accounts/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
"use server";

import { BattleStadiumApiClient, defaultConfig } from "~/lib/api";
import { type paths } from "~/lib/api/openapi-v1";
import { auth } from "@clerk/nextjs/server";
import { type FetchOptions } from "openapi-fetch";

export async function getAccounts(
options?: FetchOptions<paths["/accounts"]["get"]>,
) {
const usersOptions = {
...defaultConfig("listUsers"),
...options,
};
const skipClerkAuth = true;

return (await BattleStadiumApiClient(skipClerkAuth)).GET(
"/accounts",
usersOptions,
);
}

export async function getAccount(
username: string,
options?: FetchOptions<paths["/accounts/{username}"]["get"]>,
) {
const userOptions = {
...defaultConfig(`getUser-${username}`),
...options,
params: { path: { username } },
};

return (await BattleStadiumApiClient()).GET(
"/accounts/{username}",
userOptions,
);
}

export async function getAccountMe(
options?: FetchOptions<paths["/accounts/me"]["get"]>,
) {
const { userId } = await auth();

if (!userId) {
return null;
}

const userMeOptions = {
...defaultConfig(`getAccountMe(${userId})`),
...options,
};

return (await BattleStadiumApiClient()).GET("/accounts/me", userMeOptions);
}
49 changes: 49 additions & 0 deletions apps/nextjs/src/app/server-actions/organizations/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"use server";

import { BattleStadiumApiClient, defaultConfig } from "~/lib/api";
import { type paths } from "~/lib/api/openapi-v1";
import { type FetchOptions } from "openapi-fetch";

export async function getOrganizations(
options?: FetchOptions<paths["/organizations"]["get"]>,
) {
const organizationsOptions = {
...defaultConfig("getOrganizations"),
...options,
params: {
query: {
page: options?.params?.query?.page ?? 0,
per_page: options?.params?.query?.per_page ?? 20,
},
},
};
const skipClerkAuth = true;

const resp = await (
await BattleStadiumApiClient(skipClerkAuth)
).GET("/organizations", organizationsOptions);
const allOrgs = resp.data?.data;
const partnerOrgs = (allOrgs ?? [])?.filter((org) => org.partner);
const nonPartnerOrgs = (allOrgs ?? [])?.filter((org) => !org.partner);

return {
partners: partnerOrgs,
nonpartners: nonPartnerOrgs,
};
}

export async function getOrganization(
slug: string,
options?: FetchOptions<paths["/organizations/{slug}"]["get"]>,
) {
const organizationOptions = {
...defaultConfig(`getOrganization(${slug})`),
...options,
params: { path: { slug } },
};

return (await BattleStadiumApiClient()).GET(
"/organizations/{slug}",
organizationOptions,
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"use server";

import { BattleStadiumApiClient, defaultConfig } from "~/lib/api";
import { type paths } from "~/lib/api/openapi-v1";
import { type FetchOptions } from "openapi-fetch";

export async function getOrganizationTournaments(
slug: string,
options?: FetchOptions<paths["/organizations/{slug}/tournaments"]["get"]>,
) {
const organizationTournamentsOptions = {
...defaultConfig(`getOrganizationTournaments(${slug})`),
...options,
params: {
path: { slug },
...options?.params,
},
};

const tours =
(
await (
await BattleStadiumApiClient()
).GET("/organizations/{slug}/tournaments", organizationTournamentsOptions)
).data ?? [];
return tours;
}
81 changes: 81 additions & 0 deletions apps/nextjs/src/app/server-actions/pokemon/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
"use server";

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

type 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(
options?: FetchOptions<paths["/pokemon_teams"]["get"]>,
) {
const pokemonOptions = {
...defaultConfig("getPokemonList"),
...options,
};

return (await BattleStadiumApiClient()).GET("/pokemon_teams", pokemonOptions);
}

export async function postPokemonTeam(
validatedTeam: ValidatedPokemon[],
metadata: PokePasteMetadata,
options?: FetchOptions<paths["/pokemon_teams"]["post"]>,
) {
const body: PostPokemonTeamBody = {
pokepaste_id: metadata.id,
profile_id: 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,
})),
};

const pokemonOptions = {
...defaultConfig("postPokemonTeam"),
...options,
body,
};

return (await BattleStadiumApiClient()).POST(
"/pokemon_teams",
pokemonOptions,
);
}
62 changes: 62 additions & 0 deletions apps/nextjs/src/app/server-actions/profiles/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"use server";

import { BattleStadiumApiClient, defaultConfig } from "~/lib/api";
import { type paths } from "~/lib/api/openapi-v1";
import { revalidateTag } from "next/cache";
import { type FetchOptions } from "openapi-fetch";

export async function getProfiles(
options?: FetchOptions<paths["/profiles"]["get"]>,
) {
const profilesOptions = {
...defaultConfig("getPlayerProfiles"),
...options,
};

return (await BattleStadiumApiClient()).GET("/profiles", profilesOptions);
}

export async function getProfilesByAccountId(
id: number,
options?: FetchOptions<paths["/profiles"]["get"]>,
) {
const profileOptions = {
...defaultConfig(`getPlayerProfileByAccountId-${id}`),
...options,
params: {
query: {
account_id: id,
},
},
};

const profiles =
(await (await BattleStadiumApiClient()).GET("/profiles", profileOptions))
.data ?? [];

return profiles;
}

export async function createProfile(
username: string,
accountId: number,
options?: FetchOptions<paths["/profiles"]["post"]>,
) {
const profileOptions = {
...defaultConfig("postPlayerProfile"),
...options,
params: {
query: {
user_name: username,
},
},
};

const resp = (
await (await BattleStadiumApiClient()).POST("/profiles", profileOptions)
).data;

revalidateTag(`getPlayerProfileByAccountId-${accountId}`);

return { success: true, resp };
}
Loading

0 comments on commit bdcdcf4

Please sign in to comment.