aretherecookies-mobile/js/records/ProductRecord.js

52 lines
1.1 KiB
JavaScript
Raw Normal View History

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,
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,
images: Set<string>,
2017-06-03 19:43:45 -05:00
thumbImage: ?string,
titleImage: ?string,
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,
placeType: '',
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: '',
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,
images: new Set([productRaw.thumbimage]),
2017-08-05 20:38:29 -05:00
});
};
2020-04-17 22:50:23 -05:00
export default ProductRecord;