aretherecookies-mobile/js/records/ProductRecord.js
2020-05-31 15:43:53 -05:00

51 lines
1.1 KiB
JavaScript

import { Set, Record } from 'immutable';
import { type RawProduct } from '../apis/ProductsApi';
import { type Category } from '../constants/CategoryConstants';
import { type Quantity } from '../constants/QuantityConstants';
export type Product = {
id: ?string,
name: string,
placeId: ?number,
latitude: number,
longitude: number,
distance: number,
quantity: Quantity,
category: Category,
images: Set<string>,
thumbImage: ?string,
titleImage: ?string,
lastupdated: number,
};
const FoodRecordDefaults: Product = {
id: '',
name: '',
placeId: null,
placeType: '',
latitude: 0,
longitude: 0,
distance: 999,
quantity: '',
category: '',
images: new Set(),
thumbImage: '',
titleImage: '',
lastupdated: 0,
};
const ProductRecord = Record(FoodRecordDefaults, 'ProductRecord');
export const createProduct = (productRaw: ?RawProduct) => {
if (!productRaw) {
return productRaw;
}
return new ProductRecord({
...productRaw,
placeType: productRaw.placeType,
thumbImage: productRaw.thumbimage,
images: new Set([productRaw.thumbimage]),
});
};
export default ProductRecord;