-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use API to fetch Dossiers * Remove unused packages for data base management
- Loading branch information
1 parent
5e9ab21
commit 4afeff4
Showing
7 changed files
with
113 additions
and
473 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
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,31 @@ | ||
import { type NextRequest } from "next/server"; | ||
import { prisma } from "@/prisma"; | ||
|
||
// export const dynamic = "force-static"; | ||
|
||
function parseNumber(value: string | null, defaultValue: number) { | ||
if (value === null) { | ||
return defaultValue; | ||
} | ||
|
||
const parsed = Number.parseInt(value); | ||
|
||
return Number.isInteger(parsed) ? parsed : defaultValue; | ||
} | ||
|
||
export async function GET(request: NextRequest) { | ||
const searchParams = request.nextUrl.searchParams; | ||
const legislature = searchParams.get("legislature") ?? "16"; | ||
const theme = searchParams.get("theme"); | ||
const page = parseNumber(searchParams.get("page"), 0); | ||
const pageSize = parseNumber(searchParams.get("pageSize"), 20); | ||
|
||
const data = await prisma.dossier.findMany({ | ||
where: { legislature, ...(theme === "" ? {} : { theme }) }, | ||
orderBy: { numero: "asc" }, // TODO replace by last date when possible | ||
take: pageSize, | ||
skip: page * pageSize, | ||
}); | ||
|
||
return Response.json({ data }); | ||
} |
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.