From 0426228f47c661bbb7991f939d544b6eb166ecdf Mon Sep 17 00:00:00 2001 From: deanchen Date: Sat, 8 Oct 2022 17:50:11 +0800 Subject: [PATCH] fix: org number --- server/infra/database/TreeRepository.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/server/infra/database/TreeRepository.ts b/server/infra/database/TreeRepository.ts index 829cf988..c7e2bf14 100644 --- a/server/infra/database/TreeRepository.ts +++ b/server/infra/database/TreeRepository.ts @@ -63,8 +63,8 @@ export default class TreeRepository extends BaseRepository { COUNT(*) FROM trees LEFT JOIN planter ON trees.planter_id = planter.id - LEFT JOIN entity ON entity.id = planter.organization_id - WHERE entity.id = ${organization_id} + WHERE + planter.organization_id in ( SELECT entity_id from getEntityRelationshipChildren(${organization_id})) `; const total = await this.session.getDB().raw(totalSql); return parseInt(total.rows[0].count.toString()); @@ -87,7 +87,8 @@ export default class TreeRepository extends BaseRepository { LEFT JOIN region on ST_WITHIN(trees.estimated_geometric_location, region.geom) and region.type_id in (select id from region_type where type = 'country') - WHERE entity.id = ${organization_id} + WHERE + planter.organization_id in ( SELECT entity_id from getEntityRelationshipChildren(${organization_id})) LIMIT ${limit} OFFSET ${offset} `;