Skip to content

Commit

Permalink
fixed problem with nested keys
Browse files Browse the repository at this point in the history
  • Loading branch information
emuroni committed Aug 2, 2023
1 parent 4d441a0 commit d287d11
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
10 changes: 9 additions & 1 deletion lib/common/data/data_sources/mappers/filter_mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ class FilterMapper extends ToMapper<Filter, FilterEntity> {
case FilterOperator.lesserEqual:
return Filter.lessThanOrEquals(to.name, to.value);
case FilterOperator.inList:
return Filter.inList(to.name, to.value as List<Object>);
try {
List<dynamic> dynamicList = to.value as List<dynamic>;
List<Object> objectList = dynamicList.map((item) => item as Object)
.toList();
Filter filter = Filter.inList(to.name, objectList);
return filter;
} catch (e) {
return Filter.inList(to.name, to.value as List<Object>);
}
case FilterOperator.or:
return Filter.or((to.value as List<FilterEntity>)
.map((filter) => mapTo(filter))
Expand Down
28 changes: 21 additions & 7 deletions lib/iden3comm/data/mappers/proof_request_filters_mapper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,8 @@ class ProofRequestFiltersMapper
if (query.credentialSubject != null) {
Map<String, dynamic> request = query.credentialSubject!;
request.forEach((key, map) {
if (map != null &&
map is Map &&
map.isNotEmpty &&
context != null &&
context[key] != null &&
context[key]["@type"] != null) {
String type = context[key]["@type"];
if (map != null && map is Map && map.isNotEmpty && context != null) {
String type = getValueFromNestedString(context, key);
map.forEach((operator, value) {
if (type.contains("boolean")) {
FilterEntity? booleanFilter =
Expand Down Expand Up @@ -78,6 +73,25 @@ class ProofRequestFiltersMapper
return filters;
}

///
String getValueFromNestedString(
Map<String, dynamic> contextMap, String nestedKey) {
List<String> keys = nestedKey.split('.');
dynamic value = contextMap;
for (String key in keys) {
if (value is Map<String, dynamic> && value[key].containsKey("@context")) {
value = value[key]["@context"];
} else if (value is Map<String, dynamic> &&
value[key].containsKey("@type")) {
value = value[key]["@type"];
break;
} else {
break;
}
}
return value;
}

List<FilterEntity> _getFilterByOperator(field, operator, value) {
switch (operator) {
case '\$eq':
Expand Down

0 comments on commit d287d11

Please sign in to comment.