Skip to content

Commit

Permalink
Fix document path destructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianoertel committed Sep 25, 2024
1 parent ca3702b commit a5bcabf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/helpers/query/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,13 @@ export const fetchDocumentsById = async (collection, docIds, select = [], db = F
return response.data
.filter(({ found }) => found)
.map(({ found }) => {
const [, , collectionName, docId] = found.name.split('/');
// Deconstruct the document path as Firebase conveniently doesn't return basic information like the record ID as
// part of the documentation data. Whilst this is a bit hacky, it works.
const pathParts = found.name.split('/');
const documentId = pathParts.pop();
const collectionName = pathParts.pop();
return {
id: docId,
id: documentId,
collection: collectionName,
..._mapValues(found.fields, (value) => convertValues(value)),
};
Expand Down

0 comments on commit a5bcabf

Please sign in to comment.