Products

getProducts

Below is the code for getProductsAPI. In this example we are calling a server script xe.Product which has a method called find which will return the list of all products.

module.exports.getProducts = () => {
  return async (req, res) => {
    const domain = req.subdomains[0] || "dev";
    let _query = { domain };
    const query = req.query;
    if (query && Object.keys(query).length) {
      delete query.nd;
      // _query = Object.assign(_query, ob.querystring.parse(query));
      _query = { ..._query, ...query};
    }
    res.set('Cache-Control', 'no-cache');
    const user = req.user;
    ob.log(_query);
    const products = await xe.Product.find(_query);
    res.json(products);
  };
};

postProduct

Below is the code for postProduct API. In this example allows user to make a product. In this code we retrieve the form values storing product details and pass it to a server script called xe.Product which has a method called save which will save the product details to the database.

Last updated

Was this helpful?