-
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: search by alternative titles in dashboard
- Loading branch information
1 parent
32aa82b
commit 2889822
Showing
4 changed files
with
71 additions
and
7 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,36 @@ | ||
import { validateSessionToken } from '@/server/auth/validateSession'; | ||
import prisma from '@/server/db'; | ||
import { NextRequest } from 'next/server'; | ||
|
||
export const GET = async (request: NextRequest) => { | ||
const user = await validateSessionToken(); | ||
|
||
if (!user) { | ||
return Response.json({ error: 'You are not logged in' }, { status: 400 }); | ||
} | ||
|
||
const query = request.nextUrl.searchParams.get('q'); | ||
|
||
if (!query) { | ||
return Response.json({ error: 'No query provided' }, { status: 400 }); | ||
} | ||
|
||
return Response.json( | ||
( | ||
await prisma.userEntry.findMany({ | ||
where: { | ||
userId: user.id, | ||
entry: { | ||
alternativeTitles: { | ||
some: { | ||
title: { | ||
contains: query, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}) | ||
).map(e => e.id) | ||
); | ||
}; |
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,7 @@ | ||
export default async function fetcher<JSON = any>( | ||
input: RequestInfo, | ||
init?: RequestInit | ||
): Promise<JSON> { | ||
const res = await fetch(input, init); | ||
return res.json(); | ||
} |
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