Skip to content

Commit

Permalink
Merge pull request #305 from gwynndp/grower-ref-id
Browse files Browse the repository at this point in the history
Add reference_id as a valid field for growers query
  • Loading branch information
Kpoke authored Apr 25, 2023
2 parents f6c33bf + 3a8b1cc commit d5112c2
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 1 deletion.
9 changes: 9 additions & 0 deletions server/infra/database/CaptureRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,15 @@ export default class CaptureRepository extends BaseRepository<Capture> {
delete filterObject.reference_id;
}

if (filterObject.grower_reference_id) {
result.where(
`treetracker.grower_account.reference_id`,
'=',
filterObject.grower_reference_id,
);
delete filterObject.grower_reference_id;
}

if (filterObject.organization_id) {
result.where(`${this.tableName}.planting_organization_id`, 'in', [
...filterObject.organization_id,
Expand Down
11 changes: 10 additions & 1 deletion server/infra/database/GrowerAccountRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ export default class GrowerAccountRepository extends BaseRepository<GrowerAccoun
delete filterObject.id;
}

if (filterObject.reference_id) {
result.where(
`${this.tableName}.reference_id`,
'=',
filterObject.reference_id,
);
delete filterObject.reference_id;
}

if (filterObject.first_name) {
result.where(
`${this.tableName}.first_name`,
Expand Down Expand Up @@ -357,7 +366,7 @@ export default class GrowerAccountRepository extends BaseRepository<GrowerAccoun
.select(
knex.raw(`
COUNT(${this.tableName}.id) AS count
FROM ${this.tableName}
FROM ${this.tableName}
`),
)
.where((builder) => this.filterWhereBuilder(filter, builder))
Expand Down
21 changes: 21 additions & 0 deletions server/infra/database/RawCaptureRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,15 @@ export default class RawCaptureRepository extends BaseRepository<RawCapture> {
delete filterObject.reference_id;
}

if (filterObject.grower_reference_id) {
result.where(
`treetracker.grower_account.reference_id`,
'=',
filterObject.grower_reference_id,
);
delete filterObject.grower_reference_id;
}

if (filterObject.organization_id) {
result.where(`field_data.session.organization_id`, 'in', [
...filterObject.organization_id,
Expand Down Expand Up @@ -152,6 +161,12 @@ export default class RawCaptureRepository extends BaseRepository<RawCapture> {
'=',
'field_data.wallet_registration.id',
)
.leftJoin(
'treetracker.grower_account',
'field_data.wallet_registration.grower_account_id',
'=',
'treetracker.grower_account.id',
)
.leftJoin(
'field_data.device_configuration',
'field_data.session.device_configuration_id',
Expand Down Expand Up @@ -202,6 +217,12 @@ export default class RawCaptureRepository extends BaseRepository<RawCapture> {
'=',
'field_data.wallet_registration.id',
)
.leftJoin(
'treetracker.grower_account',
'field_data.wallet_registration.grower_account_id',
'=',
'treetracker.grower_account.id',
)
.leftJoin(
'field_data.device_configuration',
'field_data.session.device_configuration_id',
Expand Down
2 changes: 2 additions & 0 deletions server/routers/capturesRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ router.get(
query,
Joi.object().keys({
grower_account_id: Joi.string().uuid(),
grower_reference_id: Joi.number(),
organization_id: Joi.array(),
limit: Joi.number().integer().min(1).max(20000),
offset: Joi.number().integer().min(0),
Expand Down Expand Up @@ -71,6 +72,7 @@ router.get(
query,
Joi.object().keys({
grower_account_id: Joi.string().uuid(),
grower_reference_id: Joi.number(),
organization_id: Joi.array(),
limit: Joi.number().integer().min(1).max(20000),
offset: Joi.number().integer().min(0),
Expand Down
2 changes: 2 additions & 0 deletions server/routers/growerAccountsRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ router.get(
keyword: Joi.string(),
organization_id: Joi.array(),
id: Joi.string().uuid(),
reference_id: Joi.number(),
person_id: Joi.string().uuid(),
device_identifier: Joi.string(),
first_name: Joi.string(),
Expand Down Expand Up @@ -139,6 +140,7 @@ router.get(
keyword: Joi.string(),
organization_id: Joi.array(),
id: Joi.string().uuid(),
reference_id: Joi.number(),
person_id: Joi.string().uuid(),
device_identifier: Joi.string(),
first_name: Joi.string(),
Expand Down
2 changes: 2 additions & 0 deletions server/routers/rawCapturesRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ router.get(
status: Joi.string().allow('unprocessed', 'approved', 'rejected'),
bulk_pack_file_name: Joi.string(),
grower_account_id: Joi.string().uuid(),
grower_reference_id: Joi.number(),
organization_id: Joi.array(),
startDate: Joi.string().regex(/^\d{4}-\d{2}-\d{2}$/),
endDate: Joi.string().regex(/^\d{4}-\d{2}-\d{2}$/),
Expand Down Expand Up @@ -76,6 +77,7 @@ router.get(
status: Joi.string().allow('unprocessed', 'approved', 'rejected'),
bulk_pack_file_name: Joi.string(),
grower_account_id: Joi.string().uuid(),
grower_reference_id: Joi.number(),
organization_id: Joi.array(),
startDate: Joi.string().regex(/^\d{4}-\d{2}-\d{2}$/),
endDate: Joi.string().regex(/^\d{4}-\d{2}-\d{2}$/),
Expand Down

0 comments on commit d5112c2

Please sign in to comment.