2018-04-08 10:54:29 -05:00
|
|
|
import { Set, Record } from 'immutable';
|
2020-04-17 22:50:23 -05:00
|
|
|
import { type RawProduct } from '../apis/ProductsApi';
|
2019-06-22 15:48:52 +00:00
|
|
|
import { type Category } from '../constants/CategoryConstants';
|
|
|
|
|
import { type Quantity } from '../constants/QuantityConstants';
|
2017-06-24 16:06:11 -05:00
|
|
|
|
2020-04-17 22:50:23 -05:00
|
|
|
export type Product = {
|
2017-10-22 12:38:05 -05:00
|
|
|
id: ?string,
|
2017-06-03 19:43:45 -05:00
|
|
|
name: string,
|
|
|
|
|
placeId: ?number,
|
2017-07-02 12:32:26 -05:00
|
|
|
latitude: number,
|
|
|
|
|
longitude: number,
|
|
|
|
|
distance: number,
|
2017-06-03 19:43:45 -05:00
|
|
|
quantity: Quantity,
|
2017-06-24 16:06:11 -05:00
|
|
|
category: Category,
|
2020-05-31 15:43:53 -05:00
|
|
|
images: Set<string>,
|
2017-06-03 19:43:45 -05:00
|
|
|
thumbImage: ?string,
|
|
|
|
|
titleImage: ?string,
|
2017-11-19 12:22:09 -06:00
|
|
|
lastupdated: number,
|
2017-03-25 21:05:55 -05:00
|
|
|
};
|
|
|
|
|
|
2020-04-17 22:50:23 -05:00
|
|
|
const FoodRecordDefaults: Product = {
|
2017-10-22 12:38:05 -05:00
|
|
|
id: '',
|
2017-06-03 19:43:45 -05:00
|
|
|
name: '',
|
|
|
|
|
placeId: null,
|
2020-04-13 22:11:20 -05:00
|
|
|
placeType: '',
|
2017-07-02 12:32:26 -05:00
|
|
|
latitude: 0,
|
|
|
|
|
longitude: 0,
|
|
|
|
|
distance: 999,
|
2019-06-22 15:48:52 +00:00
|
|
|
quantity: '',
|
|
|
|
|
category: '',
|
2018-04-08 10:54:29 -05:00
|
|
|
images: new Set(),
|
2017-06-03 19:43:45 -05:00
|
|
|
thumbImage: '',
|
|
|
|
|
titleImage: '',
|
2017-11-19 12:22:09 -06:00
|
|
|
lastupdated: 0,
|
2017-03-25 21:05:55 -05:00
|
|
|
};
|
|
|
|
|
|
2020-04-17 22:50:23 -05:00
|
|
|
const ProductRecord = Record(FoodRecordDefaults, 'ProductRecord');
|
2017-08-05 20:38:29 -05:00
|
|
|
|
2020-04-17 22:50:23 -05:00
|
|
|
export const createProduct = (productRaw: ?RawProduct) => {
|
|
|
|
|
if (!productRaw) {
|
|
|
|
|
return productRaw;
|
2019-03-02 10:37:53 -06:00
|
|
|
}
|
2020-04-17 22:50:23 -05:00
|
|
|
return new ProductRecord({
|
|
|
|
|
...productRaw,
|
|
|
|
|
placeType: productRaw.placeType,
|
|
|
|
|
thumbImage: productRaw.thumbimage,
|
2020-05-31 15:43:53 -05:00
|
|
|
images: new Set([productRaw.thumbimage]),
|
2017-08-05 20:38:29 -05:00
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2020-04-17 22:50:23 -05:00
|
|
|
export default ProductRecord;
|