import Config from '../config'; import axios from 'axios'; export const getAllProducts = async data => { const res = await axios.get(`${Config.inventoryUrl}`); return res.data; } export const deleteProduct = async (sku) => { await axios.delete(`${Config.inventoryUrl}/${sku}`) .then(() => { getAllProducts(); }); } export const getFilteredProducts = async (searchTerm, searchBy) => { const res = await axios.get(`${Config.inventoryUrl}`); return res.data.filter(product => { let productFiltered; if(searchBy === "name"){ productFiltered = product.productName.toLowerCase(); }else if(searchBy === "sku"){ productFiltered = product.sku.toLowerCase(); } return productFiltered.includes(searchTerm.toLowerCase()); }); }