From 9d3b867e9e024bd38101b7b68e70f833096c395f Mon Sep 17 00:00:00 2001 From: Martin Zanoni Date: Wed, 11 Jan 2023 10:57:53 +0100 Subject: [PATCH] add multilingualcollection, fix bug in objectcollection --- lib/src/factory/dataValue.factory.ts | 6 +++++- lib/src/models/dataValue.ts | 16 ++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/src/factory/dataValue.factory.ts b/lib/src/factory/dataValue.factory.ts index 5753d69..a3dee54 100644 --- a/lib/src/factory/dataValue.factory.ts +++ b/lib/src/factory/dataValue.factory.ts @@ -1,4 +1,4 @@ -import { StringDataValue, StringCollectionDataValue, NumberDataValue, DoubleCollectionDataValue, BooleanDataValue, BooleanCollectionDataValue, MultiCurrencyDataValue, MultilingualDataValue, ObjectDataValue, ObjectCollectionDataValue, DataValue } from '..'; +import { StringDataValue, StringCollectionDataValue, NumberDataValue, DoubleCollectionDataValue, BooleanDataValue, BooleanCollectionDataValue, MultiCurrencyDataValue, MultilingualDataValue, ObjectDataValue, ObjectCollectionDataValue, DataValue, MultilingualCollectionDataValue } from '..'; export class DataValueFactory { static string(value: string): StringDataValue { @@ -33,6 +33,10 @@ export class DataValueFactory { return new MultilingualDataValue(values); } + static multilingualCollection(values: { values: string[], language: string }[]): MultilingualCollectionDataValue { + return new MultilingualCollectionDataValue(values); + } + static object(data: { [key: string]: DataValue }): ObjectDataValue { return new ObjectDataValue(data); } diff --git a/lib/src/models/dataValue.ts b/lib/src/models/dataValue.ts index 4b2c0d2..41005b9 100644 --- a/lib/src/models/dataValue.ts +++ b/lib/src/models/dataValue.ts @@ -1,4 +1,4 @@ -import { DataObject, DataValue, MultiCurrency, Multilingual } from './data-contracts'; +import { DataObject, DataValue, MultiCurrency, Multilingual, MultilingualCollectionValue } from './data-contracts'; export type DataValueTypes = 'String' | 'Double' | 'Boolean' | 'Multilingual' | 'Money' | 'MultiCurrency' | 'StringList' | 'DoubleList' | 'BooleanList' | 'MultilingualCollection' | 'Object' | 'ObjectList'; @@ -51,6 +51,18 @@ export class StringCollectionDataValue extends DataValueBase> { + constructor(values: { values: string[], language: string }[]) { + super('MultilingualCollection', + { + $type: 'System.Collections.Generic.List`1[[Relewise.Client.DataTypes.Multilingual, Relewise.Client]], System.Private.CoreLib', + $values: values.map(x => ({ values: x.values, language: { value: x.language } })), + }); + } + + readonly isCollection = true; +} + export class NumberDataValue extends DataValueBase { constructor(value: number) { super('Double', value); @@ -131,7 +143,7 @@ export class ObjectCollectionDataValue extends DataValueBase ({ $type: 'Relewise.Client.DataTypes.DataObject, Relewise.Client', data: x })), }); }