From 4c901d073376ab9fd37284801011a12261d5963d Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Tue, 6 Feb 2024 13:12:21 +0000 Subject: Linting and formatting --- web/app/api/auth/[...nextauth]/route.tsx | 2 +- web/app/api/v1/links/route.ts | 105 ++++++++++++++++--------------- 2 files changed, 57 insertions(+), 50 deletions(-) (limited to 'web/app/api') diff --git a/web/app/api/auth/[...nextauth]/route.tsx b/web/app/api/auth/[...nextauth]/route.tsx index bfcda516..e722926b 100644 --- a/web/app/api/auth/[...nextauth]/route.tsx +++ b/web/app/api/auth/[...nextauth]/route.tsx @@ -1,3 +1,3 @@ import { authHandler } from "@/lib/auth"; -export { authHandler as GET, authHandler as POST } +export { authHandler as GET, authHandler as POST }; diff --git a/web/app/api/v1/links/route.ts b/web/app/api/v1/links/route.ts index 5be1018e..97bfa3de 100644 --- a/web/app/api/v1/links/route.ts +++ b/web/app/api/v1/links/route.ts @@ -1,60 +1,67 @@ import { authOptions } from "@/lib/auth"; import prisma from "@/lib/prisma"; -import { ZNewBookmarkedLinkRequest, ZGetLinksResponse, ZBookmarkedLink } from "@/lib/types/api/links"; +import { + ZNewBookmarkedLinkRequest, + ZGetLinksResponse, + ZBookmarkedLink, +} from "@/lib/types/api/links"; import { getServerSession } from "next-auth"; import { NextRequest, NextResponse } from "next/server"; export async function POST(request: NextRequest) { - // TODO: We probably should be using an API key here instead of the session; - const session = await getServerSession(authOptions); - if (!session) { - return new Response(null, { status: 401 }); - } - - const linkRequest = ZNewBookmarkedLinkRequest.safeParse(await request.json()); - - if (!linkRequest.success) { - return NextResponse.json({ - error: linkRequest.error.toString(), - }, { status: 400 }); - } - - const link = await prisma.bookmarkedLink.create({ - data: { - url: linkRequest.data.url, - userId: session.user.id, - } - }); - - let response: ZBookmarkedLink = { ...link }; - - return NextResponse.json(response, { status: 201 }); + // TODO: We probably should be using an API key here instead of the session; + const session = await getServerSession(authOptions); + if (!session) { + return new Response(null, { status: 401 }); + } + + const linkRequest = ZNewBookmarkedLinkRequest.safeParse(await request.json()); + + if (!linkRequest.success) { + return NextResponse.json( + { + error: linkRequest.error.toString(), + }, + { status: 400 }, + ); + } + + const link = await prisma.bookmarkedLink.create({ + data: { + url: linkRequest.data.url, + userId: session.user.id, + }, + }); + + let response: ZBookmarkedLink = { ...link }; + + return NextResponse.json(response, { status: 201 }); } export async function GET() { - // TODO: We probably should be using an API key here instead of the session; - const session = await getServerSession(authOptions); - if (!session) { - return new Response(null, { status: 401 }); - } - const links = await prisma.bookmarkedLink.findMany({ - where: { - userId: session.user.id, - }, + // TODO: We probably should be using an API key here instead of the session; + const session = await getServerSession(authOptions); + if (!session) { + return new Response(null, { status: 401 }); + } + const links = await prisma.bookmarkedLink.findMany({ + where: { + userId: session.user.id, + }, + select: { + id: true, + url: true, + createdAt: true, + details: { select: { - id: true, - url: true, - createdAt: true, - details: { - select: { - title: true, - description: true, - imageUrl: true, - } - }, - } - }); - - let response: ZGetLinksResponse = { links }; - return NextResponse.json(response); + title: true, + description: true, + imageUrl: true, + }, + }, + }, + }); + + let response: ZGetLinksResponse = { links }; + return NextResponse.json(response); } -- cgit v1.2.3-70-g09d2