Skip to content

Commit

Permalink
Lint fix (#5)
Browse files Browse the repository at this point in the history
* lint fix

* types

* updated more actions to use drizzle db

* fix some linting whining about stuff

* prettier
  • Loading branch information
thatguyinabeanie authored Nov 10, 2024
1 parent 5516126 commit 2b3b2e8
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 135 deletions.
1 change: 1 addition & 0 deletions apps/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"sort-packages": "pnpx sort-package-json",
"start": "pnpm with-env next start",
"typecheck": "tsc --noEmit",
"typecheck:watch": "pnpm typecheck --watch",
"vercel:pull": "vercel env pull .env.development.local",
"with-env": "dotenv -e ../../.env --"
},
Expand Down
12 changes: 6 additions & 6 deletions apps/nextjs/src/app/organizations/[org_slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
getOrganization,
getOrganizations,
} from "~/app/server-actions/organizations/actions";
import { getOrganizationTournaments } from "~/app/server-actions/organizations/tournaments/actions";
import { getSingleOrganizationTournaments } from "~/app/server-actions/organizations/tournaments/actions";
import OrganizationHeader from "~/components/organizations/organization-header";

export const revalidate = 200;
Expand All @@ -30,7 +30,7 @@ export async function generateMetadata(
export async function generateStaticParams() {
const orgs = await getOrganizations();

return orgs.map(({ slug }) => ({ org_slug: slug }));
return orgs.filter((org) => org.slug).map((org) => ({ org_slug: org.slug }));
}

// const columns = [
Expand Down Expand Up @@ -65,14 +65,14 @@ export default async function OrganizationDetailPage(
props: Readonly<OrganizationDetailPageProps>,
) {
const params = await props.params;
const organization = await getOrganization(params.org_slug);
const { organization, tournaments } = await getSingleOrganizationTournaments(
params.org_slug,
);

if (!organization) {
return <div>404 - Not Found</div>;
}

const tournaments = await getOrganizationTournaments(params.org_slug);

return (
<>
<OrganizationHeader organization={organization}>
Expand All @@ -87,7 +87,7 @@ export default async function OrganizationDetailPage(
{tournaments.map((tournament) => (
<div key={tournament.id}>
<h3>{tournament.name}</h3>
<p>{tournament.start_at}</p>
<p>{tournament.startAt}</p>
</div>
))}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import Link from "next/link";
import { Chip } from "@battle-stadium/ui";

import type { OrganizationTournamentProps } from "~/types";
import { getOrganization } from "~/app/server-actions/organizations/actions";
import {
getTournament,
getTournaments,
} from "~/app/server-actions/tournaments/actions";
getOrganizationTournaments,
getSingleOrganizationSingleTournament,
} from "~/app/server-actions/organizations/tournaments/actions";
import { getTournament } from "~/app/server-actions/tournaments/actions";
import OrganizationHeader from "~/components/organizations/organization-header";

export const revalidate = 300;
Expand All @@ -17,17 +17,17 @@ export async function generateMetadata(
props: Readonly<OrganizationTournamentProps>,
) {
const params = await props.params;
const tournament = (await getTournament(params.tournament_id)).data;
const tournament = await getTournament(params.tournament_id);

return { title: tournament?.name ?? "Tournament" };
}

export async function generateStaticParams() {
const tournaments = (await getTournaments()).data?.data ?? [];
const results = await getOrganizationTournaments(1, 500);

return tournaments.map(({ organization, id }) => ({
org_slug: organization.slug,
tournament_id: id.toString(),
return results.map(({ tournaments, organizations }) => ({
org_slug: organizations?.slug,
tournament_id: tournaments.id.toString(),
}));
}

Expand All @@ -36,15 +36,10 @@ export default async function OrganizationTournament(
) {
const params = await props.params;
const { org_slug, tournament_id } = params;
const tournament = (await getTournament(tournament_id)).data;
const { organization, tournament } =
await getSingleOrganizationSingleTournament(org_slug, tournament_id);

if (!tournament) {
return <div>404 - Not Found</div>;
}

const organization = await getOrganization(tournament.organization.slug);

if (!organization) {
if (!organization || !tournament) {
return <div>404 - Not Found</div>;
}

Expand All @@ -61,9 +56,9 @@ export default async function OrganizationTournament(

<div className="pt-2" />

<p>Registration: {tournament.registration_start_at}</p>
<p>Starts: {tournament.start_at}</p>
<p>Check in opens: {tournament.check_in_start_at} </p>
<p>Registration: {tournament.registrationStartAt}</p>
<p>Starts: {tournament.startAt}</p>
<p>Check in opens: {tournament.checkInStartAt} </p>

<div className="pt-2" />
</div>
Expand All @@ -88,7 +83,7 @@ export default async function OrganizationTournament(

interface TournamentDetailChipsProps {
org_slug: string;
tournament_id: number;
tournament_id: bigint;
}
function TournamentDetailChips(props: Readonly<TournamentDetailChipsProps>) {
const { org_slug, tournament_id } = props;
Expand Down
7 changes: 2 additions & 5 deletions apps/nextjs/src/app/server-actions/accounts/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

import { auth } from "@clerk/nextjs/server";

import type { Account } from "@battle-stadium/db/schema";
import { db, eq } from "@battle-stadium/db";
import { accounts, clerkUsers, profiles } from "@battle-stadium/db/schema";

export async function getAccounts() {
return await db.query.accounts.findMany();
}

export async function getAccount(
username: string,
): Promise<Account | null | undefined> {
export async function getAccount(username: string) {
const profile = await db.query.profiles.findFirst({
where: eq(profiles.username, username),
});
Expand All @@ -26,7 +23,7 @@ export async function getAccount(
});
}

export async function getAccountMe(): Promise<Account | null | undefined> {
export async function getAccountMe() {
const { userId } = await auth();

if (!userId) {
Expand Down
5 changes: 2 additions & 3 deletions apps/nextjs/src/app/server-actions/organizations/actions.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
"use server";

import type { Organization } from "@battle-stadium/db/schema";
import { eq } from "@battle-stadium/db";
import { db } from "@battle-stadium/db/client";
import { organizations } from "@battle-stadium/db/schema";

export async function getOrganizations(): Promise<Organization[]> {
export async function getOrganizations() {
const orgs = await db.query.organizations.findMany();
return orgs;
}

export async function getPartneredOrganizations(): Promise<Organization[]> {
export async function getPartneredOrganizations() {
const orgs = await db.query.organizations.findMany({
where: eq(organizations.partner, true),
});
Expand Down
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,
};
}
49 changes: 16 additions & 33 deletions apps/nextjs/src/app/server-actions/tournaments/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,25 @@

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

import { db, eq } from "@battle-stadium/db";
import { tournaments } from "@battle-stadium/db/schema";

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

export async function getTournament(
tournament_id: number,
options?: FetchOptions<paths["/tournaments/{tournament_id}"]["get"]>,
) {
const tournamentOptions = {
...defaultConfig(`getTournament(${tournament_id})`),
...options,
params: { path: { tournament_id } },
};

return BattleStadiumApiClient().GET(
"/tournaments/{tournament_id}",
tournamentOptions,
);
export async function getTournament(tournament_id: bigint) {
return await db.query.tournaments.findFirst({
with: { organization: true },
where: eq(tournaments.id, BigInt(tournament_id)),
});
}

export async function getTournaments(
page = 0,
per_page = 20,
options?: FetchOptions<paths["/tournaments"]["get"]>,
) {
const tournamentsOptions = {
...defaultConfig("getTournaments"),
...options,
params: { query: { page, per_page } },
};

const skipClerkAuth = true;

return BattleStadiumApiClient(skipClerkAuth).GET(
"/tournaments",
tournamentsOptions,
);
export async function getTournaments(page = 1, pageSize = 20) {
return await db.query.tournaments.findMany({
orderBy: (tournaments, { desc }) => desc(tournaments.startAt),
limit: pageSize,
offset: (page - 1) * pageSize,
});
}

export async function postTournamentRegistration(
Expand Down Expand Up @@ -79,13 +62,13 @@ export async function postTournamentRegistration(
}

export async function getTournamentPlayers(
tournament_id: number,
tournament_id: bigint,
options?: FetchOptions<paths["/tournaments/{tournament_id}/players"]["get"]>,
) {
const tournamentPlayersOptions = {
...defaultConfig(`getTournamentPlayers(${tournament_id})`),
...options,
params: { path: { tournament_id } },
params: { path: { tournament_id: Number(tournament_id) } },
};

const resp = await BattleStadiumApiClient().GET(
Expand Down
Loading

1 comment on commit 2b3b2e8

@vercel
Copy link

@vercel vercel bot commented on 2b3b2e8 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.