Skip to content

Commit c91ebd7

Browse files
authored
Merge pull request #599 from gwynndp/fix-device-filter-bug
fix(planters): bugs when filtering by device identifier and org
2 parents 2cebcaf + a1cd7d6 commit c91ebd7

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

src/repositories/planter.repository.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export class PlanterRepository extends DefaultCrudRepository<
7777
if (organizationId === null) {
7878
const planterIds = await this.getNonOrganizationPlanterIds();
7979
return {
80-
and: [{ organizationId: null }, { id: { inq: planterIds } }],
80+
and: [{ organizationId: null }, { 'planter.id': { inq: planterIds } }],
8181
};
8282
} else {
8383
const planterIds = await this.getPlanterIdsByOrganizationId(
@@ -88,7 +88,7 @@ export class PlanterRepository extends DefaultCrudRepository<
8888
return {
8989
or: [
9090
{ organizationId: { inq: entityIds } },
91-
{ id: { inq: planterIds } },
91+
{ 'planter.id': { inq: planterIds } },
9292
],
9393
};
9494
}
@@ -113,13 +113,11 @@ export class PlanterRepository extends DefaultCrudRepository<
113113
if (deviceIdentifier === null) {
114114
return `LEFT JOIN planter_registrations
115115
ON planter.id=planter_registrations.planter_id
116-
WHERE (planter_registrations.device_identifier ISNULL)
117-
GROUP BY planter.id`;
116+
WHERE (planter_registrations.device_identifier ISNULL)`;
118117
}
119118
return `JOIN planter_registrations
120119
ON planter.id=planter_registrations.planter_id
121-
WHERE (planter_registrations.device_identifier='${deviceIdentifier}')
122-
GROUP BY planter.id`;
120+
WHERE (planter_registrations.device_identifier='${deviceIdentifier}')`;
123121
}
124122

125123
// loopback .find() wasn't applying the org filters
@@ -134,10 +132,9 @@ export class PlanterRepository extends DefaultCrudRepository<
134132

135133
try {
136134
if (this.dataSource.connector) {
137-
const columnNames = this.dataSource.connector.buildColumnNames(
138-
'Planter',
139-
filter,
140-
);
135+
const columnNames = this.dataSource.connector
136+
.buildColumnNames('Planter', filter)
137+
.replace('"id"', 'planter.id as "id"');
141138

142139
let selectStmt;
143140
if (deviceIdentifier) {

0 commit comments

Comments
 (0)