Skip to content

Commit

Permalink
runs formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
xwilson03 committed Aug 22, 2024
1 parent 3a7bf22 commit c1b7e7c
Show file tree
Hide file tree
Showing 13 changed files with 117 additions and 95 deletions.
4 changes: 2 additions & 2 deletions apps/web/src/actions/rsvp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { z } from "zod";
import { db } from "db";
import { eq } from "db/drizzle";
import { userCommonData } from "db/schema";
import { getUser } from "db/functions"
import { getUser } from "db/functions";

export const rsvpMyself = authenticatedAction(
z.any(),
async (_, { userId }) => {
const user = await getUser(userId);
if (!user) throw new Error("User not found");
if (!user) throw new Error("User not found");

await db
.update(userCommonData)
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/actions/user-profile-mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const modifyAccountSettings = authenticatedAction(
async ({ firstName, lastName }, { userId }) => {
const user = await getUser(userId);
if (!user) throw new Error("User not found");

await db
.update(userCommonData)
.set({ firstName, lastName })
Expand Down
45 changes: 23 additions & 22 deletions apps/web/src/app/admin/check-in/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,30 @@ export default async function Page({
}: {
searchParams: { [key: string]: string | undefined };
}) {
if (!searchParams.user)
return (
<div>
<CheckinScanner
hasScanned={false}
checkedIn={null}
scanUser={null}
hasRSVP={null}
/>
</div>
);

if (!searchParams.user) return (
<div>
<CheckinScanner
hasScanned={false}
checkedIn={null}
scanUser={null}
hasRSVP={null}
/>
</div>
);

const scanUser = await getUser(searchParams.user);
if (!scanUser) return (
<div>
<CheckinScanner
hasScanned={true}
checkedIn={null}
scanUser={null}
hasRSVP={null}
/>
</div>
);
const scanUser = await getUser(searchParams.user);
if (!scanUser)
return (
<div>
<CheckinScanner
hasScanned={true}
checkedIn={null}
scanUser={null}
hasRSVP={null}
/>
</div>
);

return (
<div>
Expand Down
8 changes: 5 additions & 3 deletions apps/web/src/app/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ import { notFound } from "next/navigation";
import { getAllUsers, getUser } from "db/functions";

export default async function Page() {

const { userId } = auth();
if (!userId) return notFound();

const adminUser = await getUser(userId);
if (!adminUser || (adminUser.role !== "admin" && adminUser.role !== "super_admin")) {
if (
!adminUser ||
(adminUser.role !== "admin" && adminUser.role !== "super_admin")
) {
return notFound();
}

const allUsers = await getAllUsers() ?? [];
const allUsers = (await getAllUsers()) ?? [];

const { rsvpCount, checkinCount, recentSignupCount } =
getRecentRegistrationData(allUsers);
Expand Down
17 changes: 9 additions & 8 deletions apps/web/src/app/admin/scanner/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ export default async function Page({
);
}

const scanUser = await getHacker(searchParams.user, false);
const scanUser = await getHacker(searchParams.user, false);

const scan = (!scanUser) ? null :
await db.query.scans.findFirst({
where: and(
eq(scans.eventID, event.id),
eq(scans.userID, scanUser.clerkID),
),
});
const scan = !scanUser
? null
: await db.query.scans.findFirst({
where: and(
eq(scans.eventID, event.id),
eq(scans.userID, scanUser.clerkID),
),
});

return (
<div>
Expand Down
5 changes: 4 additions & 1 deletion apps/web/src/app/api/admin/events/create/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ export async function POST(req: Request) {
if (!userId) return new Response("Unauthorized", { status: 401 });

const reqUserRecord = await getUser(userId);
if (!reqUserRecord || (reqUserRecord.role !== "super_admin" && reqUserRecord.role !== "admin")) {
if (
!reqUserRecord ||
(reqUserRecord.role !== "super_admin" && reqUserRecord.role !== "admin")
) {
return new Response("Unauthorized", { status: 401 });
}

Expand Down
7 changes: 5 additions & 2 deletions apps/web/src/app/api/admin/export/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ export async function GET() {
if (!userId) return new Response("Unauthorized", { status: 401 });

const reqUserRecord = await getUser(userId);
if (!reqUserRecord || (reqUserRecord.role !== "super_admin" && reqUserRecord.role !== "admin")) {
if (
!reqUserRecord ||
(reqUserRecord.role !== "super_admin" && reqUserRecord.role !== "admin")
) {
return new Response("Unauthorized", { status: 401 });
}

const userTableData = await getAllHackers() ?? [];
const userTableData = (await getAllHackers()) ?? [];

const flattenedUsers = userTableData.map((user) => {
// TODO: Have to use any here to avoid type errors as we reshape the data. Could be fixed with a better type definition.
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/app/settings/account/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getHacker } from "db/functions";

export default async function Page() {
const { userId } = auth();
if (!userId) return redirect("/sign-in");
if (!userId) return redirect("/sign-in");

const user = await getHacker(userId, false);
if (!user) return redirect("/sign-in");
Expand Down
6 changes: 1 addition & 5 deletions apps/web/src/components/schedule/EventFull.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ import Balancer from "react-wrap-balancer";
import { formatInTimeZone } from "date-fns-tz";
import { Event } from "db/types";

export default function EventFull({
event,
}: {
event: Event;
}) {
export default function EventFull({ event }: { event: Event }) {
return (
<div className="relative w-screen">
<div
Expand Down
71 changes: 43 additions & 28 deletions packages/db/functions/hacker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,62 @@ import { db, eq, sql } from "..";
import { userCommonData } from "../schema";
import { Hacker } from "../types";


const _getAllHackers = db.query.userCommonData.findMany({
with: { hackerData: true }
}).prepare("getAllHackers");
const _getAllHackers = db.query.userCommonData
.findMany({
with: { hackerData: true },
})
.prepare("getAllHackers");

export function getAllHackers(): Promise<Hacker[] | undefined> {
return _getAllHackers.execute();
return _getAllHackers.execute();
}

// ID

const _getHackerByIDWithTeam = db.query.userCommonData
.findFirst({
where: eq(userCommonData.clerkID, sql.placeholder('_clerkID')),
with: { hackerData: { with: { team: true } } }
}).prepare("getHackerByIDWithTeam");
.findFirst({
where: eq(userCommonData.clerkID, sql.placeholder("_clerkID")),
with: { hackerData: { with: { team: true } } },
})
.prepare("getHackerByIDWithTeam");

const _getHackerByIDAlone = db.query.userCommonData
.findFirst({
where: eq(userCommonData.clerkID, sql.placeholder('_clerkID')),
with: { hackerData: true }
}).prepare("getHackerByID");

export function getHacker(clerkID: string, withTeam: boolean) : Promise<Hacker | undefined> {
return (withTeam) ? _getHackerByIDWithTeam.execute({_clerkID: clerkID}) : _getHackerByIDAlone.execute({_clerkID: clerkID});
.findFirst({
where: eq(userCommonData.clerkID, sql.placeholder("_clerkID")),
with: { hackerData: true },
})
.prepare("getHackerByID");

export function getHacker(
clerkID: string,
withTeam: boolean,
): Promise<Hacker | undefined> {
return withTeam
? _getHackerByIDWithTeam.execute({ _clerkID: clerkID })
: _getHackerByIDAlone.execute({ _clerkID: clerkID });
}

// Tag

const _getHackerByTagWithTeam = db.query.userCommonData
.findFirst({
where: eq(userCommonData.hackerTag, sql.placeholder('_hackerTag')),
with: { hackerData: { with: { team: true } } }
}).prepare("getHackerByTagWithTeam");
.findFirst({
where: eq(userCommonData.hackerTag, sql.placeholder("_hackerTag")),
with: { hackerData: { with: { team: true } } },
})
.prepare("getHackerByTagWithTeam");

const _getHackerByTagAlone = db.query.userCommonData
.findFirst({
where: eq(userCommonData.hackerTag, sql.placeholder('_hackerTag')),
with: { hackerData: true }
}).prepare("getHackerByTag");

export function getHackerByTag(hackerTag: string, withTeam: boolean) : Promise<Hacker | undefined> {
return (withTeam) ? _getHackerByTagWithTeam.execute({_hackerTag: hackerTag}) : _getHackerByTagAlone.execute({_hackerTag: hackerTag});
}
.findFirst({
where: eq(userCommonData.hackerTag, sql.placeholder("_hackerTag")),
with: { hackerData: true },
})
.prepare("getHackerByTag");

export function getHackerByTag(
hackerTag: string,
withTeam: boolean,
): Promise<Hacker | undefined> {
return withTeam
? _getHackerByTagWithTeam.execute({ _hackerTag: hackerTag })
: _getHackerByTagAlone.execute({ _hackerTag: hackerTag });
}
4 changes: 2 additions & 2 deletions packages/db/functions/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from "./user"
export * from "./hacker"
export * from "./user";
export * from "./hacker";
27 changes: 14 additions & 13 deletions packages/db/functions/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,32 @@ import { db, eq, sql } from "..";
import { userCommonData } from "../schema";
import { User } from "../types";


const _getAllUsers = db.query.userCommonData.findMany().prepare("getAllUsers");

export function getAllUsers(): Promise<User[] | undefined> {
return _getAllUsers.execute();
return _getAllUsers.execute();
}

// ID

const _getUser = db.query.userCommonData
.findFirst({
where: eq(userCommonData.clerkID, sql.placeholder('_clerkID')),
}).prepare("getUser");
.findFirst({
where: eq(userCommonData.clerkID, sql.placeholder("_clerkID")),
})
.prepare("getUser");

export function getUser(clerkID: string) : Promise<User | undefined> {
return _getUser.execute({_clerkID: clerkID});
export function getUser(clerkID: string): Promise<User | undefined> {
return _getUser.execute({ _clerkID: clerkID });
}

// Tag

const _getUserByTag = db.query.userCommonData
.findFirst({
where: eq(userCommonData.hackerTag, sql.placeholder('_hackerTag')),
}).prepare("getUserByTag");
.findFirst({
where: eq(userCommonData.hackerTag, sql.placeholder("_hackerTag")),
})
.prepare("getUserByTag");

export function getUserByTag(hackerTag: string) : Promise<User | undefined> {
return _getUserByTag.execute({_hackerTag: hackerTag});
}
export function getUserByTag(hackerTag: string): Promise<User | undefined> {
return _getUserByTag.execute({ _hackerTag: hackerTag });
}
14 changes: 7 additions & 7 deletions packages/db/types.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { InferSelectModel } from "drizzle-orm";
import { userCommonData, userHackerData, teams, scans, events } from "./schema";

export interface Scan extends InferSelectModel<typeof scans> {};
export interface User extends InferSelectModel<typeof userCommonData> {};
export interface Team extends InferSelectModel<typeof teams> {};
export interface Event extends InferSelectModel<typeof events> {};
export interface Scan extends InferSelectModel<typeof scans> {}
export interface User extends InferSelectModel<typeof userCommonData> {}
export interface Team extends InferSelectModel<typeof teams> {}
export interface Event extends InferSelectModel<typeof events> {}

export interface Hacker extends User {
hackerData: typeof userHackerData.$inferSelect & {
team?: Team | null;
hackerData: typeof userHackerData.$inferSelect & {
team?: Team | null;
};
}
}

0 comments on commit c1b7e7c

Please sign in to comment.