generated from warmachine028/github-super-starter-kit
-
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.
- Loading branch information
1 parent
6b96de1
commit 76431e8
Showing
8 changed files
with
230 additions
and
130 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { validateRequest } from '@/auth' | ||
import { prisma } from '@/lib' | ||
import { getNotificationDataInclude, NotificationsPage } from '@/types' | ||
import { NextRequest } from 'next/server' | ||
|
||
export const GET = async (req: NextRequest) => { | ||
try { | ||
const cursor = req.nextUrl.searchParams.get('cursor') || undefined | ||
const pageSize = 10 | ||
const { user } = await validateRequest() | ||
|
||
if (!user) { | ||
return Response.json({ error: 'Unauthorized' }, { status: 401 }) | ||
} | ||
const notifications = await prisma.notification.findMany({ | ||
where: { recipientId: user.id }, | ||
include: getNotificationDataInclude(), | ||
orderBy: { createdAt: 'desc' }, | ||
take: pageSize + 1, | ||
cursor: cursor ? { id: cursor } : undefined | ||
}) | ||
const nextCursor = | ||
notifications.length > pageSize ? notifications[pageSize].id : null | ||
const data: NotificationsPage = { | ||
notifications: notifications.slice(0, pageSize), | ||
nextCursor | ||
} | ||
|
||
return Response.json(data) | ||
} catch (error) { | ||
console.error(error) | ||
return Response.json({ error: 'Internal server error' }, { 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
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
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.
76431e8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
next-book – ./
next-book-pritam-kundu.vercel.app
nextife.vercel.app
next-book-15.vercel.app
next-book-git-main-pritam-kundu.vercel.app
nextifly.vercel.app
next-book-pritam.vercel.app
next-boook.vercel.app