orderQuery method
Query<DynamicMap> ?
orderQuery(
- Query<
DynamicMap> firestoreQuery, - ModelQueryFilter filter,
- ModelAdapterCollectionQuery query, [
- FirestoreModelAdapterBase? adapter,
Implementation
Query<DynamicMap>? orderQuery(
Query<DynamicMap> firestoreQuery,
ModelQueryFilter filter,
ModelAdapterCollectionQuery query, [
FirestoreModelAdapterBase? adapter,
]) {
if (!enabledQuery(filter.value, filter, query, adapter)) {
return null;
}
switch (filter.type) {
case ModelQueryFilterType.orderByAsc:
if (filter.key.isEmpty) {
return null;
}
final key = filter.key!;
firestoreQuery = _fixDifferentKeys(
key,
firestoreQuery,
filter,
query,
);
firestoreQuery = firestoreQuery.orderBy(
convertQueryKey(key, filter, query, adapter),
);
break;
case ModelQueryFilterType.orderByDesc:
if (filter.key.isEmpty) {
return null;
}
final key = filter.key!;
firestoreQuery = _fixDifferentKeys(
key,
firestoreQuery,
filter,
query,
);
firestoreQuery = firestoreQuery.orderBy(
convertQueryKey(key, filter, query, adapter),
descending: true,
);
break;
case ModelQueryFilterType.limit:
final val = filter.value;
if (val is! num) {
return firestoreQuery;
}
firestoreQuery = firestoreQuery.limit(
val.toInt() * query.page,
);
break;
default:
break;
}
return firestoreQuery;
}