Skip to content

Commit 3a56200

Browse files
committed
fix: bugs when filtering by device identifier and org
2 parents 66d389d + a1cd7d6 commit 3a56200

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

src/mixins/utils.repository-mixin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export function UtilsRepositoryMixin<
8080
const planterIds = await this.getNonOrganizationPlanterIds();
8181
// if planter repository request
8282
if (model === 'planter') {
83-
return { id: { inq: planterIds } };
83+
return { planterId: { inq: planterIds } };
8484
} else {
8585
// if trees or other repository request
8686
return {
@@ -102,7 +102,7 @@ export function UtilsRepositoryMixin<
102102
return {
103103
or: [
104104
{ organizationId: { inq: entityIds } },
105-
{ id: { inq: planterIds } },
105+
{ planterId: { inq: planterIds } },
106106
],
107107
};
108108
} else {

src/repositories/planter.repository.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,11 @@ export class PlanterRepository extends UtilsRepositoryMixin<
5050
if (deviceIdentifier === null) {
5151
return `LEFT JOIN planter_registrations
5252
ON planter.id=planter_registrations.planter_id
53-
WHERE (planter_registrations.device_identifier ISNULL)
54-
GROUP BY planter.id`;
53+
WHERE (planter_registrations.device_identifier ISNULL)`;
5554
}
5655
return `JOIN planter_registrations
5756
ON planter.id=planter_registrations.planter_id
58-
WHERE (planter_registrations.device_identifier='${deviceIdentifier}')
59-
GROUP BY planter.id`;
57+
WHERE (planter_registrations.device_identifier='${deviceIdentifier}')`;
6058
}
6159

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

7371
try {
7472
if (this.dataSource.connector) {
75-
const columnNames = this.dataSource.connector.buildColumnNames(
76-
'Planter',
77-
filter,
78-
);
73+
const columnNames = this.dataSource.connector
74+
.buildColumnNames('Planter', filter)
75+
.replace('"id"', 'planter.id as "id"');
7976

8077
let selectStmt;
8178
if (deviceIdentifier) {

0 commit comments

Comments
 (0)