Compare commits

..

2 Commits

Author SHA1 Message Date
a8b0374d5e Fix variable declaration in toastHandler 2023-05-21 01:42:16 +02:00
90dbadac24 Fixed the redirection loop in the pagination of /items
A redirection loop occurred when there were no items in the database.
2023-05-21 01:31:35 +02:00
2 changed files with 3 additions and 4 deletions

View File

@ -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) => {

View File

@ -1,4 +1,4 @@
const currentToasts = [];
currentToasts = [];
/**
* Generic function to create a new toast