Skip to content

Instantly share code, notes, and snippets.

@meshboy
Last active December 3, 2018 03:57
Show Gist options
  • Save meshboy/0be340a4e98889ff4bc110160f070c00 to your computer and use it in GitHub Desktop.
Save meshboy/0be340a4e98889ff4bc110160f070c00 to your computer and use it in GitHub Desktop.
const createRecipe = async (root, { input }, { user }) => {
throwErrorIfUserNotAuthenticated(user);
// bring out the image from input for file processing
const { image, ...recipeObject } = await input;
let url = "";
if (image) {
const result = await uploadFile(image);
url = result.url;
}
const recipe = await Recipe.findOne({ name: input.name.toLowerCase() });
if (recipe) {
throw new Error("Recipe already exists!");
}
Object.assign(recipeObject, { image: url, userId: user.id });
return Recipe.create(recipeObject);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment