Greenstand / treetracker-web-map-client

The front end of the treetracker web map app.
http://map.treetracker.org
GNU Affero General Public License v3.0
64 stars 182 forks source link

Implement the `organzation` component in the /capture page #1766

Open dadiorchen opened 8 months ago

dadiorchen commented 8 months ago

The capture page, here the planting organization is wrong:

Image

We need to use the stakeholder endpoint in query API to fetch the stakeholder, (organization here)

https://github.com/Greenstand/treetracker-query-api/blob/ebf9d2cf474fc5ed8479809d54140ce5f80e3170/docs/api/spec/query-api.yaml#L273-L284

Please write the integration test and mock the data, please verify the organization info on the result page (the info return from your mock object)

khalatevarun commented 8 months ago
async function serverSideData(params) {
  const { captureid } = params;
  const tree = await getCapturesById(captureid);
  const { planting_organization_id, grower_account_id, lat, lon } = tree;
  const grower = await getGrowerById(grower_account_id);
  const country = await getCountryByLatLon(lat, lon);
  let organization; // = await getStakeHolderById(planting_organization_id);

  if (planting_organization_id) {
    log.warn('load org from planting_orgniazation_id');
    organization = await getStakeHolderById(planting_organization_id);
  } else if (grower.organization_id) {
    log.warn('load org from planter. organization_id');
    organization = await getStakeHolderById(grower.organization_id);
  } else {
    log.warn('can not load org for tree:', tree, grower);
  }

  return {
    tree,
    grower,
    organization,
    country,
  };
}

we are already using the getStakeHolderById function to fetch the stakeholder if planting_organization_id is null

@dadiorchen the handling is already done, is there any thing else that needs to be changed in the code