generated from t3-oss/create-t3-turbo
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fcf13f3
commit bdcdcf4
Showing
27 changed files
with
4,414 additions
and
110 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
49
apps/nextjs/src/app/server-actions/organizations/actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} |
27 changes: 27 additions & 0 deletions
27
apps/nextjs/src/app/server-actions/organizations/tournaments/actions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; | ||
} |
Oops, something went wrong.