Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

chore: remove api route (#659)

bautistaaaedb31780c53c
diff --git a/apps/web/src/app/[locale]/challenge/[id]/submissions/_components/overview.tsx b/apps/web/src/app/[locale]/challenge/[id]/submissions/_components/overview.tsx
index cd407c2a..6898fe03 100644
--- a/apps/web/src/app/[locale]/challenge/[id]/submissions/_components/overview.tsx
+++ b/apps/web/src/app/[locale]/challenge/[id]/submissions/_components/overview.tsx
@@ -1,17 +1,18 @@
-import { useQuery } from '@tanstack/react-query';
-import { Copy, X } from '@repo/ui/icons';
-import Link from 'next/link';
-import { getBaseUrl } from '~/utils/getBaseUrl';
-import { getRelativeTime } from '~/utils/relativeTime';
import { Button } from '@repo/ui/components/button';
-import { toast } from '@repo/ui/components/use-toast';
+import { Markdown } from '@repo/ui/components/markdown';
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from '@repo/ui/components/tooltip';
-import { Markdown } from '@repo/ui/components/markdown';
+import { toast } from '@repo/ui/components/use-toast';
+import { Copy, X } from '@repo/ui/icons';
+import { useQuery } from '@tanstack/react-query';
+import Link from 'next/link';
+import { getBaseUrl } from '~/utils/getBaseUrl';
+import { getRelativeTime } from '~/utils/relativeTime';
+import { getChallengeSubmissionById } from '../getChallengeSubmissions';
interface Props {
submissionId: string;
@@ -24,7 +25,7 @@ ${code} \`\`\``;
export function SubmissionOverview({ submissionId }: Props) {
const { data: submission } = useQuery({
queryKey: ['submission', submissionId],
- queryFn: () => getSubmission(submissionId),
+ queryFn: () => getChallengeSubmissionById(submissionId),
});
const code = codifyForMarkdown(submission?.code.trimStart() ?? '');
@@ -78,7 +79,3 @@ export function SubmissionOverview({ submissionId }: Props) {
</>
);
}
-
-async function getSubmission(id: string) {
- return fetch(`${getBaseUrl()}/api/submissions/${id}`).then((res) => res.json());
-}
diff --git a/apps/web/src/app/[locale]/challenge/[id]/submissions/getChallengeSubmissions.ts b/apps/web/src/app/[locale]/challenge/[id]/submissions/getChallengeSubmissions.ts
index 839cd22e..6636c2bb 100644
--- a/apps/web/src/app/[locale]/challenge/[id]/submissions/getChallengeSubmissions.ts
+++ b/apps/web/src/app/[locale]/challenge/[id]/submissions/getChallengeSubmissions.ts
@@ -1,9 +1,11 @@
+'use server';
+
import { cache } from 'react';
import { prisma } from '@repo/db';
export type ChallengeSubmissions = NonNullable<Awaited<ReturnType<typeof getChallengeSubmissions>>>;
-export const getChallengeSubmissions = cache(async (userId: string, challengeId: string) => {
- const solutions = await prisma.submission.findMany({
+export const getChallengeSubmissions = cache((userId: string, challengeId: string) => {
+ return prisma.submission.findMany({
where: { challengeId: Number(challengeId), userId },
orderBy: [
{
@@ -11,6 +13,12 @@ export const getChallengeSubmissions = cache(async (userId: string, challengeId:
},
],
});
+});
- return solutions;
+export const getChallengeSubmissionById = cache((id: string) => {
+ return prisma.submission.findFirst({
+ where: {
+ id: Number(id),
+ },
+ });
});
diff --git a/apps/web/src/app/api/submissions/[id]/route.ts b/apps/web/src/app/api/submissions/[id]/route.ts
deleted file mode 100644
index 62071ee6..00000000
--- a/apps/web/src/app/api/submissions/[id]/route.ts
+++ /dev/null
@@ -1,12 +0,0 @@
-import { NextResponse } from 'next/server';
-import { prisma } from '@repo/db';
-
-export async function GET(request: Request, { params }: { params: { id: string } }) {
- const submission = await prisma.submission.findFirst({
- where: {
- id: Number(params.id),
- },
- });
-
- return NextResponse.json(submission);
-}