assetflow/src/routes/frontend/:id.ts

37 lines
713 B
TypeScript
Raw Normal View History

2023-05-01 00:14:16 +02:00
import { Request, Response } from 'express';
import { prisma, __path } from '../../index.js';
import * as Eta from 'eta';
2023-05-15 01:37:51 +02:00
function get(req: Request, res: Response) {
// Get data from database using sku from url.
2023-05-01 00:14:16 +02:00
prisma.item
.findFirst({
where: {
SKU: req.params.id
2023-05-15 01:37:51 +02:00
},
select: {
SKU: true,
name: true,
comment: true,
amount: true,
// Get category name from relation.
category: {
select: {
name: true
}
}
2023-05-01 00:14:16 +02:00
}
})
.then((item) => {
if (item) {
Eta.renderFile(__path + '/src/frontend/publicInfoPage.eta.html', item).then((html) => {
res.send(html);
});
} else {
res.send('Item not found');
}
});
2023-05-15 01:37:51 +02:00
}
export default { get };