broach44 / for-the-love-of-java

1 stars 0 forks source link

Before Creating new Shop, Check for Exisiting #38

Closed broach44 closed 4 years ago

broach44 commented 4 years ago

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

broach44 commented 4 years ago
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);
};