Skip to content

Commit

Permalink
Merge pull request #370 from gwynndp/capture-filter-by-session-id
Browse files Browse the repository at this point in the history
Improve validations for Capture filter by session
  • Loading branch information
Kpoke committed Jan 10, 2024
2 parents 98a94f7 + c616f52 commit baf4879
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
20 changes: 20 additions & 0 deletions server/infra/database/CaptureRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@ export default class CaptureRepository extends BaseRepository<Capture> {
delete filterObject.organization_id;
}

// if we want to allow the client to pass more than one org id

// if (filterObject.organization_ids) {
// result.where(
// `${this.tableName}.planting_organization_id`,
// 'in',
// filterObject.organization_ids.split(','),
// );
// delete filterObject.organization_ids;
// }

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

result.where(filterObject);
}

Expand Down
9 changes: 9 additions & 0 deletions server/infra/database/RawCaptureRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ export default class RawCaptureRepository extends BaseRepository<RawCapture> {
delete filterObject.organization_id;
}

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

result.where(filterObject);
}

Expand Down
1 change: 1 addition & 0 deletions server/interfaces/CaptureFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import DbModel from './DbModel';
interface CaptureFilter extends DbModel {
organization_id?: Array<string> | undefined;
reference_id?: string | undefined;
session_id?: string | undefined;
grower_account_id?: string | undefined;
startDate?: string | undefined;
endDate?: string | undefined;
Expand Down
1 change: 1 addition & 0 deletions server/interfaces/RawCaptureFilter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import DbModel from './DbModel';
interface RawCaptureFilter extends DbModel {
organization_id?: Array<string> | undefined;
reference_id?: string | undefined;
session_id?: string | undefined;
grower_account_id?: string | undefined;
startDate?: string | undefined;
endDate?: string | undefined;
Expand Down
6 changes: 4 additions & 2 deletions server/routers/capturesRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ router.get(
Joi.object().keys({
grower_account_id: Joi.string().uuid(),
grower_reference_id: Joi.number(),
organization_id: Joi.array(),
organization_id: Joi.array().items(Joi.string().uuid()),
session_id: Joi.string().uuid(),
limit: Joi.number().integer().min(1).max(20000),
offset: Joi.number().integer().min(0),
startDate: Joi.string().regex(/^\d{4}-\d{2}-\d{2}$/),
Expand Down Expand Up @@ -73,7 +74,8 @@ router.get(
Joi.object().keys({
grower_account_id: Joi.string().uuid(),
grower_reference_id: Joi.number(),
organization_id: Joi.array(),
organization_id: Joi.array().items(Joi.string().uuid()),
session_id: Joi.string().uuid(),
limit: Joi.number().integer().min(1).max(20000),
offset: Joi.number().integer().min(0),
startDate: Joi.string().regex(/^\d{4}-\d{2}-\d{2}$/),
Expand Down
6 changes: 4 additions & 2 deletions server/routers/rawCapturesRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ router.get(
bulk_pack_file_name: Joi.string(),
grower_account_id: Joi.string().uuid(),
grower_reference_id: Joi.number(),
organization_id: Joi.array(),
organization_id: Joi.array().items(Joi.string().uuid()),
session_id: Joi.string().uuid(),
startDate: Joi.string().regex(/^\d{4}-\d{2}-\d{2}$/),
endDate: Joi.string().regex(/^\d{4}-\d{2}-\d{2}$/),
id: Joi.string().uuid(),
Expand Down Expand Up @@ -78,7 +79,8 @@ router.get(
bulk_pack_file_name: Joi.string(),
grower_account_id: Joi.string().uuid(),
grower_reference_id: Joi.number(),
organization_id: Joi.array(),
organization_id: Joi.array().items(Joi.string().uuid()),
session_id: Joi.string().uuid(),
startDate: Joi.string().regex(/^\d{4}-\d{2}-\d{2}$/),
endDate: Joi.string().regex(/^\d{4}-\d{2}-\d{2}$/),
id: Joi.string().uuid(),
Expand Down

0 comments on commit baf4879

Please sign in to comment.