37 lines
713 B
TypeScript
37 lines
713 B
TypeScript
import { Request, Response } from 'express';
|
|
import { prisma, __path } from '../../index.js';
|
|
import * as Eta from 'eta';
|
|
|
|
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) => {
|
|
if (item) {
|
|
Eta.renderFile(__path + '/src/frontend/publicInfoPage.eta.html', item).then((html) => {
|
|
res.send(html);
|
|
});
|
|
} else {
|
|
res.send('Item not found');
|
|
}
|
|
});
|
|
}
|
|
|
|
export default { get };
|