Skip to content

Commit

Permalink
updates trivial instances of changed schema columns
Browse files Browse the repository at this point in the history
  • Loading branch information
xwilson03 committed Aug 3, 2024
1 parent 01a10b8 commit d37ffee
Show file tree
Hide file tree
Showing 23 changed files with 126 additions and 154 deletions.
12 changes: 6 additions & 6 deletions apps/bot/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import { serve } from "bun";
import c from "config";
import { db } from "db";
import { eq } from "db/drizzle";
import { discordVerification, users } from "db/schema";
import { discordVerification, userCommonData } from "db/schema";
import { nanoid } from "nanoid";
import { z } from "zod";

/* DISCORD BOT */

Expand Down Expand Up @@ -199,8 +198,9 @@ app.post("/api/checkDiscordVerification", async (h) => {
return h.json({ success: false });
}
console.log("got here 2");
const user = await db.query.users.findFirst({
where: eq(users.clerkID, verification.clerkID),
const user = await db.query.userCommonData.findFirst({
where: eq(userCommonData.clerkID, verification.clerkID),
with: { hackerData: true }
});
console.log("got here 2 with user", user);
if (!user) {
Expand All @@ -210,7 +210,7 @@ app.post("/api/checkDiscordVerification", async (h) => {

const { discordRole: userGroupRoleName } = (
c.groups as Record<string, { discordRole: string }>
)[Object.keys(c.groups)[user.group]];
)[Object.keys(c.groups)[user.hackerData.group]];

const guild = client.guilds.cache.get(verification.guild);
if (!guild) {
Expand All @@ -228,7 +228,7 @@ app.post("/api/checkDiscordVerification", async (h) => {
if (!role || !userGroupRole) {
console.log(
"failed cause could not find a role, was looking for group " +
user.group +
user.hackerData.group +
" called " +
userGroupRoleName,
);
Expand Down
12 changes: 6 additions & 6 deletions apps/web/src/actions/admin/user-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { adminAction } from "@/lib/safe-action";
import { z } from "zod";
import { perms } from "config";
import { users } from "db/schema";
import { userCommonData } from "db/schema";
import { db } from "db";
import { eq } from "db/drizzle";
import { revalidatePath } from "next/cache";
Expand All @@ -21,9 +21,9 @@ export const updateRole = adminAction(
throw new Error("You are not allowed to do this");
}
await db
.update(users)
.update(userCommonData)
.set({ role: roleToSet })
.where(eq(users.clerkID, userIDToUpdate));
.where(eq(userCommonData.clerkID, userIDToUpdate));
revalidatePath(`/admin/users/${userIDToUpdate}`);
return { success: true };
},
Expand All @@ -37,9 +37,9 @@ export const setUserApproval = adminAction(

async ({ userIDToUpdate, approved }, { user, userId }) => {
await db
.update(users)
.set({ approved })
.where(eq(users.clerkID, userIDToUpdate));
.update(userCommonData)
.set({ isApproved: approved })
.where(eq(userCommonData.clerkID, userIDToUpdate));
revalidatePath(`/admin/users/${userIDToUpdate}`);
return { success: true };
},
Expand Down
12 changes: 6 additions & 6 deletions apps/web/src/actions/rsvp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import { authenticatedAction } from "@/lib/safe-action";
import { z } from "zod";
import { db } from "db";
import { eq } from "db/drizzle";
import { users } from "db/schema";
import { userCommonData } from "db/schema";

export const rsvpMyself = authenticatedAction(
z.any(),
async (_, { userId }) => {
const user = await db.query.users.findFirst({
where: eq(users.clerkID, userId),
const user = await db.query.userCommonData.findFirst({
where: eq(userCommonData.clerkID, userId),
});
if (!user) throw new Error("User not found");
await db
.update(users)
.set({ rsvp: true })
.where(eq(users.clerkID, userId));
.update(userCommonData)
.set({ isRSVPed: true })
.where(eq(userCommonData.clerkID, userId));
return { success: true };
},
);
7 changes: 3 additions & 4 deletions apps/web/src/app/admin/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import Link from "next/link";
import { Button } from "@/components/shadcn/ui/button";
import DashNavItem from "@/components/dash/shared/DashNavItem";
import { eq } from "db/drizzle";
import { users } from "db/schema";
import { userCommonData } from "db/schema";
import FullScreenMessage from "@/components/shared/FullScreenMessage";
import ProfileButton from "@/components/shared/ProfileButton";
import { Suspense } from "react";
import ClientToast from "@/components/shared/ClientToast";
import { redirect } from "next/navigation";
import NavBarLinksGrouper from "@/components/shared/NavBarLinksGrouper";

interface AdminLayoutProps {
children: React.ReactNode;
Expand All @@ -25,8 +24,8 @@ export default async function AdminLayout({ children }: AdminLayoutProps) {
return redirect("/sign-in");
}

const user = await db.query.users.findFirst({
where: eq(users.clerkID, userId),
const user = await db.query.userCommonData.findFirst({
where: eq(userCommonData.clerkID, userId),
});

if (!user || (user.role !== "admin" && user.role !== "super_admin")) {
Expand Down
18 changes: 8 additions & 10 deletions apps/web/src/app/admin/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import {
} from "@/components/shadcn/ui/card";
import { db } from "db";
import { eq, desc } from "db/drizzle";
import { users } from "db/schema";
import { userCommonData } from "db/schema";
import { Users, UserCheck, User2, TimerReset, MailCheck } from "lucide-react";
import type { userType } from "@/lib/utils/shared/types";
import { unstable_cache } from "next/cache";
import { env } from "@/env";
import { auth } from "@clerk/nextjs";
import { notFound } from "next/navigation";

Expand All @@ -25,9 +23,9 @@ export default async function Page() {

if (!userId) return notFound();

const adminUser = await db.query.users.findFirst({
where: eq(users.clerkID, userId),
orderBy: desc(users.createdAt),
const adminUser = await db.query.userCommonData.findFirst({
where: eq(userCommonData.clerkID, userId),
orderBy: desc(userCommonData.signupTime),
});

if (
Expand Down Expand Up @@ -162,10 +160,10 @@ function getRecentRegistrationData(users: userType[]) {
}

for (const user of users) {
if (user.rsvp) rsvpCount++;
if (user.checkedIn) checkinCount++;
if (user.isRSVPed) rsvpCount++;
if (user.checkinTimestamp) checkinCount++;

const stamp = user.createdAt.toISOString().split("T")[0];
const stamp = user.signupTime.toISOString().split("T")[0];

if (recentSignupCount[stamp] != undefined) recentSignupCount[stamp]++;
}
Expand All @@ -174,7 +172,7 @@ function getRecentRegistrationData(users: userType[]) {
}

async function getUsers() {
const usersReq = await db.query.users.findMany();
const usersReq = await db.query.userCommonData.findMany();
return usersReq;
}

Expand Down
15 changes: 5 additions & 10 deletions apps/web/src/app/admin/users/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import { Button } from "@/components/shadcn/ui/button";
import { FolderInput } from "lucide-react";
import { DefaultPagination } from "@/components/admin/users/DefaultPagination";
import SearchBar from "@/components/admin/users/SearchBar";
import Filters from "../../../components/admin/users/Filters";
import { users } from "db/schema";
import { parseCheckBoxParams } from "@/lib/utils/shared/pageParams";
import { userCommonData } from "db/schema";

export default async function Page({
searchParams,
Expand All @@ -27,15 +25,12 @@ export default async function Page({
const end = maxPerPage + start;

// Might want to work with cache in prod to see if this will be plausible to do
const userData = await db.query.users.findMany({
with: {
registrationData: true,
profileData: true,
},
const userData = await db.query.userCommonData.findMany({
with: { hackerData: true },
where: and(
or(
ilike(users.firstName, `%${user}%`),
ilike(users.lastName, `%${user}%`),
ilike(userCommonData.firstName, `%${user}%`),
ilike(userCommonData.lastName, `%${user}%`),
),
),
});
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/app/api/admin/events/create/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { auth } from "@clerk/nextjs";
import { eq } from "db/drizzle";
import { db } from "db";
import { users, events } from "db/schema";
import { userCommonData, events } from "db/schema";
import { newEventValidator } from "@/validators/shared/newEvent";
import { BasicRedirValidator } from "@/validators/shared/basicRedir";
import { NextResponse } from "next/server";
Expand All @@ -14,8 +14,8 @@ export async function POST(req: Request) {

if (!userId) return new Response("Unauthorized", { status: 401 });

const reqUserRecord = await db.query.users.findFirst({
where: eq(users.clerkID, userId),
const reqUserRecord = await db.query.userCommonData.findFirst({
where: eq(userCommonData.clerkID, userId),
});

if (
Expand Down
16 changes: 6 additions & 10 deletions apps/web/src/app/api/admin/export/route.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { db } from "db";
import { eq } from "db/drizzle";
import { users } from "db/schema";
import { userCommonData } from "db/schema";
import { auth } from "@clerk/nextjs";

function escape(value: any) {
Expand Down Expand Up @@ -37,8 +37,8 @@ export async function GET() {

if (!userId) return new Response("Unauthorized", { status: 401 });

const reqUserRecord = await db.query.users.findFirst({
where: eq(users.clerkID, userId),
const reqUserRecord = await db.query.userCommonData.findFirst({
where: eq(userCommonData.clerkID, userId),
});

if (
Expand All @@ -48,19 +48,15 @@ export async function GET() {
return new Response("Unauthorized", { status: 401 });
}

const userTableData = await db.query.users.findMany({
with: {
registrationData: true,
profileData: true,
},
const userTableData = await db.query.userCommonData.findMany({
with: { hackerData: true },
});

const columed = 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.
let toRet: any = {
...user,
...user.registrationData,
...user.profileData,
...user.hackerData,
};
delete toRet.registrationData;
delete toRet.profileData;
Expand Down
13 changes: 7 additions & 6 deletions apps/web/src/app/api/team/create/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { auth } from "@clerk/nextjs";
import { NextResponse } from "next/server";
import { db } from "db";
import { eq } from "db/drizzle";
import { users, teams, errorLog } from "db/schema";
import { userCommonData, userHackerData, teams, errorLog } from "db/schema";
import { newTeamValidator } from "@/validators/shared/team";
import { nanoid } from "nanoid";
import c from "config";
Expand All @@ -12,12 +12,13 @@ export async function POST(req: Request) {
const { userId } = await auth();
if (!userId) return new Response("Unauthorized", { status: 401 });

const user = await db.query.users.findFirst({
where: eq(users.clerkID, userId),
const user = await db.query.userCommonData.findFirst({
where: eq(userCommonData.clerkID, userId),
with: {hackerData: true}
});
if (!user) return new Response("Unauthorized", { status: 401 });

if (user.teamID) {
if (user.hackerData.teamID) {
return NextResponse.json({
success: false,
message:
Expand Down Expand Up @@ -47,11 +48,11 @@ export async function POST(req: Request) {
ownerID: userId,
});
await tx
.update(users)
.update(userHackerData)
.set({
teamID,
})
.where(eq(users.clerkID, userId));
.where(eq(userHackerData.clerkID, userId));
});
return NextResponse.json({
success: true,
Expand Down
6 changes: 3 additions & 3 deletions apps/web/src/app/api/team/invite/decline/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { auth } from "@clerk/nextjs";
import { NextResponse } from "next/server";
import { z } from "zod";
import { db } from "db";
import { users, invites, teams } from "db/schema";
import { userCommonData, invites, teams } from "db/schema";
import { eq, and } from "db/drizzle";

const inviteDeclineValidator = z.object({
Expand All @@ -23,8 +23,8 @@ export async function POST(req: Request) {
});
}

const user = await db.query.users.findFirst({
where: eq(users.clerkID, userId),
const user = await db.query.userCommonData.findFirst({
where: eq(userCommonData.clerkID, userId),
with: {
invites: {
where: eq(invites.teamID, body.data.teamInviteID),
Expand Down
8 changes: 4 additions & 4 deletions apps/web/src/app/dash/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ClientToast from "@/components/shared/ClientToast";
import { TRPCReactProvider } from "@/trpc/react";
import { db } from "db";
import { eq } from "db/drizzle";
import { users } from "db/schema";
import { userCommonData } from "db/schema";

interface DashLayoutProps {
children: React.ReactNode;
Expand All @@ -25,15 +25,15 @@ export default async function DashLayout({ children }: DashLayoutProps) {
return redirect("/register");
}

const user = await db.query.users.findFirst({
where: eq(users.clerkID, clerkUser.id),
const user = await db.query.userCommonData.findFirst({
where: eq(userCommonData.clerkID, clerkUser.id),
});

if (!user) return redirect("/register");

if (
(c.featureFlags.core.requireUsersApproval as boolean) === true &&
user.approved === false &&
user.isApproved === false &&
user.role === "hacker"
) {
return redirect("/i/approval");
Expand Down
11 changes: 3 additions & 8 deletions apps/web/src/app/dash/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
// import { SignOutButton } from "@clerk/nextjs";
// import { Button } from "@/components/shadcn/ui/button";
// import { Suspense } from "react";
// import Loading from "@/components/shared/Loading";
import { auth } from "@clerk/nextjs";
import { db } from "db";
import { users } from "db/schema";
import { userCommonData } from "db/schema";
import { eq } from "db/drizzle";
import c from "config";
import superjson from "superjson";
import { createQRpayload } from "@/lib/utils/shared/qr";

// HackKit Bubbles
Expand All @@ -22,8 +17,8 @@ import {
export default async function Page() {
const { userId } = auth();
if (!userId) return null;
const user = await db.query.users.findFirst({
where: eq(users.clerkID, userId),
const user = await db.query.userCommonData.findFirst({
where: eq(userCommonData.clerkID, userId),
});
if (!user) return null;

Expand Down
Loading

0 comments on commit d37ffee

Please sign in to comment.