|
1 | 1 | import { Injectable } from '@angular/core'; |
2 | 2 | import { cloneDeep, isEqual } from 'lodash-es'; |
3 | 3 | import { filter, map, Observable, ReplaySubject } from 'rxjs'; |
4 | | -import { |
5 | | - JsonAttributeNode, |
6 | | - JsonNode, |
7 | | - JsonRootNode, |
8 | | - RosettaBasicType, |
9 | | -} from '../models/builder.model'; |
| 4 | +import { JsonAttributeNode, JsonNode, JsonRootNode, RosettaBasicType, } from '../models/builder.model'; |
10 | 5 | import { isAttributeExhausted, isListBasedBasicType } from '../utils/node.util'; |
11 | | -import { isJsonRootNode, isStringArray } from '../utils/type-guards.util'; |
| 6 | +import { isEnumType, isJsonRootNode, isNumberArray, isStringArray, } from '../utils/type-guards.util'; |
12 | 7 | import { IdentityService } from './identity.service'; |
13 | 8 |
|
14 | 9 | export interface NodeDataChangeEvent { |
@@ -224,20 +219,36 @@ export class NodeDatabaseService { |
224 | 219 | throw new Error('Attempt to add undefined value to sibling'); |
225 | 220 | } |
226 | 221 |
|
227 | | - switch (newJsonAttribute.definition.type) { |
228 | | - case RosettaBasicType.STRING: |
229 | | - const newValue = (newJsonAttribute.value || '') as string; |
230 | | - if (isStringArray(matchingSiblingAttributeNode.value)) { |
231 | | - matchingSiblingAttributeNode.value.push(newValue); |
232 | | - } else if (typeof matchingSiblingAttributeNode.value === 'string') { |
233 | | - const newValues = [newValue, matchingSiblingAttributeNode.value]; |
234 | | - matchingSiblingAttributeNode.value = newValues; |
235 | | - } |
236 | | - break; |
237 | | - default: |
238 | | - throw new Error( |
239 | | - `Adding value ${newJsonAttribute.value} to matchingSiblingAttributeNode.value ${matchingSiblingAttributeNode.value} is not supported` |
240 | | - ); |
| 222 | + if (isEnumType(newJsonAttribute.definition.type)) { |
| 223 | + const newValue = (newJsonAttribute.value || '') as string; |
| 224 | + if (isStringArray(matchingSiblingAttributeNode.value)) { |
| 225 | + matchingSiblingAttributeNode.value.push(newValue) |
| 226 | + } else { |
| 227 | + matchingSiblingAttributeNode.value = [newValue, matchingSiblingAttributeNode.value as string]; |
| 228 | + } |
| 229 | + } else { |
| 230 | + switch (newJsonAttribute.definition.type) { |
| 231 | + case RosettaBasicType.STRING: |
| 232 | + const newStringValue = (newJsonAttribute.value || '') as string; |
| 233 | + if (isStringArray(matchingSiblingAttributeNode.value)) { |
| 234 | + matchingSiblingAttributeNode.value.push(newStringValue); |
| 235 | + } else { |
| 236 | + matchingSiblingAttributeNode.value = [newStringValue, matchingSiblingAttributeNode.value as string]; |
| 237 | + } |
| 238 | + break; |
| 239 | + case RosettaBasicType.NUMBER: |
| 240 | + const newNumberValue = (newJsonAttribute.value || 0) as number; |
| 241 | + if (isNumberArray(matchingSiblingAttributeNode.value)) { |
| 242 | + matchingSiblingAttributeNode.value.push(newNumberValue); |
| 243 | + } else { |
| 244 | + matchingSiblingAttributeNode.value = [newNumberValue, matchingSiblingAttributeNode.value as number]; |
| 245 | + } |
| 246 | + break; |
| 247 | + default: |
| 248 | + throw new Error( |
| 249 | + `Adding value ${newJsonAttribute.value} to matchingSiblingAttributeNode.value ${matchingSiblingAttributeNode.value} is not supported` |
| 250 | + ); |
| 251 | + } |
241 | 252 | } |
242 | 253 | } |
243 | 254 |
|
|
0 commit comments