assetflow/src/routes/frontend/dashboard.ts
Spacelord 3569c9ed4b Updated styles and Added storageManager.
- Dark/White-mode support
- Collapsible navs
- Renamed items template.
- StorageBuilding's are now StorageUnit's
- Formatting, general cleanup, some bug fixing.
2023-05-13 00:06:35 +02:00

30 lines
1011 B
TypeScript

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 !== '/') {
// TODO: Respond based on content-type (with req.is('application/json'))
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 });
});
}
};