current state
This commit is contained in:
28
src/routes/frontend/dashboard.ts
Normal file
28
src/routes/frontend/dashboard.ts
Normal file
@ -0,0 +1,28 @@
|
||||
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 !== '/') {
|
||||
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 });
|
||||
});
|
||||
}
|
||||
};
|
@ -1,18 +0,0 @@
|
||||
import express, { Request, Response } from 'express';
|
||||
import { prisma, __path } from '../../index.js';
|
||||
|
||||
export default (req: Request, res: Response) => {
|
||||
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/demopage.eta.html', { recents: items, stats: { total: count } });
|
||||
});
|
||||
});
|
||||
// res.render(__path + '/src/frontend/demopage.eta.html');
|
||||
};
|
@ -36,8 +36,6 @@ export default (req: Request, res: Response) => {
|
||||
values.forEach((value) => {
|
||||
categories.delete(value.name);
|
||||
});
|
||||
// Log categories
|
||||
log.web.debug(categories);
|
||||
|
||||
const categoryPromises: PrismaPromise<Category>[] = [];
|
||||
categories.forEach((category: string) => {
|
||||
@ -71,8 +69,6 @@ export default (req: Request, res: Response) => {
|
||||
}
|
||||
});
|
||||
listOfPromises.push(promise);
|
||||
|
||||
|
||||
}
|
||||
Promise.all(listOfPromises).then((values) => {
|
||||
console.log(values);
|
||||
|
@ -3,16 +3,18 @@ import express from 'express';
|
||||
// Route imports
|
||||
import skuRoute from './:id.js';
|
||||
import testRoute from './test.js';
|
||||
import etaTestRoute from './etaTest.js';
|
||||
import dashboardRoute from './dashboard.js';
|
||||
import csvImportRoute from './import/csvImport.js';
|
||||
import listAllItems from './listAllItems.js';
|
||||
|
||||
// Router base is '/'
|
||||
const Router = express.Router();
|
||||
const Router = express.Router({ strict: false });
|
||||
|
||||
|
||||
Router.use('/etaTest', etaTestRoute);
|
||||
Router.use('/:id(\\w{8})', skuRoute);
|
||||
Router.use('/test', testRoute);
|
||||
Router.use('/allItems', listAllItems)
|
||||
Router.use('/import/csv', csvImportRoute);
|
||||
|
||||
Router.use('/:id(\\w{8})', skuRoute);
|
||||
Router.use('/', dashboardRoute);
|
||||
|
||||
export default Router;
|
||||
|
15
src/routes/frontend/listAllItems.ts
Normal file
15
src/routes/frontend/listAllItems.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import express, { Request, Response } from 'express';
|
||||
import { prisma, __path } from '../../index.js';
|
||||
|
||||
export default (req: Request, res: Response) => {
|
||||
prisma.item
|
||||
.findMany({})
|
||||
.then((items) => {
|
||||
// Count amount of total items
|
||||
res.render(__path + '/src/frontend/allItems.eta.html', { items: items });
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
res.status(500).render(__path + '/src/frontend/errors/dbError.eta.html', { error: err });
|
||||
});
|
||||
};
|
@ -1,4 +1,4 @@
|
||||
import { Express } from 'express';
|
||||
import express, { Express } from 'express';
|
||||
|
||||
// Route imports
|
||||
import frontend_routes from './frontend/index.js';
|
||||
@ -6,9 +6,11 @@ import static_routes from './static/index.js';
|
||||
import api_routes from './api/index.js';
|
||||
import dev_routes from './dev/index.js';
|
||||
|
||||
export default (app: Express) => {
|
||||
app.use('/', frontend_routes);
|
||||
app.use('/static', static_routes);
|
||||
app.use('/api', api_routes);
|
||||
app.use('/dev', dev_routes); // This is just for development. ToDo: Add check if we are in devmode.
|
||||
};
|
||||
const Router = express.Router({ strict: false });
|
||||
|
||||
Router.use('/static', static_routes);
|
||||
Router.use('/api', api_routes);
|
||||
Router.use('/dev', dev_routes); // This is just for development. ToDo: Add check if we are in devmode.
|
||||
Router.use('/', frontend_routes);
|
||||
|
||||
export default Router;
|
Reference in New Issue
Block a user