2023-05-04 20:21:10 +02:00
|
|
|
import express, { Request, Response } from 'express';
|
|
|
|
import { prisma, __path } from '../../index.js';
|
|
|
|
|
|
|
|
export default (req: Request, res: Response) => {
|
|
|
|
// TODO: Fix it? Express behaves like fucking shit with routers and /. Do not ask about it or touch it. EVER! (But if you can fix it a PR is welcome!)
|
|
|
|
if (req.originalUrl !== '/') {
|
2023-05-12 23:57:21 +02:00
|
|
|
// TODO: Respond based on content-type (with req.is('application/json'))
|
2023-05-04 20:21:10 +02:00
|
|
|
res.status(404).render(__path + '/src/frontend/errors/404.eta.html', { url: req.originalUrl });
|
|
|
|
} else {
|
|
|
|
prisma.item
|
|
|
|
.findMany({
|
|
|
|
orderBy: {
|
|
|
|
updatedAt: 'desc'
|
|
|
|
},
|
|
|
|
// Limit to 10 items
|
|
|
|
take: 10
|
|
|
|
})
|
|
|
|
.then((items) => {
|
|
|
|
// Count amount of total items
|
|
|
|
prisma.item.count().then((count) => {
|
|
|
|
res.render(__path + '/src/frontend/dashboard.eta.html', { recents: items, stats: { total: count } });
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
console.error(err);
|
|
|
|
res.status(500).render(__path + '/src/frontend/errors/dbError.eta.html', { error: err });
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|