Skip to content

Commit

Permalink
Merge branch 'mdENV' of https://github.com/bcgov/biohubbc into mdENV
Browse files Browse the repository at this point in the history
  • Loading branch information
MacQSL committed Nov 13, 2024
2 parents 943add1 + d7e9df4 commit b3840f9
Show file tree
Hide file tree
Showing 95 changed files with 4,677 additions and 1,675 deletions.
19 changes: 19 additions & 0 deletions api/src/models/sampling-locations-view.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
export interface ISiteAdvancedFilters {
survey_id?: number;
keyword?: string;
system_user_id?: number;
}

export interface IMethodAdvancedFilters {
survey_id?: number;
sample_site_id?: number;
keyword?: string;
system_user_id?: number;
}

export interface IPeriodAdvancedFilters {
survey_id?: number;
sample_site_id?: number;
sample_method_id?: number;
system_user_id?: number;
}
7 changes: 5 additions & 2 deletions api/src/openapi/schemas/observation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { OpenAPIV3 } from 'openapi-types';
import { paginationResponseSchema } from './pagination';
import { SampleLocationSchema } from './sample-site';

export const observervationsWithSubcountDataSchema: OpenAPIV3.SchemaObject = {
type: 'object',
Expand Down Expand Up @@ -225,7 +226,8 @@ export const observervationsWithSubcountDataSchema: OpenAPIV3.SchemaObject = {
'qualitative_measurements',
'quantitative_measurements',
'qualitative_environments',
'quantitative_environments'
'quantitative_environments',
'sample_sites'
],
properties: {
observationCount: {
Expand Down Expand Up @@ -412,7 +414,8 @@ export const observervationsWithSubcountDataSchema: OpenAPIV3.SchemaObject = {
}
}
}
}
},
sample_sites: SampleLocationSchema
}
},
pagination: { ...paginationResponseSchema }
Expand Down
156 changes: 156 additions & 0 deletions api/src/openapi/schemas/sample-site.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
import { OpenAPIV3 } from 'openapi-types';
import { techniqueSimpleViewSchema } from './technique';

export const SampleLocationSchema: OpenAPIV3.SchemaObject = {
type: 'array',
description: 'Sample location response object (includes sites, techniques, periods, stratums, blocks).',
items: {
type: 'object',
additionalProperties: false,
required: ['survey_sample_site_id', 'survey_id', 'name', 'description', 'geometry_type'],
properties: {
survey_sample_site_id: {
type: 'integer',
minimum: 1
},
survey_id: {
type: 'integer',
minimum: 1
},
name: {
type: 'string',
maxLength: 50
},
description: {
type: 'string',
maxLength: 250
},
geometry_type: {
type: 'string',
maxLength: 50
},
sample_methods: {
type: 'array',
required: [
'survey_sample_method_id',
'survey_sample_site_id',
'technique',
'method_response_metric_id',
'sample_periods'
],
items: {
type: 'object',
additionalProperties: false,
properties: {
survey_sample_method_id: {
type: 'integer',
minimum: 1
},
survey_sample_site_id: {
type: 'integer',
minimum: 1
},
technique: techniqueSimpleViewSchema,
method_response_metric_id: {
type: 'integer',
minimum: 1
},
description: {
type: 'string',
maxLength: 250
},
sample_periods: {
type: 'array',
required: [
'survey_sample_period_id',
'survey_sample_method_id',
'start_date',
'start_time',
'end_date',
'end_time'
],
items: {
type: 'object',
additionalProperties: false,
properties: {
survey_sample_period_id: {
type: 'integer',
minimum: 1
},
survey_sample_method_id: {
type: 'integer',
minimum: 1
},
start_date: {
type: 'string'
},
start_time: {
type: 'string',
nullable: true
},
end_date: {
type: 'string'
},
end_time: {
type: 'string',
nullable: true
}
}
}
}
}
}
},
blocks: {
type: 'array',
items: {
type: 'object',
additionalProperties: false,
required: ['survey_sample_block_id', 'survey_sample_site_id', 'survey_block_id'],
properties: {
survey_sample_block_id: {
type: 'number'
},
survey_sample_site_id: {
type: 'number'
},
survey_block_id: {
type: 'number'
},
name: {
type: 'string'
},
description: {
type: 'string'
}
}
}
},
stratums: {
type: 'array',
items: {
type: 'object',
additionalProperties: false,
required: ['survey_sample_stratum_id', 'survey_sample_site_id', 'survey_stratum_id'],
properties: {
survey_sample_stratum_id: {
type: 'number'
},
survey_sample_site_id: {
type: 'number'
},
survey_stratum_id: {
type: 'number'
},
name: {
type: 'string'
},
description: {
type: 'string'
}
}
}
}
}
}
};
3 changes: 2 additions & 1 deletion api/src/paths/observation/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ describe('findObservations', () => {
qualitative_measurements: [],
quantitative_measurements: [],
qualitative_environments: [],
quantitative_environments: []
quantitative_environments: [],
sample_sites: []
});
expect(mockRes.jsonValue.pagination).not.to.be.null;

Expand Down
3 changes: 2 additions & 1 deletion api/src/paths/observation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ export function findObservations(): RequestHandler {
qualitative_measurements: [],
quantitative_measurements: [],
qualitative_environments: [],
quantitative_environments: []
quantitative_environments: [],
sample_sites: []
},
pagination: makePaginationResponse(observationsTotalCount, paginationOptions)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ describe('getSurveyObservations', () => {
qualitative_measurements: [],
quantitative_measurements: [],
qualitative_environments: [],
quantitative_environments: []
quantitative_environments: [],
sample_sites: []
}
});

Expand Down Expand Up @@ -190,7 +191,8 @@ describe('getSurveyObservations', () => {
qualitative_measurements: [],
quantitative_measurements: [],
qualitative_environments: [],
quantitative_environments: []
quantitative_environments: [],
sample_sites: []
},
pagination: {
total: 59,
Expand Down Expand Up @@ -220,7 +222,8 @@ describe('getSurveyObservations', () => {
qualitative_measurements: [],
quantitative_measurements: [],
qualitative_environments: [],
quantitative_environments: []
quantitative_environments: [],
sample_sites: []
}
});

Expand Down Expand Up @@ -248,7 +251,8 @@ describe('getSurveyObservations', () => {
qualitative_measurements: [],
quantitative_measurements: [],
qualitative_environments: [],
quantitative_environments: []
quantitative_environments: [],
sample_sites: []
},
pagination: {
total: 50,
Expand Down Expand Up @@ -278,7 +282,8 @@ describe('getSurveyObservations', () => {
qualitative_measurements: [],
quantitative_measurements: [],
qualitative_environments: [],
quantitative_environments: []
quantitative_environments: [],
sample_sites: []
}
});

Expand All @@ -301,7 +306,8 @@ describe('getSurveyObservations', () => {
qualitative_measurements: [],
quantitative_measurements: [],
qualitative_environments: [],
quantitative_environments: []
quantitative_environments: [],
sample_sites: []
},
pagination: {
total: 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import { CritterbaseService, getCritterbaseUser } from '../../../../../../servic
import { InsertUpdateObservations, ObservationService } from '../../../../../../services/observation-service';
import { ObservationSubCountEnvironmentService } from '../../../../../../services/observation-subcount-environment-service';
import { getLogger } from '../../../../../../utils/logger';
import { ensureCompletePaginationOptions, makePaginationResponse } from '../../../../../../utils/pagination';
import { ApiPaginationOptions } from '../../../../../../zod-schema/pagination';
import {
ensureCompletePaginationOptions,
makePaginationOptionsFromRequest,
makePaginationResponse
} from '../../../../../../utils/pagination';

const defaultLog = getLogger('/api/project/{projectId}/survey/{surveyId}/observation');

Expand Down Expand Up @@ -375,19 +378,11 @@ export function getSurveyObservations(): RequestHandler {
const surveyId = Number(req.params.surveyId);
defaultLog.debug({ label: 'getSurveyObservations', surveyId });

const page: number | undefined = req.query.page ? Number(req.query.page) : undefined;
const limit: number | undefined = req.query.limit ? Number(req.query.limit) : undefined;
const order: 'asc' | 'desc' | undefined = req.query.order ? (String(req.query.order) as 'asc' | 'desc') : undefined;

const sortQuery: string | undefined = req.query.sort ? String(req.query.sort) : undefined;
let sort = sortQuery;

if (sortQuery && samplingSiteSortingColumnName[sortQuery]) {
sort = samplingSiteSortingColumnName[sortQuery];
const paginationOptions = makePaginationOptionsFromRequest(req);
if (paginationOptions.sort && samplingSiteSortingColumnName[paginationOptions.sort]) {
paginationOptions.sort = samplingSiteSortingColumnName[paginationOptions.sort];
}

const paginationOptions: Partial<ApiPaginationOptions> = { page, limit, order, sort };

const connection = getDBConnection(req.keycloak_token);

try {
Expand Down
Loading

0 comments on commit b3840f9

Please sign in to comment.