mirror of
https://github.com/Mueller-Patrick/Betterzon.git
synced 2026-05-01 17:50:10 +00:00
BETTERZON-38: Adjusted prices API
This commit is contained in:
@@ -23,7 +23,20 @@ export const pricesRouter = express.Router();
|
||||
|
||||
pricesRouter.get('/', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const prices: Prices = await PriceService.findAll();
|
||||
let prices: Prices = [];
|
||||
const product = req.query.product;
|
||||
const vendor = req.query.vendor;
|
||||
const type = req.query.type;
|
||||
|
||||
if (product) {
|
||||
if (vendor) {
|
||||
prices = await PriceService.findByVendor(<string> product, <string> vendor, <string> type);
|
||||
} else {
|
||||
prices = await PriceService.findByType(<string> product, <string> type);
|
||||
}
|
||||
} else {
|
||||
prices = await PriceService.findAll();
|
||||
}
|
||||
|
||||
res.status(200).send(prices);
|
||||
} catch (e) {
|
||||
@@ -50,26 +63,6 @@ pricesRouter.get('/:id', async (req: Request, res: Response) => {
|
||||
}
|
||||
});
|
||||
|
||||
// GET items/:name
|
||||
|
||||
pricesRouter.get('/products/:id', async (req: Request, res: Response) => {
|
||||
const id: number = parseInt(req.params.id, 10);
|
||||
|
||||
if (!id) {
|
||||
res.status(400).send('Missing parameters.');
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const prices: Prices = await PriceService.findByProduct(id);
|
||||
|
||||
res.status(200).send(prices);
|
||||
} catch (e) {
|
||||
res.status(404).send(e.message);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// POST items/
|
||||
|
||||
// pricesRouter.post('/', async (req: Request, res: Response) => {
|
||||
|
||||
Reference in New Issue
Block a user