Skip to content

Commit

Permalink
fix: bugs when filtering by device identifier and org
Browse files Browse the repository at this point in the history
  • Loading branch information
gwynndp committed Nov 7, 2021
2 parents 66d389d + a1cd7d6 commit 3a56200
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/mixins/utils.repository-mixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function UtilsRepositoryMixin<
const planterIds = await this.getNonOrganizationPlanterIds();
// if planter repository request
if (model === 'planter') {
return { id: { inq: planterIds } };
return { planterId: { inq: planterIds } };
} else {
// if trees or other repository request
return {
Expand All @@ -102,7 +102,7 @@ export function UtilsRepositoryMixin<
return {
or: [
{ organizationId: { inq: entityIds } },
{ id: { inq: planterIds } },
{ planterId: { inq: planterIds } },
],
};
} else {
Expand Down
13 changes: 5 additions & 8 deletions src/repositories/planter.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ export class PlanterRepository extends UtilsRepositoryMixin<
if (deviceIdentifier === null) {
return `LEFT JOIN planter_registrations
ON planter.id=planter_registrations.planter_id
WHERE (planter_registrations.device_identifier ISNULL)
GROUP BY planter.id`;
WHERE (planter_registrations.device_identifier ISNULL)`;
}
return `JOIN planter_registrations
ON planter.id=planter_registrations.planter_id
WHERE (planter_registrations.device_identifier='${deviceIdentifier}')
GROUP BY planter.id`;
WHERE (planter_registrations.device_identifier='${deviceIdentifier}')`;
}

// default .find() wasn't applying the org filters
Expand All @@ -72,10 +70,9 @@ export class PlanterRepository extends UtilsRepositoryMixin<

try {
if (this.dataSource.connector) {
const columnNames = this.dataSource.connector.buildColumnNames(
'Planter',
filter,
);
const columnNames = this.dataSource.connector
.buildColumnNames('Planter', filter)
.replace('"id"', 'planter.id as "id"');

let selectStmt;
if (deviceIdentifier) {
Expand Down

0 comments on commit 3a56200

Please sign in to comment.