Fixed routing and publicInfoPage.

This commit is contained in:
2023-05-15 01:37:51 +02:00
parent 1f2eb78333
commit ee61e94853
18 changed files with 170 additions and 160 deletions

View File

@ -2,15 +2,28 @@ import { Request, Response } from 'express';
import { prisma, __path } from '../../index.js';
import * as Eta from 'eta';
export default (req: Request, res: Response) => {
// retrieve data from database using id from url
function get(req: Request, res: Response) {
// Get data from database using sku from url.
prisma.item
.findFirst({
where: {
SKU: req.params.id
},
select: {
SKU: true,
name: true,
comment: true,
amount: true,
// Get category name from relation.
category: {
select: {
name: true
}
}
}
})
.then((item) => {
console.log(JSON.stringify(item));
if (item) {
Eta.renderFile(__path + '/src/frontend/publicInfoPage.eta.html', item).then((html) => {
res.send(html);
@ -19,4 +32,6 @@ export default (req: Request, res: Response) => {
res.send('Item not found');
}
});
};
}
export default { get };