Skip to content

Commit

Permalink
Merge pull request #349 from aayushgauba/main
Browse files Browse the repository at this point in the history
fix:organization_counter for species
  • Loading branch information
dadiorchen committed Jul 24, 2023
2 parents 01e6d7c + 9e52d0c commit 91f70d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
43 changes: 22 additions & 21 deletions server/infra/database/SpeciesRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,30 +43,31 @@ export default class SpeciesRepository extends BaseRepository<Species> {
async countByOrganization(organization_id: number) {
const totalSql = `
SELECT
species_id as id, total, ts.name, ts.desc
FROM
(
SELECT
ss.species_id, count(ss.species_id) as total
from webmap.species_stat ss
WHERE
ss.planter_id IN (
SELECT
id
FROM planter p
species_id as id, total, ts.name, ts.desc
FROM
(
SELECT
ss.species_id, count(ss.species_id) as total
from webmap.species_stat ss
WHERE
p.organization_id in ( SELECT entity_id from getEntityRelationshipChildren(${organization_id}))
)
OR
ss.planting_organization_id = ${organization_id}
GROUP BY ss.species_id
) s_count
JOIN tree_species ts
ON ts.id = s_count.species_id
ORDER BY total DESC
ss.planter_id IN (
SELECT
id
FROM planter p
WHERE
p.organization_id in ( SELECT entity_id from getEntityRelationshipChildren(${organization_id}))
)
OR
ss.planting_organization_id = ${organization_id}
GROUP BY ss.species_id
) s_count
JOIN tree_species ts
ON ts.id = s_count.species_id
ORDER BY total DESC
`;
const total = await this.session.getDB().raw(totalSql);
return parseInt(total.rows[0].count.toString());
return parseInt(total.rows.length);
}

async getByPlanter(planter_id: number, options: FilterOptions) {
Expand Down
2 changes: 1 addition & 1 deletion server/infra/database/SpeciesRepositoryV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class SpeciesRepositoryV2 extends BaseRepository<Species> {
ORDER BY total DESC
`;
const total = await this.session.getDB().raw(totalSql);
return parseInt(total.rows[0].count.toString());
return parseInt(total.rows.length);
}

async getByPlanter(planter_id: number, options: FilterOptions) {
Expand Down

0 comments on commit 91f70d1

Please sign in to comment.