@@ -2,17 +2,35 @@ import { Guid } from './Guid';
2
2
import { toDateIn , toDateOut } from './date-converters' ;
3
3
import type * as $types from './types' ;
4
4
5
+ export enum CategoryUnionTypes {
6
+ CategoryElectronicsDto = '1' ,
7
+ CategoryMotorsDto = '2'
8
+ }
9
+
5
10
export enum ProductStatus {
6
11
InStock = 0 ,
7
12
OutOfStock = - 1 ,
8
13
UnderTheOrder = 1
9
14
}
10
15
16
+ interface ICategoryElectronicsDtoBaseInterface {
17
+ syntheticTest : $types . TypeOrUndefinedNullable < number > ;
18
+ }
19
+
20
+ interface ICategoryMotorsDtoBaseInterface {
21
+ volume : $types . TypeOrUndefinedNullable < number > ;
22
+ }
23
+
11
24
export interface ICategory {
12
25
name : $types . TypeOrUndefinedNullable < string > ;
26
+ type : $types . TypeOrUndefined < string > ;
13
27
}
14
28
29
+ export type ICategoryElectronicsDto = ICategoryElectronicsDtoBaseInterface & ICategory ;
30
+ export type ICategoryMotorsDto = ICategoryMotorsDtoBaseInterface & ICategory ;
31
+
15
32
export interface IProduct {
33
+ categories : $types . TypeOrUndefinedNullable < ICategory [ ] > ;
16
34
category : $types . TypeOrUndefinedNullable < ICategory > ;
17
35
colors : $types . TypeOrUndefined < string [ ] > ;
18
36
expireDate : $types . TypeOrUndefined < string > ;
@@ -27,6 +45,47 @@ export interface IProductIdentityDTO {
27
45
id : $types . TypeOrUndefined < string > ;
28
46
}
29
47
48
+ export type CategoryUnion = Category | CategoryElectronicsDto | CategoryMotorsDto ;
49
+ export type ICategoryUnion = ICategory | ICategoryElectronicsDto | ICategoryMotorsDto ;
50
+
51
+ export class CategoryUnionClass {
52
+ public static fromDTO ( dto : ICategoryUnion ) : CategoryUnion {
53
+ if ( this . isCategoryElectronicsDto ( dto ) ) {
54
+ return CategoryElectronicsDto . fromDTO ( dto ) ;
55
+ }
56
+ if ( this . isCategoryMotorsDto ( dto ) ) {
57
+ return CategoryMotorsDto . fromDTO ( dto ) ;
58
+ }
59
+ return Category . fromDTO ( dto ) ;
60
+ }
61
+
62
+ public static toDTO ( model : CategoryUnion ) : ICategoryUnion {
63
+ if ( this . isICategoryElectronicsDto ( model ) ) {
64
+ return CategoryElectronicsDto . toDTO ( model ) ;
65
+ }
66
+ if ( this . isICategoryMotorsDto ( model ) ) {
67
+ return CategoryMotorsDto . toDTO ( model ) ;
68
+ }
69
+ return Category . toDTO ( model ) ;
70
+ }
71
+
72
+ private static isCategoryElectronicsDto ( dto : ICategoryUnion ) : dto is ICategoryElectronicsDto {
73
+ return dto . type === CategoryUnionTypes . CategoryElectronicsDto ;
74
+ }
75
+
76
+ private static isCategoryMotorsDto ( dto : ICategoryUnion ) : dto is ICategoryMotorsDto {
77
+ return dto . type === CategoryUnionTypes . CategoryMotorsDto ;
78
+ }
79
+
80
+ private static isICategoryElectronicsDto ( dto : CategoryUnion ) : dto is CategoryElectronicsDto {
81
+ return dto . type === CategoryUnionTypes . CategoryElectronicsDto ;
82
+ }
83
+
84
+ private static isICategoryMotorsDto ( dto : CategoryUnion ) : dto is CategoryMotorsDto {
85
+ return dto . type === CategoryUnionTypes . CategoryMotorsDto ;
86
+ }
87
+ }
88
+
30
89
export class ProductIdentityDTO {
31
90
public id : Guid ;
32
91
private __productIdentityDTO ! : string ;
@@ -42,23 +101,73 @@ export class ProductIdentityDTO {
42
101
43
102
export class Category {
44
103
public name : $types . TypeOrUndefinedNullable < string > = undefined ;
104
+ public type : $types . TypeOrUndefined < string > = undefined ;
45
105
private __category ! : string ;
46
106
47
107
public static toDTO ( model : Partial < Category > ) : ICategory {
48
108
return {
49
109
name : model . name ,
110
+ type : model . type ,
50
111
} ;
51
112
}
52
113
53
114
public static fromDTO ( dto : ICategory ) : Category {
54
115
const model = new Category ( ) ;
55
116
model . name = dto . name ;
117
+ model . type = dto . type ;
118
+ return model ;
119
+ }
120
+ }
121
+
122
+ export class CategoryElectronicsDto {
123
+ public name : $types . TypeOrUndefinedNullable < string > = undefined ;
124
+ public type : $types . TypeOrUndefined < string > = undefined ;
125
+ public syntheticTest : $types . TypeOrUndefinedNullable < number > = undefined ;
126
+ private __categoryElectronicsDto ! : string ;
127
+
128
+ public static toDTO ( model : Partial < CategoryElectronicsDto > ) : ICategoryElectronicsDto {
129
+ return {
130
+ syntheticTest : model . syntheticTest ,
131
+ name : model . name ,
132
+ type : model . type ,
133
+ } ;
134
+ }
135
+
136
+ public static fromDTO ( dto : ICategoryElectronicsDto ) : CategoryElectronicsDto {
137
+ const model = new CategoryElectronicsDto ( ) ;
138
+ model . syntheticTest = dto . syntheticTest ;
139
+ model . name = dto . name ;
140
+ model . type = dto . type ;
141
+ return model ;
142
+ }
143
+ }
144
+
145
+ export class CategoryMotorsDto {
146
+ public name : $types . TypeOrUndefinedNullable < string > = undefined ;
147
+ public type : $types . TypeOrUndefined < string > = undefined ;
148
+ public volume : $types . TypeOrUndefinedNullable < number > = undefined ;
149
+ private __categoryMotorsDto ! : string ;
150
+
151
+ public static toDTO ( model : Partial < CategoryMotorsDto > ) : ICategoryMotorsDto {
152
+ return {
153
+ volume : model . volume ,
154
+ name : model . name ,
155
+ type : model . type ,
156
+ } ;
157
+ }
158
+
159
+ public static fromDTO ( dto : ICategoryMotorsDto ) : CategoryMotorsDto {
160
+ const model = new CategoryMotorsDto ( ) ;
161
+ model . volume = dto . volume ;
162
+ model . name = dto . name ;
163
+ model . type = dto . type ;
56
164
return model ;
57
165
}
58
166
}
59
167
60
168
export class Product {
61
- public category : $types . TypeOrUndefinedNullable < Category > = undefined ;
169
+ public categories : CategoryUnionClass [ ] = [ ] ;
170
+ public category : $types . TypeOrUndefinedNullable < CategoryUnionClass > = undefined ;
62
171
public colors : string [ ] = [ ] ;
63
172
public expireDate : $types . TypeOrUndefined < Date > = undefined ;
64
173
public externalId : $types . TypeOrUndefinedNullable < Guid > = undefined ;
@@ -70,6 +179,7 @@ export class Product {
70
179
71
180
public static toDTO ( model : Partial < Product > ) : IProduct {
72
181
return {
182
+ categories : model . categories ? model . categories . map ( x => Category . toDTO ( x ) ) : undefined ,
73
183
category : model . category ? Category . toDTO ( model . category ) : undefined ,
74
184
colors : model . colors ,
75
185
expireDate : toDateOut ( model . expireDate ) ,
@@ -83,6 +193,7 @@ export class Product {
83
193
84
194
public static fromDTO ( dto : IProduct ) : Product {
85
195
const model = new Product ( ) ;
196
+ model . categories = dto . categories ? dto . categories . map ( x => Category . fromDTO ( x ) ) : [ ] ;
86
197
model . category = dto . category ? Category . fromDTO ( dto . category ) : undefined ;
87
198
model . colors = dto . colors ? dto . colors : [ ] ;
88
199
model . expireDate = toDateIn ( dto . expireDate ) ;
0 commit comments