Greenstand / treetracker-admin-api

Legacy API microservice for the admin panel
GNU Affero General Public License v3.0
31 stars 81 forks source link

fix: include capture count in species results #577

Closed nmcharlton closed 3 years ago

nmcharlton commented 3 years ago

Resolves #573

This PR merges the species capture counts directly into the results of the standard species find query.

Unfortunately, LoopBack makes it quite fiddly to arbitrarily extend objects in API responses, so I've returned Promise<any[]> for simplicity. I'm open to suggestions for a better solution.

Ideally, we'd do the species find and get the capture counts all in one SQL query, but LoopBack makes the former a little opaque. That said, performing two separate queries and merging manually shouldn't add significant overhead.

I'll update the corresponding query in the client to not make separate api/trees/count queries (under Greenstand/treetracker-admin-client#115).