Connect, collaborate, and grow with a community of TypeScript developers
Better db than what trash did (#130)
Sean Boult6a44a9113285
diff --git a/prisma/challenges.mock.ts b/prisma/challenges.mock.tsindex 078e3626..8eb15191 100644--- a/prisma/challenges.mock.ts+++ b/prisma/challenges.mock.ts@@ -31,7 +31,7 @@ export const CHALLENGE_MAP: Record<name: `Beginner Challenge ${challengeIndex + 1}`,createdAt: new Date(),updatedAt: new Date(),- Bookmark: randomTrueOrFalse()+ bookmark: randomTrueOrFalse()? {create: {userId: randomTrueOrFalse() ? trashId : gId,diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 78233b6c..8cf3f4f4 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -79,16 +79,16 @@ model User {image String?accounts Account[]sessions Session[]- Challenge Challenge[]- Vote Vote[]- Solution Solution[]- Report Report[]- Bookmark Bookmark[]- SharedSolution SharedSolution[]- Comment ChallengeComment[]- Reply ChallengeReply[]- SolutionComment SolutionComment[]- SolutionReply SolutionReply[]+ challenge Challenge[]+ vote Vote[]+ solution Solution[]+ report Report[]+ bookmark Bookmark[]+ sharedSolution SharedSolution[]+ comment ChallengeComment[]+ reply ChallengeReply[]+ solutionComment SolutionComment[]+ solutionReply SolutionReply[]}model VerificationToken {@@ -110,12 +110,12 @@ model Challenge {prompt String @db.MediumTextuser User @relation(fields: [userId], references: [id])userId String- Vote Vote[]- Solution Solution[]- Comment ChallengeComment[]- Report Report[]- Bookmark Bookmark[]- SharedSolution SharedSolution[]+ vote Vote[]+ solution Solution[]+ comment ChallengeComment[]+ report Report[]+ bookmark Bookmark[]+ sharedSolution SharedSolution[]@@index([userId])}@@ -128,7 +128,7 @@ model Vote {challengeId Int?solution Solution? @relation(fields: [solutionId], references: [id])solutionId Int?- SharedSolution SharedSolution? @relation(fields: [sharedSolutionId], references: [id])+ sharedSolution SharedSolution? @relation(fields: [sharedSolutionId], references: [id])sharedSolutionId Int?@@index([userId])@@ -141,12 +141,12 @@ model SharedSolution {createdAt DateTime @default(now())title Stringdescription String @db.MediumText- Vote Vote[]- User User? @relation(fields: [userId], references: [id])+ vote Vote[]+ user User? @relation(fields: [userId], references: [id])userId String?- Challenge Challenge? @relation(fields: [challengeId], references: [id])+ challenge Challenge? @relation(fields: [challengeId], references: [id])challengeId Int?- SolutionComment SolutionComment[]+ solutionComment SolutionComment[]@@index([userId])@@index([challengeId])@@ -161,7 +161,7 @@ model Solution {userId Stringchallenge Challenge @relation(fields: [challengeId], references: [id])challengeId Int- Vote Vote[]+ vote Vote[]@@index([userId])@@index([challengeId])@@ -199,7 +199,7 @@ model SolutionComment {solution SharedSolution @relation(fields: [solutionId], references: [id])solutionId Inttext String- SolutionReply SolutionReply[]+ solutionReply SolutionReply[]@@index([userId])@@index([solutionId])diff --git a/prisma/seed.ts b/prisma/seed.tsindex add4dcce..f74aeb95 100644--- a/prisma/seed.ts+++ b/prisma/seed.ts@@ -28,7 +28,7 @@ try {id: trashId,email: '[email protected]',name: 'chris',- Challenge: challenges(),+ challenge: challenges(),},});@@ -39,7 +39,7 @@ try {id: gId,email: '[email protected]',name: 'g',- Challenge: challenges(),+ challenge: challenges(),},});diff --git a/src/app/create/preview/page.tsx b/src/app/create/preview/page.tsxindex b2064680..b7aaa8e0 100644--- a/src/app/create/preview/page.tsx+++ b/src/app/create/preview/page.tsx@@ -63,7 +63,7 @@ export default function PreviewCreatedChallenge() {<ExploreCardchallenge={{...createChallengeStore.data,- _count: { Vote: 420 },+ _count: { vote: 420 },updatedAt: new Date(),difficulty: 'BEGINNER',}}diff --git a/src/components/challenge/description-panel.tsx b/src/components/challenge/description-panel.tsxindex 46636247..03b4f83b 100644--- a/src/components/challenge/description-panel.tsx+++ b/src/components/challenge/description-panel.tsx@@ -49,9 +49,9 @@ export type FormValues = {export function DescriptionPanel({ challenge }: Props) {const router = useRouter();- const [votes, setVotes] = useState(challenge._count.Vote);- const [hasVoted, setHasVoted] = useState(challenge.Vote.length > 0);- const [hasBookmarked, setHasBookmarked] = useState(challenge.Bookmark.length > 0);+ const [votes, setVotes] = useState(challenge._count.vote);+ const [hasVoted, setHasVoted] = useState(challenge.vote.length > 0);+ const [hasBookmarked, setHasBookmarked] = useState(challenge.bookmark.length > 0);const session = useSession();const debouncedSearch = useRef(debounce(async (challengeId: number, userId: string, shouldIncrement: boolean) => {diff --git a/src/components/challenge/editor/index.tsx b/src/components/challenge/editor/index.tsxindex 18082fe9..a0746170 100644--- a/src/components/challenge/editor/index.tsx+++ b/src/components/challenge/editor/index.tsx@@ -49,7 +49,7 @@ const LIB_URI = 'ts:filename/checking.d.ts';type Props = (| {mode: 'solve';- challenge: Pick<NonNullable<Challenge>, 'Solution' | 'prompt' | 'id'>;+ challenge: Pick<NonNullable<Challenge>, 'solution' | 'prompt' | 'id'>;prompt?: never;}| {@@ -93,7 +93,7 @@ export const CodePanel = (props: Props) => {if (props.mode !== 'solve') return props.prompt ?? '';// if a user has an existing solution use that instead of prompt- const usersExistingSolution = props.challenge.Solution?.[0];+ const usersExistingSolution = props.challenge.solution?.[0];if (!usersExistingSolution) {return props.challenge.prompt;@@ -103,7 +103,7 @@ export const CodePanel = (props: Props) => {const parsedUserSolution = usersExistingSolution?.code;return `${appendSolutionToThis ?? ''}${separator ?? ''}${parsedUserSolution}`;- }, [props.challenge?.Solution, props.challenge?.prompt, props.mode, props.prompt]);+ }, [props.challenge?.solution, props.challenge?.prompt, props.mode, props.prompt]);const [code, setCode] = useState(defaultCode);diff --git a/src/components/challenge/increment.action.ts b/src/components/challenge/increment.action.tsindex cceca3fb..87ad6a7e 100644--- a/src/components/challenge/increment.action.ts+++ b/src/components/challenge/increment.action.ts@@ -32,10 +32,10 @@ export async function incrementOrDecrementUpvote(where: { id: challengeId },include: {_count: {- select: { Vote: true },+ select: { vote: true },},},});- return count?._count.Vote;+ return count?._count.vote;}diff --git a/src/components/challenge/index.tsx b/src/components/challenge/index.tsxindex 9588d24a..10bede37 100644--- a/src/components/challenge/index.tsx+++ b/src/components/challenge/index.tsx@@ -33,21 +33,21 @@ async function getChallenge(id: string, session: Session | null) {where: { id: +id },include: {_count: {- select: { Vote: true },+ select: { vote: true },},- Vote: {+ vote: {where: {userId: session?.user.id,challengeId: +id,},},- Bookmark: {+ bookmark: {where: {userId: session?.user.id,challengeId: +id,},},- Solution: {+ solution: {where: {userId: session?.user.id,challengeId: +id,@@ -59,7 +59,7 @@ async function getChallenge(id: string, session: Session | null) {],take: 10,},- SharedSolution: {+ sharedSolution: {where: {challengeId: +id,},diff --git a/src/components/challenge/solutions/index.tsx b/src/components/challenge/solutions/index.tsxindex 1169410c..668c00ae 100644--- a/src/components/challenge/solutions/index.tsx+++ b/src/components/challenge/solutions/index.tsx@@ -17,7 +17,7 @@ interface Props {challenge: NonNullable<Challenge>;}export function Solutions({ challenge }: Props) {- const hasSolution = challenge.Solution?.length > 0;+ const hasSolution = challenge.solution?.length > 0;const [openSolutionEditor, setOpenSolutionEditor] = useState(false);const handleClick = () => {diff --git a/src/components/challenge/solutions/solution-editor.tsx b/src/components/challenge/solutions/solution-editor.tsxindex 339f1f81..6cc0fb6a 100644--- a/src/components/challenge/solutions/solution-editor.tsx+++ b/src/components/challenge/solutions/solution-editor.tsx@@ -41,7 +41,7 @@ export function SolutionEditor({ setOpen, challenge }: Props) {const form = useForm<FormSchema>({resolver: zodResolver(formSchema),defaultValues: {- content: getDefaultMarkdown(challenge.Solution[0]?.code ?? ''),+ content: getDefaultMarkdown(challenge.solution[0]?.code ?? ''),},});const { toast } = useToast();diff --git a/src/components/challenge/submissions.tsx b/src/components/challenge/submissions.tsxindex f3c9a24f..affcea45 100644--- a/src/components/challenge/submissions.tsx+++ b/src/components/challenge/submissions.tsx@@ -21,7 +21,7 @@ interface Props {type Status = 'all' | 'accepted' | 'rejected';export function Submissions({ challenge }: Props) {const [selectedStatus, setSelectStatus] = useState<Status>('all');- const submissions = challenge.Solution;+ const submissions = challenge.solution;const filteredSubmissions = useMemo(() => {const predicate = (submission: Solution) => {diff --git a/src/components/explore/explore-card.tsx b/src/components/explore/explore-card.tsxindex 482d442a..1bebdc87 100644--- a/src/components/explore/explore-card.tsx+++ b/src/components/explore/explore-card.tsx@@ -61,7 +61,7 @@ export function ExploreCard({ challenge }: Props) {</div><div className="ml-4 flex items-center justify-center text-center"><ThumbsUp size={20} className="mr-2" />- <span>{challenge._count.Vote}</span>+ <span>{challenge._count.vote}</span></div></div><div>{getRelativeTime(challenge.updatedAt)}</div>diff --git a/src/components/explore/index.tsx b/src/components/explore/index.tsxindex 86fadd43..e21e8c2c 100644--- a/src/components/explore/index.tsx+++ b/src/components/explore/index.tsx@@ -32,7 +32,7 @@ async function getChallenge() {return prisma.challenge.findMany({include: {_count: {- select: { Vote: true },+ select: { vote: true },},},});diff --git a/src/components/user/dashboard/index.tsx b/src/components/user/dashboard/index.tsxindex ecda1041..fcbf3649 100644--- a/src/components/user/dashboard/index.tsx+++ b/src/components/user/dashboard/index.tsx@@ -19,7 +19,7 @@ async function getUserdata(id: string) {id,},include: {- Solution: {+ solution: {where: {userId: id},@@ -130,7 +130,7 @@ export default async function Dashboard({ user }: Props) {<CardTitle>Solutions</CardTitle></CardHeader><CardContent className="pl-2">- <SolutionsTab solutions={userData?.Solution} />+ <SolutionsTab solutions={userData.solution} /></CardContent></Card></div>diff --git a/src/components/user/dashboard/solutions-tab.tsx b/src/components/user/dashboard/solutions-tab.tsxindex a4d16ac2..7701f909 100644--- a/src/components/user/dashboard/solutions-tab.tsx+++ b/src/components/user/dashboard/solutions-tab.tsx@@ -10,7 +10,7 @@ import {import { UserData } from '.';import Link from 'next/link';-export function SolutionsTab({ solutions = [] }: { solutions: UserData['Solution'] }) {+export function SolutionsTab({ solutions = [] }: { solutions: UserData['solution'] }) {return (<Table><TableCaption>A list of your recent challenges.</TableCaption>diff --git a/tsconfig.json b/tsconfig.jsonindex 2fd286bc..6819231f 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -36,17 +36,19 @@".eslintrc.cjs","next-env.d.ts","*.ts",- "./scripts/*.js",- "./scripts/*.mjs",- "./scripts/*.cjs",+ "./scripts/*.js",+ "./scripts/*.mjs",+ "./scripts/*.cjs","./src/**/*.ts","./src/**/*.tsx","./src/**/*.cjs","./src/**/*.mjs",- ".next/types/**/*.ts"-, "scripts/dl-monaco.mjs" ],+ ".next/types/**/*.ts",+ "scripts/dl-monaco.mjs",+ "./prisma/*.ts"+ ],"exclude": ["node_modules",- "*.d.ts",+ "*.d.ts"]}