aretherecookies-mobile/js/apis/QuantityApi.js
Bart Akeley 9221b7f9b5 quantities round trip api and stream
make POST requests to /quantity to update the quantity of an existing food item - then mixin the new quantity with the existing food items observable
2017-11-26 19:52:16 -06:00

27 lines
633 B
JavaScript

// @flow
import type { Quantity } from '../constants/QuantityConstants';
import { BASE_URL } from '../constants/AppConstants';
import type { QuantityResponse } from '../constants/QuantityConstants';
export const setQuantity = ({
foodItemId,
quantity,
}: {
foodItemId: string,
quantity: Quantity,
}): ?Promise<QuantityResponse> => {
try {
return fetch(`http://${BASE_URL}/quantity`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
foodItemId,
quantity,
}),
}).then(res => res.json());
} catch (error) {
console.log(error); //eslint-disable-line
}
};