Added api search route for sku
This commit is contained in:
parent
137da0e31e
commit
ac7ebbbf5e
30
src/routes/api/v1/search/sku.ts
Normal file
30
src/routes/api/v1/search/sku.ts
Normal 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 };
|
Loading…
Reference in New Issue
Block a user