-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathitemToProduct.ts
More file actions
35 lines (30 loc) · 1.06 KB
/
itemToProduct.ts
File metadata and controls
35 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/**
* @author Labs64 <netlicensing@labs64.com>
* @license Apache-2.0
* @link https://netlicensing.io
* @copyright 2017 Labs64 NetLicensing
*/
import itemToObject from '@/converters/itemToObject';
import Product from '@/entities/Product';
import ProductDiscount from '@/entities/ProductDiscount';
// types
import { Item } from '@/types/api/response';
import { ProductProps } from '@/types/entities/Product';
import { ProductDiscountEntity } from '@/types/entities/ProductDiscount';
export default <T extends object = ProductProps>(item?: Item) => {
const props = itemToObject<Record<string, unknown>>(item, {
number: 'string',
name: 'string',
version: 'string',
description: 'string',
licensingInfo: 'string',
licenseeAutoCreate: 'boolean',
inUse: 'boolean',
});
const discounts: ProductDiscountEntity[] | undefined = props.discount as ProductDiscountEntity[] | undefined;
delete props.discount;
if (discounts) {
props.discounts = discounts.map((d) => ProductDiscount(d));
}
return Product<T>(props as ProductProps<T>);
};