diff --git a/src/routes/frontend/items.ts b/src/routes/frontend/items.ts index 2f62c30..5305f17 100644 --- a/src/routes/frontend/items.ts +++ b/src/routes/frontend/items.ts @@ -14,15 +14,14 @@ async function get(req: Request, res: Response) { const takeSize = 25; // Amount of times per page const pageSize = Math.ceil(itemCount / takeSize); // Amount of pages, always round up - // If page is less then 1 or more then the max page size redirect to first or last page + // If page is less then 1 or more then the max page size redirect to first or last page. If itemCount is 0 do not redirect. if (page < 1) { res.redirect('?page=1'); return; - } else if (page > pageSize) { + } else if (page > pageSize && itemCount !== 0) { res.redirect('?page=' + pageSize); return; } - prisma.item .findMany({ skip: (page - 1) * takeSize, take: takeSize }) // Skip the amount of items per page times the page number minus 1; skip has to be (page-1)*takeSize because skip is 0 indexed .then((items) => {