Skip to content

Commit

Permalink
feat: 'other' platform support
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley committed Nov 6, 2024
1 parent 8b76a9b commit 9cd5ebc
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
42 changes: 42 additions & 0 deletions packages/firestore/lib/web/RNFBFirestoreModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {
getDoc,
getDocs,
getCount,
getAggregateFromServer,
count,
average,
sum,
deleteDoc,
setDoc,
updateDoc,
Expand Down Expand Up @@ -215,6 +219,44 @@ export default {
});
},

aggregateQuery(appName, databaseId, path, type, filters, orders, options, aggregateQueries) {
return guard(async () => {
const firestore = getCachedFirestoreInstance(appName, databaseId);
const queryRef =
type === 'collectionGroup' ? collectionGroup(firestore, path) : collection(firestore, path);
const query = buildQuery(queryRef, filters, orders, options);
const aggregateSpec = {};

for (let i = 0; i < aggregateQueries.length; i++) {
const aggregateQuery = aggregateQueries[i];
const { aggregateType, field, key } = aggregateQuery;

switch (aggregateType) {
case 'count':
aggregateSpec[key] = count();
break;
case 'average':
aggregateSpec[key] = average(field);
break;
case 'sum':
aggregateSpec[key] = sum(field);
break;
}
}
const result = await getAggregateFromServer(query, aggregateSpec);

const data = result.data();
const response = {};
for (let i = 0; i < aggregateQueries.length; i++) {
const aggregateQuery = aggregateQueries[i];
const { key } = aggregateQuery;
response[key] = data[key];
}

return response;
});
},

/**
* Get a collection from Firestore.
* @param {string} appName - The app name.
Expand Down
2 changes: 1 addition & 1 deletion packages/firestore/lib/web/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,5 @@ function getFilterConstraint(filter) {
throw new Error('Invalid filter operator');
}

throw new Error('Invaldi filter.');
throw new Error('Invalid filter.');
}

0 comments on commit 9cd5ebc

Please sign in to comment.