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.
* lint fix * types * updated more actions to use drizzle db * fix some linting whining about stuff * prettier
- Loading branch information
1 parent
5516126
commit 2b3b2e8
Showing
15 changed files
with
144 additions
and
135 deletions.
There are no files selected for viewing
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
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
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
61 changes: 41 additions & 20 deletions
61
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 |
---|---|---|
@@ -1,29 +1,50 @@ | ||
"use server"; | ||
|
||
import type { FetchOptions } from "openapi-fetch"; | ||
import { and, db, desc, eq } from "@battle-stadium/db"; | ||
import { organizations, tournaments } from "@battle-stadium/db/schema"; | ||
|
||
import type { paths } from "~/lib/api/openapi-v1"; | ||
import { BattleStadiumApiClient, defaultConfig } from "~/lib/api"; | ||
function tournamentsLeftJoinOrganizations() { | ||
return db | ||
.select() | ||
.from(tournaments) | ||
.leftJoin(organizations, eq(tournaments.organizationId, organizations.id)); | ||
} | ||
|
||
export async function getOrganizationTournaments(page = 1, pageSize = 20) { | ||
return await tournamentsLeftJoinOrganizations() | ||
.orderBy(desc(tournaments.startAt)) | ||
.limit(pageSize) | ||
.offset((page - 1) * pageSize); | ||
} | ||
|
||
export async function getOrganizationTournaments( | ||
export async function getSingleOrganizationTournaments( | ||
slug: string, | ||
options?: FetchOptions<paths["/organizations/{slug}/tournaments"]["get"]>, | ||
page = 1, | ||
pageSize = 20, | ||
) { | ||
const organizationTournamentsOptions = { | ||
...defaultConfig(`getOrganizationTournaments(${slug})`), | ||
...options, | ||
params: { | ||
path: { slug }, | ||
...options?.params, | ||
}, | ||
const results = await tournamentsLeftJoinOrganizations() | ||
.where(eq(organizations.slug, slug)) | ||
.orderBy(desc(tournaments.startAt)) | ||
.limit(pageSize) | ||
.offset((page - 1) * pageSize); | ||
|
||
return { | ||
tournaments: results.map(({ tournaments }) => tournaments), | ||
organization: results[0]?.organizations, | ||
}; | ||
} | ||
|
||
const tours = | ||
( | ||
await BattleStadiumApiClient().GET( | ||
"/organizations/{slug}/tournaments", | ||
organizationTournamentsOptions, | ||
) | ||
).data ?? []; | ||
return tours; | ||
export async function getSingleOrganizationSingleTournament( | ||
slug: string, | ||
tournamentId: bigint, | ||
) { | ||
const results = await tournamentsLeftJoinOrganizations() | ||
.where(and(eq(organizations.slug, slug), eq(tournaments.id, tournamentId))) | ||
.orderBy(desc(tournaments.startAt)) | ||
.limit(1); | ||
|
||
return { | ||
tournament: results[0]?.tournaments, | ||
organization: results[0]?.organizations, | ||
}; | ||
} |
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
Oops, something went wrong.
2b3b2e8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
nextjs – ./
nextjs-battlestadium.vercel.app
www.battlestadium.gg
nextjs-git-main-battlestadium.vercel.app
battlestadium.gg