Skip to content

Commit

Permalink
add multilingualcollection, fix bug in objectcollection
Browse files Browse the repository at this point in the history
  • Loading branch information
mzanoni committed Jan 11, 2023
1 parent e9b6eb2 commit 9d3b867
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/src/factory/dataValue.factory.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down
16 changes: 14 additions & 2 deletions lib/src/models/dataValue.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -51,6 +51,18 @@ export class StringCollectionDataValue extends DataValueBase<CollectionWithType<
readonly isCollection = true;
}

export class MultilingualCollectionDataValue extends DataValueBase<CollectionWithType<MultilingualCollectionValue>> {
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<number> {
constructor(value: number) {
super('Double', value);
Expand Down Expand Up @@ -131,7 +143,7 @@ export class ObjectCollectionDataValue extends DataValueBase<CollectionWithType<
constructor(dataObjects: { [key: string]: DataValue }[]) {
super('ObjectList',
{
$type: 'Relewise.Client.DataTypes.DataObject, Relewise.Client',
$type: 'System.Collections.Generic.List`1[[Relewise.Client.DataTypes.DataObject, Relewise.Client]], System.Private.CoreLib',
$values: dataObjects.map(x => ({ $type: 'Relewise.Client.DataTypes.DataObject, Relewise.Client', data: x })),
});
}
Expand Down

0 comments on commit 9d3b867

Please sign in to comment.