the functions code is in dart:
Future main(final context) async {
final body = (context.req.body as String?).isNullOrEmpty
? {}
: json.decode(context.req.body);
final bounds =
body['bounds'] == null ? null : LatLngBounds.fromJson(body['bounds']);
final geoQueries = bounds == null
? []
: [
Query.greaterThanEqual('lat', bounds.sw.lat),
Query.lessThanEqual('lat', bounds.ne.lat),
Query.greaterThanEqual('lon', bounds.sw.lng),
Query.lessThanEqual('lon', bounds.ne.lng),
];
try {
final hubDocuments = await databases.listDocuments(
databaseId: dbID,
collectionId: hubsID,
queries: [Query.limit(100), ...geoQueries],
);
final postDocuments = await databases.listDocuments(
databaseId: dbID,
collectionId: postsID,
queries: [Query.limit(100), ...geoQueries],
);
final filteredPosts = postDocuments.documents
.where((post) => (post.data['hubID'] as String?).isNullOrEmpty)
.toList();
context.log('hubs: ${hubDocuments.documents.length}');
context.log('all posts: ${postDocuments.documents.length}');
context.log('not connected posts: ${filteredPosts.length}');
final responseData =
[...hubDocuments.documents, ...filteredPosts].map((document) {
final runtimeType = document.data['runtimeType'];
if (runtimeType == null || runtimeType == 'null') {
context.error('runtimeType is null for ${document.data['\$id']}');
}