diff --git a/js/apis/FoodItemsApi.js b/js/apis/FoodItemsApi.js index 66fb15d..8ce4c58 100644 --- a/js/apis/FoodItemsApi.js +++ b/js/apis/FoodItemsApi.js @@ -76,18 +76,18 @@ export const getFoodItems = memoize( ); export const createFoodItem = async (foodItem: FoodItemRecord) => { + if (!AuthManager.user) { + throw new Error('You must be logged in to create food items'); + } + + const username = AuthManager.user.name; + const res = await fetchRequest({ endpoint: '/addfooditem', method: 'POST', body: foodItem, }); - if (!AuthManager.user) { - return; - } - - const username = AuthManager.user.name; - const addImageUri = (imageUri: string) => addImage({ foodItemId: res.id, imageUri, username }); const images = map(path(['url']), await Promise.all(map(addImageUri, foodItem.images.toArray()))); diff --git a/js/records/FoodItemRecord.js b/js/records/FoodItemRecord.js index 2f733d7..d5c2658 100644 --- a/js/records/FoodItemRecord.js +++ b/js/records/FoodItemRecord.js @@ -38,7 +38,10 @@ const FoodRecordDefaults: FoodItem = { const FoodItemRecord = Record(FoodRecordDefaults, 'FoodItemRecord'); export const createFoodItem = (foodItemRaw: ?RawFoodItem) => { - return !foodItemRaw ? foodItemRaw : new FoodItemRecord({ + if (!foodItemRaw) { + return foodItemRaw; + } + return new FoodItemRecord({ ...foodItemRaw, placeId: foodItemRaw.placeid, thumbImage: foodItemRaw.thumbimage, diff --git a/yarn.lock b/yarn.lock index 5b72540..9b3e2fc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4964,6 +4964,7 @@ react-native-image-picker@^0.27: react-native-image-resizer@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/react-native-image-resizer/-/react-native-image-resizer-1.0.0.tgz#d47e14943c37938e287fbd639e4db7ceb7fd8917" + integrity sha1-1H4UlDw3k44of71jnk23zrf9iRc= react-native-loading-spinner-overlay@^0.5.2: version "0.5.2"