39 lines
1.2 KiB
JavaScript
39 lines
1.2 KiB
JavaScript
|
|
import { http } from './http'
|
||
|
|
import { mapPurchasedShoppingList, mapCurrentShoppingList } from './mappers/shoppingListMapper'
|
||
|
|
|
||
|
|
export async function getMyShoppingList() {
|
||
|
|
const ingredients = await http.get('/shopping/current/me/ingredients')
|
||
|
|
return ingredients
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function saveMyShoppingList(list) {
|
||
|
|
const ingredients = await http.post('/shopping/current/me/ingredients', list)
|
||
|
|
return ingredients
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function getShoppingList(id) {
|
||
|
|
const dto = await http.get(`/shopping/${encodeURIComponent(id)}`)
|
||
|
|
const mapped = mapPurchasedShoppingList(dto)
|
||
|
|
return mapped.list
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function getCurrentShoppingList() {
|
||
|
|
const dto = await http.get('/shopping/current')
|
||
|
|
return mapCurrentShoppingList(dto)
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function purchaseShoppingList(completedRequests) {
|
||
|
|
const dto = await http.post('/shopping/', { items: completedRequests })
|
||
|
|
const mapped = mapPurchasedShoppingList(dto)
|
||
|
|
return mapped.list
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function requestMeal(mealId) {
|
||
|
|
const items = await http.post('/shopping/current/meals/me', { meal_id: mealId })
|
||
|
|
return items
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function unrequestMeal(mealId) {
|
||
|
|
await http.del(`/shopping/current/meals/${encodeURIComponent(mealId)}`)
|
||
|
|
}
|