Skip to content

Commit

Permalink
Merge pull request #27 from Relewise/feat/add-missing-dataValue-types
Browse files Browse the repository at this point in the history
add multilingualcollection, fix bug in objectcollection
  • Loading branch information
mzanoni authored Jan 11, 2023
2 parents 65b5dae + 9d3b867 commit e62073c
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 e62073c

Please sign in to comment.