Added api search route for sku

This commit is contained in:
Leon Meier 2023-06-27 20:56:04 +02:00
parent 137da0e31e
commit ac7ebbbf5e

View File

@ -0,0 +1,30 @@
import { Request, Response } from 'express';
import { prisma, __path, log } from '../../../../index.js';
// Get item.
function get(req: Request, res: Response) {
if (!req.query.sku) {
res.status(400).json({ errorcode: 'VALIDATION_ERROR', error: 'One or more required fields are missing' });
return;
}
prisma.item
.findMany({
where: {
SKU: {
contains: req.query.sku.toString()
}
},
include: {
category: true
}
})
.then((items) => {
res.status(200).json(JSON.stringify(items));
})
.catch((err) => {
log.db.error(err);
res.status(500).json({ errorcode: 'DB_ERROR', error: err });
});
}
export default { get };