getCollection method

  1. @override
FutureOr<JsonObject> getCollection({
  1. required String collectionPath,
  2. String? changeRootName,
})
override

Implementation

@override
FutureOr<JsonObject> getCollection({
  required String collectionPath,
  String? changeRootName,
}) async {
  final collectionParent = di<PathUtils>().parent(collectionPath);
  final collectionName = di<PathUtils>().name(collectionPath);

  final collectionDocuments = await _getCollectionDocuments(
    documentPath:
        firestorePathUtils.absolutePathFromRelative(collectionParent),
    collectionName: collectionName,
  );

  final colJson = JsonObject();
  final docsArrayJson = <JsonObject>[];

  // 1 go through all the documents in the initial collection
  for (final collectionDocument in collectionDocuments) {
    // 2 parse the document
    final docJson = await _getDocumentJson(
      document: collectionDocument,
      json: JsonObject(),
    );

    docsArrayJson.add(docJson);
  }

  colJson[documentMapper.metaName] = collectionName;
  colJson[documentMapper.metaDocuments] = docsArrayJson;

  return colJson;
}