-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: forum - upvote | downvote | saved
- Loading branch information
1 parent
58377d7
commit 9545be4
Showing
7 changed files
with
303 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { getServerSession } from 'next-auth'; | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
import startDb from '@/lib/db'; | ||
import Forum from '@/models/Forum'; | ||
import { authOptions } from '../../auth/[...nextauth]/authOptions'; | ||
import { UserDataTypes } from '../../auth/[...nextauth]/next-auth.interfaces'; | ||
|
||
export const maxDuration = 60; | ||
export const dynamic = 'force-dynamic'; | ||
|
||
export async function POST(req: NextRequest) { | ||
try { | ||
const session: UserDataTypes | null = await getServerSession(authOptions); | ||
if (!session?.user) { | ||
return NextResponse.json({ error: 'You are not authorized' }, { status: 401 }); | ||
} | ||
const body = await req.json(); | ||
await startDb(); | ||
const forum = await Forum.create({ ...body, user: session?.user._id }); | ||
return NextResponse.json(forum, { status: 200 }); | ||
} catch (error: any) { | ||
return NextResponse.json({ error: error?.message }, { status: 500 }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.