Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Autumn-Ou committed Jun 1, 2023
1 parent 34bd425 commit 574edf8
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 91 deletions.
15 changes: 8 additions & 7 deletions pages/api/@me/favourites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,14 @@ export default async function getUserFavourites(
if (req.body) {
const body = JSON.parse(req.body);

const existingTeam: FavouritedTeam | null = await db.favouritedTeam.findUnique({
where: {
// @ts-ignore
userId: session.user.id,
team_number: body.team_number,
},
});
const existingTeam: FavouritedTeam | null =
await db.favouritedTeam.findUnique({
where: {
// @ts-ignore
userId: session.user.id,
team_number: body.team_number,
},
});

if (existingTeam) {
res.status(200).send("Team already favorited");
Expand Down
37 changes: 22 additions & 15 deletions pages/api/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ import { NextApiRequest, NextApiResponse } from "next";
import { tbaAxios } from "@/lib/fetchTBA";
import db from "@/lib/db";
import { Match, Prisma } from "@prisma/client";
import {AxiosResponse} from "axios";
import { AxiosResponse } from "axios";

export default async function getDistricts(
req: NextApiRequest,
res: NextApiResponse
): Promise<void> {
const { event } = req.query;
const eventData: AxiosResponse<any, any> = await tbaAxios.get(`/event/${event}`);
const matches: AxiosResponse<any, any> = await tbaAxios.get(`/event/${event}/matches`);
const eventData: AxiosResponse<any, any> = await tbaAxios.get(
`/event/${event}`
);
const matches: AxiosResponse<any, any> = await tbaAxios.get(
`/event/${event}/matches`
);

const formattedMatchesData = matches.data.map((match: Match) => {
return {
Expand All @@ -34,22 +38,25 @@ export default async function getDistricts(
where: { key: String(event) },
});

const existingMatchKeys: Set<string | null> = new Set(existingMatches.map((match: Match) => match.key));
const existingMatchKeys: Set<string | null> = new Set(
existingMatches.map((match: Match) => match.key)
);
const newMatches = formattedMatchesData.filter(
(match: any) => !existingMatchKeys.has(match.key)
);

const updatePromises: (Prisma.Prisma__MatchClient<Match> | undefined)[] = existingMatches.map((existingMatch: Match) => {
const newMatchData = formattedMatchesData.find(
(match: any): boolean => match.key === existingMatch.key
);
if (newMatchData) {
return db.match.update({
where: { id: existingMatch.id },
data: newMatchData,
});
}
});
const updatePromises: (Prisma.Prisma__MatchClient<Match> | undefined)[] =
existingMatches.map((existingMatch: Match) => {
const newMatchData = formattedMatchesData.find(
(match: any): boolean => match.key === existingMatch.key
);
if (newMatchData) {
return db.match.update({
where: { id: existingMatch.id },
data: newMatchData,
});
}
});

await Promise.all(updatePromises);

Expand Down
12 changes: 7 additions & 5 deletions pages/api/seed/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,13 @@ const addTeamsToEvents = async (): Promise<boolean> => {
},
data: {
teams: {
connect: participatingTeams.data.map((teamKey: string): {team_number : number} => {
return {
team_number: parseInt(teamKey.substring(3)),
};
}),
connect: participatingTeams.data.map(
(teamKey: string): { team_number: number } => {
return {
team_number: parseInt(teamKey.substring(3)),
};
}
),
},
},
});
Expand Down
5 changes: 3 additions & 2 deletions pages/api/teams/events.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import db from "@/lib/db";
import { NextApiRequest, NextApiResponse } from "next";
import { CURR_YEAR } from "@/lib/constants";
import {Match, Team} from "@prisma/client";
import { Match, Team } from "@prisma/client";

export default async function getDistricts(
req: NextApiRequest,
Expand Down Expand Up @@ -63,7 +63,8 @@ export default async function getDistricts(
eventMatches: JSON.parse(
JSON.stringify(
eventMatches,
(key: string, value) => (typeof value === "bigint" ? value.toString() : value) // return everything else unchanged
(key: string, value) =>
typeof value === "bigint" ? value.toString() : value // return everything else unchanged
)
),
});
Expand Down
4 changes: 2 additions & 2 deletions pages/api/teams/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ export default async function getDistricts(
},
},
}),
await fetch(`${API_URL}/api/teams/socials?team=${team}`).then((res: Response) =>
res.json()
await fetch(`${API_URL}/api/teams/socials?team=${team}`).then(
(res: Response) => res.json()
),
]);

Expand Down
17 changes: 9 additions & 8 deletions pages/api/teams/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@ import { AxiosResponse } from "axios";
import { CURR_YEAR } from "@/lib/constants";
import { fetchFIRST } from "@/lib/fetchFIRST";
import db from "@/lib/db";
import {Team, Event} from "@prisma/client";
import { Team, Event } from "@prisma/client";

export default async function getTeamInfo(
req: NextApiRequest,
res: NextApiResponse
): Promise<void> {
const { team } = req.query;
const teamEvents: (Team & {events: Event[]}) | null = await db.team.findUnique({
where: { team_number: Number(team) },
include: {
events: {
where: { year: CURR_YEAR },
const teamEvents: (Team & { events: Event[] }) | null =
await db.team.findUnique({
where: { team_number: Number(team) },
include: {
events: {
where: { year: CURR_YEAR },
},
},
},
});
});
const events: Event[] | undefined = teamEvents?.events;

const currentEvent: Event | undefined = events
Expand Down
21 changes: 11 additions & 10 deletions pages/event/[event]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import Head from "next/head";
import db from "@/lib/db";
import { AwardsTab } from "@/components/tabs/event/Awards";
import { useSession } from "next-auth/react";
import {Session, getServerSession, User} from "next-auth";
import { Session, getServerSession, User } from "next-auth";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import {FavouritedTeam} from "@prisma/client";
import { FavouritedTeam } from "@prisma/client";

export default function EventsPage({
user,
Expand Down Expand Up @@ -158,14 +158,15 @@ export const getServerSideProps: GetServerSideProps = async (
]);

if (session) {
const user: (User & {favouritedTeams: FavouritedTeam[]}) | null = await db.user.findUnique({
where: {
id: session.user.id,
},
include: {
favouritedTeams: true,
},
});
const user: (User & { favouritedTeams: FavouritedTeam[] }) | null =
await db.user.findUnique({
where: {
id: session.user.id,
},
include: {
favouritedTeams: true,
},
});

return {
props: {
Expand Down
36 changes: 20 additions & 16 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,22 +110,24 @@ export const getServerSideProps: GetServerSideProps = async ({

if (COMP_SEASON) {
await Promise.all(
user?.favouritedTeams.map(async (team: FavouritedTeam): Promise<void> => {
try {
const data = await fetch(
`${API_URL}/api/teams/next?team=${team.team_number}`,
{
next: {
revalidate: 3600,
},
}
).then((res: Response) => res.json());

teamsCurrentlyCompeting[team.team_number] = data;
} catch {
teamsCurrentlyCompeting[team.team_number] = null;
user?.favouritedTeams.map(
async (team: FavouritedTeam): Promise<void> => {
try {
const data = await fetch(
`${API_URL}/api/teams/next?team=${team.team_number}`,
{
next: {
revalidate: 3600,
},
}
).then((res: Response) => res.json());

teamsCurrentlyCompeting[team.team_number] = data;
} catch {
teamsCurrentlyCompeting[team.team_number] = null;
}
}
})
)
);
}
}
Expand All @@ -137,7 +139,9 @@ export const getServerSideProps: GetServerSideProps = async ({
const nextWeekDate: Date = new Date(
currentDate.getTime() + 7 * 24 * 60 * 60 * 1000
);
const formattedNextWeekDate:string = nextWeekDate.toISOString().slice(0, 10);
const formattedNextWeekDate: string = nextWeekDate
.toISOString()
.slice(0, 10);

const eventsThisWeek: Event[] = await db.event.findMany({
where: {
Expand Down
21 changes: 18 additions & 3 deletions pages/insights.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import db from "@/lib/db";
import Link from "next/link";
import { JSX, useEffect, useState } from "react";
import { MostPointsTable } from "../components/insights/MostPointsTable";
import {Award, Match, Team} from "@prisma/client";
import { Award, Match, Team } from "@prisma/client";

export default function InsightsPage({
insights,
Expand Down Expand Up @@ -216,7 +216,21 @@ export default function InsightsPage({
);
}

export async function getServerSideProps(): Promise<{props: {insights: any, totalMatches: number, totalEvents: number, totalTeams: number, top10Teams: {teamNumber: string, name: string | null | undefined, numAwards: number}[], mostQualMatchPts: any, mostPlayoffMatchPts: any}}> {
export async function getServerSideProps(): Promise<{
props: {
insights: any;
totalMatches: number;
totalEvents: number;
totalTeams: number;
top10Teams: {
teamNumber: string;
name: string | null | undefined;
numAwards: number;
}[];
mostQualMatchPts: any;
mostPlayoffMatchPts: any;
};
}> {
const insightsData = await fetch(`${API_URL}/api/insights`).then(
(res: Response) => res.json()
);
Expand Down Expand Up @@ -280,7 +294,8 @@ export async function getServerSideProps(): Promise<{props: {insights: any, tot
return JSON.parse(
JSON.stringify(
{ withPenaltyData, withoutPenaltyData },
(key: string, value) => (typeof value === "bigint" ? value.toString() : value) // return everything else unchanged
(key: string, value) =>
typeof value === "bigint" ? value.toString() : value // return everything else unchanged
)
);
};
Expand Down
12 changes: 3 additions & 9 deletions pages/privacy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Header } from "@/components/Header";
import { Navbar } from "@/components/navbar";
import { JSX } from "react";
import { Card } from "@/components/misc/Card";
import {DISCORD_URL, GITHUB_URL} from "@/lib/constants";
import { DISCORD_URL, GITHUB_URL } from "@/lib/constants";

export default function PrivacyPage(): JSX.Element {
return (
Expand Down Expand Up @@ -126,17 +126,11 @@ export default function PrivacyPage(): JSX.Element {
<p className="text-lightGray">
If you have any questions about this Privacy Policy, please contact
us on the{" "}
<a
href={GITHUB_URL}
className="text-white"
>
<a href={GITHUB_URL} className="text-white">
Scout Machine GitHub Repository
</a>
, or reach out to us on the{" "}
<a
href={DISCORD_URL}
className="text-white"
>
<a href={DISCORD_URL} className="text-white">
{" "}
Scout Machine Discord{" "}
</a>
Expand Down
21 changes: 11 additions & 10 deletions pages/team/[team]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import { TeamMembersTab } from "@/components/tabs/team/TeamMembers";
import { EventsTab } from "@/components/tabs/team/Events";
import { useSession } from "next-auth/react";
import { authOptions } from "@/pages/api/auth/[...nextauth]";
import {Session, getServerSession, User} from "next-auth";
import { Session, getServerSession, User } from "next-auth";
import db from "@/lib/db";
import {FavouritedTeam} from "@prisma/client";
import { FavouritedTeam } from "@prisma/client";

const SubInfo = (props: any) => {
return (
Expand Down Expand Up @@ -400,14 +400,15 @@ export const getServerSideProps: GetServerSideProps = async (

if (teamInfo) {
if (session) {
const user: (User & {favouritedTeams: FavouritedTeam[]}) | null = await db.user.findUnique({
where: {
id: session.user.id,
},
include: {
favouritedTeams: true,
},
});
const user: (User & { favouritedTeams: FavouritedTeam[] }) | null =
await db.user.findUnique({
where: {
id: session.user.id,
},
include: {
favouritedTeams: true,
},
});

return {
props: {
Expand Down
2 changes: 1 addition & 1 deletion pages/team/[team]/live.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function LiveFieldViewPage({ next }: any): null {

export const getServerSideProps: GetServerSideProps = async (
context: GetServerSidePropsContext
): Promise<{props: {next: any}}> => {
): Promise<{ props: { next: any } }> => {
const { team }: any = context.params;

const nextMatch = await fetch(`${API_URL}/api/teams/next?team=${team}`).then(
Expand Down
7 changes: 4 additions & 3 deletions pages/users/[username]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export default function UserProfilePage({ user }: any) {

const handleGenerateApiKey = async (): Promise<void> => {
try {
await fetch("/api/@me/apiKeys", { method: "POST" }).then((res: Response) =>
res.json()
await fetch("/api/@me/apiKeys", { method: "POST" }).then(
(res: Response) => res.json()
);
router.push(router.asPath);
notify("API key generated successfully!", <FaCheck />);
Expand Down Expand Up @@ -59,7 +59,8 @@ export default function UserProfilePage({ user }: any) {
});
};

const isOwnProfile: boolean | null = session && user.username == session.user.username;
const isOwnProfile: boolean | null =
session && user.username == session.user.username;

return (
<>
Expand Down

1 comment on commit 574edf8

@vercel
Copy link

@vercel vercel bot commented on 574edf8 Jun 1, 2023

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.