Last active
December 3, 2018 03:57
-
-
Save meshboy/0be340a4e98889ff4bc110160f070c00 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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