broach44/for-the-love-of-java

Before Creating new Shop, Check for Exisiting

Closed this issue · 1 comments

User Story

As a user I would like to eliminate duplicate data and not be allowed to add a new shop if one already exists.

AC

WHEN I add a new coffee shop
THEN If it already exists I should not be allowed to save and add

Dev Notes

  • Reference in comments below...
const checkCurrentInventory = (newIngredient) => {
  inventoryData.getInventory()
    .then((ingredients) => {
      const checkData = ingredients.some((ingredient) => ingredient.name === newIngredient.name);
      if (checkData === true) {
        $('#existingIngredientWarning').removeClass('hide');
      } else {
        sendNewIngredientToDb(newIngredient);
      }
    })
    .catch((error) => console.error(error));
};

const createNewIngredient = (e) => {
  e.stopImmediatePropagation();
  const newIngredient = {
    name: $('#ingredient-name').val(),
    amountStocked: $('#amount-stocked').val() * 1,
    unitOfMeasurement: $('#unit-of-measurement').val(),
    cost: $('#ingredient-cost').val() * 100,
  };
  checkCurrentInventory(newIngredient);
};