Your IP : 216.73.216.43


Current Path : /proc/thread-self/root/home/deltalab/PMS/partner-manager-backend/rest/routes/
Upload File :
Current File : //proc/thread-self/root/home/deltalab/PMS/partner-manager-backend/rest/routes/charts.js

const express = require('express');
const { orderQuery } = require('../queries');

const router = express.Router({ mergeParams: true });

router.get('/sells/:partnerId', async (req, res) => {
  try {
    const orders = await orderQuery.readMany(req.params.partnerId, req.query.year);
    return res.status(200).json({ success: true, data: orders });
  } catch (error) {
    return res.status(400).send({ success: false, message: 'Error retrieving the chart', error: error.message });
  }
});

router.get('/nSells/:partnerId', async (req, res) => {
  try {
    const orders = await orderQuery.nProductSold(req.params.partnerId, req.query.year);
    return res.status(200).json({ success: true, data: orders });
  } catch (error) {
    return res.status(400).send({ success: false, message: 'Error retrieving the chart', error: error.message });
  }
});

router.get('/nCategories/:partnerId', async (req, res) => {
  try {
    const orders = await orderQuery.nCategoriesSold(req.params.partnerId, req.query.year, req.query.firstN);
    return res.status(200).json({ success: true, data: orders });
  } catch (error) {
    return res.status(400).send({ success: false, message: 'Error retrieving the chart', error: error.message });
  }
});

router.get('/nBrands/:partnerId', async (req, res) => {
  try {
    const orders = await orderQuery.nBrandsSold(req.params.partnerId, req.query.year, req.query.firstN);
    return res.status(200).json({ success: true, data: orders });
  } catch (error) {
    return res.status(400).send({ success: false, message: 'Error retrieving the chart', error: error.message });
  }
});

router.get('/customerLocation/:partnerId', async (req, res) => {
  try {
    const orders = await orderQuery.readCustomerByZone(req.params.partnerId, req.query.year, req.query.firstN);
    return res.status(200).json({ success: true, data: orders });
  } catch (error) {
    return res.status(400).send({ success: false, message: 'Error retrieving the chart', error: error.message });
  }
});

router.get('/products/:partnerId', async (req, res) => {
  try {
    const products = await orderQuery.readBestSellers(req.params.partnerId, req.query.year, req.query.firstN);
    return res.status(200).json({ success: true, data: products });
  } catch (error) {
    return res.status(400).send({ success: false, message: 'Error retrieving the chart', error: error.message });
  }
});

module.exports = router;