68 lines
1.8 KiB
JavaScript
68 lines
1.8 KiB
JavaScript
const baseUrl = process.env.NODE_ENV !== 'dev'
|
|
? '/'
|
|
: 'http://localhost:3000/';
|
|
|
|
export const getRecipes = async () => {
|
|
const response = await fetch(`${baseUrl}backend/recipes`);
|
|
const data = await response.json();
|
|
return data;
|
|
};
|
|
|
|
export const getRecipeSteps = async () => {
|
|
const response = await fetch(`${baseUrl}backend/recipe-steps`);
|
|
const data = await response.json();
|
|
return data;
|
|
};
|
|
|
|
export const getRecipeIngredients = async () => {
|
|
const response = await fetch(`${baseUrl}backend/recipe-ingredients`);
|
|
const data = await response.json();
|
|
return data;
|
|
};
|
|
|
|
export const getRecipeById = async (id) => {
|
|
const response = await fetch(`${baseUrl}backend/recipe/${id}`);
|
|
const data = await response.json();
|
|
if (!data || !data.details) {
|
|
return { details: null };
|
|
}
|
|
return data;
|
|
};
|
|
|
|
export const addRecipe = async (recipeData) => {
|
|
console.log(JSON.stringify(recipeData));
|
|
// return
|
|
const response = await fetch(`${baseUrl}backend/add-recipe`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(recipeData),
|
|
});
|
|
const data = await response.json();
|
|
console.log(data);
|
|
return data;
|
|
};
|
|
|
|
export const setDBStars = async (id, stars) => {
|
|
console.log(JSON.stringify({ id: id, stars: stars }));
|
|
// return
|
|
const response = await fetch(`${baseUrl}backend/set-stars`, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ id: id, stars: stars }),
|
|
});
|
|
const data = await response.json();
|
|
console.log(data);
|
|
return data;
|
|
};
|
|
|
|
export const deleteRecipe = async (id) => {
|
|
console.log(id);
|
|
// return
|
|
const response = await fetch(`${baseUrl}backend/delete-recipe`, {
|
|
method: "DELETE",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ id }),
|
|
});
|
|
const data = await response.json();
|
|
return data;
|
|
};
|