-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathitemToLicense.ts
More file actions
36 lines (31 loc) · 1000 Bytes
/
itemToLicense.ts
File metadata and controls
36 lines (31 loc) · 1000 Bytes
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
36
/**
* @author Labs64 <netlicensing@labs64.com>
* @license Apache-2.0
* @link https://netlicensing.io
* @copyright 2017 Labs64 NetLicensing
*/
import itemToObject from '@/converters/itemToObject';
import License from '@/entities/License';
// types
import { Item } from '@/types/api/response';
import { LicenseProps } from '@/types/entities/License';
export default <T extends object = LicenseProps>(item?: Item) => {
const props = itemToObject<Record<string, unknown>>(item, {
active: 'boolean',
number: 'string',
name: 'string',
price: 'number',
currency: 'string',
hidden: 'boolean',
licenseeNumber: 'string',
licenseTemplateNumber: 'string',
productModuleNumber: 'string',
startDate: 'string',
inUse: 'boolean',
});
const { startDate } = props;
if (startDate && typeof startDate === 'string') {
props.startDate = startDate === 'now' ? startDate : new Date(startDate);
}
return License<T>(props as LicenseProps<T>);
};