Skip to content

Commit

Permalink
SIMSBIOHUB-627: Find Telemetry (#1434)
Browse files Browse the repository at this point in the history
- Update telemetry find endpoint and summary list components.
- Update summary container loading animation triggers
- Remove old telemetry-service.ts
  • Loading branch information
NickPhura authored Nov 28, 2024
1 parent 9f7d521 commit fdc21f7
Show file tree
Hide file tree
Showing 25 changed files with 1,075 additions and 388 deletions.
4 changes: 3 additions & 1 deletion api/src/models/animal-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export interface IAnimalAdvancedFilters {
*/
itis_tsn?: number;
/**
* Filter results by system user id (not necessarily the user making the request).
* Filter results by system user id.
*
* Note: This is not the id of the user making the request.
*
* @type {number}
* @memberof IAnimalAdvancedFilters
Expand Down
50 changes: 50 additions & 0 deletions api/src/models/observation-view.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,61 @@
export interface IObservationAdvancedFilters {
keyword?: string;
/**
* Filter results by ITIS TSNs.
*
* @type {number[]}
* @memberof IObservationAdvancedFilters
*/
itis_tsns?: number[];
/**
* Filter results by ITIS TSN.
*
* @type {number}
* @memberof IObservationAdvancedFilters
*/
itis_tsn?: number;
/**
* Filter results by start date.
*
* @type {string}
* @memberof IObservationAdvancedFilters
*/
start_date?: string;
/**
* Filter results by end date.
*
* @type {string}
* @memberof IObservationAdvancedFilters
*/
end_date?: string;
/**
* Filter results by start time.
*
* @type {string}
* @memberof IObservationAdvancedFilters
*/
start_time?: string;
/**
* Filter results by end time.
*
* @type {string}
* @memberof IObservationAdvancedFilters
*/
end_time?: string;
/**
* Filter results by minimum count.
*
* @type {number}
* @memberof IObservationAdvancedFilters
*/
min_count?: number;
/**
* Filter results by system user id.
*
* Note: This is not the id of the user making the request.
*
* @type {number}
* @memberof IObservationAdvancedFilters
*/
system_user_id?: number;
}
32 changes: 32 additions & 0 deletions api/src/models/project-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,42 @@ import { ProjectUser } from '../repositories/project-participation-repository';
import { SystemUser } from '../repositories/user-repository';

export interface IProjectAdvancedFilters {
/**
* Filter results by keyword.
*
* @type {string}
* @memberof IProjectAdvancedFilters
*/
keyword?: string;
/**
* Filter results by ITIS TSN.
*
* @type {number}
* @memberof IProjectAdvancedFilters
*/
itis_tsn?: number;
/**
* Filter results by ITIS TSNs
*
* @type {number[]}
* @memberof IProjectAdvancedFilters
*/
itis_tsns?: number[];
/**
* Filter results by system user id.
*
* Note: This is not the id of the user making the request.
*
* @type {number}
* @memberof IProjectAdvancedFilters
*/
system_user_id?: number;
/**
* Filter results by project name.
*
* @type {string}
* @memberof IProjectAdvancedFilters
*/
project_name?: string;
}

Expand Down
44 changes: 44 additions & 0 deletions api/src/models/survey-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,56 @@ import { SystemUser } from '../repositories/user-repository';
import { ITaxonomyWithEcologicalUnits } from '../services/platform-service';

export interface ISurveyAdvancedFilters {
/**
* Filter results by keyword.
*
* @type {string}
* @memberof ISurveyAdvancedFilters
*/
keyword?: string;
/**
* Filter results by ITIS TSN.
*
* @type {number}
* @memberof ISurveyAdvancedFilters
*/
itis_tsn?: number;
/**
* Filter results by ITIS TSNs.
*
* @type {number[]}
* @memberof ISurveyAdvancedFilters
*/
itis_tsns?: number[];
/**
* Filter results by start date.
*
* @type {string}
* @memberof ISurveyAdvancedFilters
*/
start_date?: string;
/**
* Filter results by end date.
*
* @type {string}
* @memberof ISurveyAdvancedFilters
*/
end_date?: string;
/**
* Filter results by survey name.
*
* @type {string}
* @memberof ISurveyAdvancedFilters
*/
survey_name?: string;
/**
* Filter results by system user id.
*
* Note: This is not the id of the user making the request.
*
* @type {number}
* @memberof ISurveyAdvancedFilters
*/
system_user_id?: number;
}

Expand Down
20 changes: 18 additions & 2 deletions api/src/models/telemetry-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,30 @@ export interface IAllTelemetryAdvancedFilters {
*/
itis_tsn?: number;
/**
* Filter results by system user id (not necessarily the user making the request).
* Filter results by start date.
*
* @type {string}
* @memberof IObservationAdvancedFilters
*/
start_date?: string;
/**
* Filter results by end date.
*
* @type {string}
* @memberof IObservationAdvancedFilters
*/
end_date?: string;
/**
* Filter results by system user id.
*
* Note: This is not the id of the user making the request.
*
* @type {number}
* @memberof IAnimalAdvancedFilters
*/
system_user_id?: number;
/**
* Filter results by survey ids
* Filter results by survey ids.
*
* @type {number[]}
* @memberof IAnimalAdvancedFilters
Expand Down
17 changes: 11 additions & 6 deletions api/src/paths/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,16 @@ GET.apiDoc = {
'project_roles',
'administrative_activity_status_type',
'intended_outcomes',
'survey_jobs',
'site_selection_strategies',
'sample_methods',
'survey_progress',
'method_response_metrics',
'attractants',
'observation_subcount_signs',
'telemetry_device_makes',
'frequency_units',
'alert_types',
'vantages'
],
properties: {
Expand Down Expand Up @@ -406,13 +411,13 @@ GET.apiDoc = {
}
}
},
alert_types: {
frequency_units: {
type: 'array',
description: 'Alert type options for system administrators managing alert messages.',
description: 'Frequency unit types.',
items: {
type: 'object',
additionalProperties: false,
required: ['id', 'name', 'description'],
required: ['id', 'name'],
properties: {
id: {
type: 'integer',
Expand All @@ -427,13 +432,13 @@ GET.apiDoc = {
}
}
},
frequency_units: {
alert_types: {
type: 'array',
description: 'Frequency unit types.',
description: 'Alert type options for system administrators managing alert messages.',
items: {
type: 'object',
additionalProperties: false,
required: ['id', 'name'],
required: ['id', 'name', 'description'],
properties: {
id: {
type: 'integer',
Expand Down
34 changes: 21 additions & 13 deletions api/src/paths/telemetry/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ import sinonChai from 'sinon-chai';
import { SYSTEM_ROLE } from '../../constants/roles';
import * as db from '../../database/db';
import { HTTPError } from '../../errors/http-error';
import {
Telemetry,
TelemetryVendorEnum
} from '../../repositories/telemetry-repositories/telemetry-vendor-repository.interface';
import { SystemUser } from '../../repositories/user-repository';
import { FindTelemetryResponse, TelemetryService } from '../../services/telemetry-service';
import { TelemetryVendorService } from '../../services/telemetry-services/telemetry-vendor-service';
import { KeycloakUserInformation } from '../../utils/keycloak-utils';
import { getMockDBConnection, getRequestHandlerMocks } from '../../__mocks__/db';
import { findTelemetry } from './index';
Expand All @@ -19,19 +23,18 @@ describe('findTelemetry', () => {
});

it('finds and returns telemetry', async () => {
const mockFindTelemetryResponse: FindTelemetryResponse[] = [
const mockFindTelemetryResponse: Telemetry[] = [
{
telemetry_id: '789-789-789',
deployment_id: 2,
critter_id: 3,
acquisition_date: '2021-01-01',
vendor: TelemetryVendorEnum.MANUAL,
serial: '123',
latitude: 49.123,
longitude: -126.123,
telemetry_type: 'vendor',
device_id: 123,
bctw_deployment_id: '123-123-123',
critter_id: 1,
deployment_id: 2,
critterbase_critter_id: '456-456-456',
animal_id: '678-678-678'
elevation: null,
temperature: null
}
];

Expand All @@ -45,14 +48,17 @@ describe('findTelemetry', () => {
sinon.stub(db, 'getDBConnection').returns(mockDBConnection);

const findTelemetryStub = sinon
.stub(TelemetryService.prototype, 'findTelemetry')
.stub(TelemetryVendorService.prototype, 'findTelemetry')
.resolves(mockFindTelemetryResponse);

const findTelemetryCountStub = sinon.stub(TelemetryVendorService.prototype, 'findTelemetryCount').resolves(1);

const { mockReq, mockRes, mockNext } = getRequestHandlerMocks();

mockReq.query = {
keyword: 'keyword',
itis_tsns: ['123456'],
start_date: '2021-01-01',
end_date: '2021-02-01',
system_user_id: '11',
page: '2',
limit: '10',
Expand All @@ -72,6 +78,7 @@ describe('findTelemetry', () => {
expect(mockDBConnection.commit).to.have.been.calledOnce;

expect(findTelemetryStub).to.have.been.calledOnceWith(true, 20, sinon.match.object, sinon.match.object);
expect(findTelemetryCountStub).to.have.been.calledOnceWith(true, 20, sinon.match.object);

expect(mockRes.jsonValue.telemetry).to.eql(mockFindTelemetryResponse);
expect(mockRes.jsonValue.pagination).not.to.be.null;
Expand All @@ -91,14 +98,15 @@ describe('findTelemetry', () => {
sinon.stub(db, 'getDBConnection').returns(mockDBConnection);

const findTelemetryStub = sinon
.stub(TelemetryService.prototype, 'findTelemetry')
.stub(TelemetryVendorService.prototype, 'findTelemetry')
.rejects(new Error('a test error'));

const { mockReq, mockRes, mockNext } = getRequestHandlerMocks();

mockReq.query = {
keyword: 'keyword',
itis_tsns: ['123456'],
start_date: '2021-01-01',
end_date: '2021-02-01',
system_user_id: '11',
page: '2',
limit: '10',
Expand Down
Loading

0 comments on commit fdc21f7

Please sign in to comment.