Skip to content

Commit

Permalink
Merge branch 'dev' into SIMSBIOHUB-449
Browse files Browse the repository at this point in the history
  • Loading branch information
NickPhura authored Nov 13, 2024
2 parents 667f2b8 + 462b432 commit 57df62a
Show file tree
Hide file tree
Showing 119 changed files with 5,376 additions and 1,794 deletions.
22 changes: 22 additions & 0 deletions api/src/constants/dates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Date formats.
*
* See BC Gov standards: https://www2.gov.bc.ca/gov/content/governments/services-for-government/policies-procedures/web-content-development-guides/writing-for-the-web/web-style-guide/numbers
*/
export const DefaultDateFormat = 'YYYY-MM-DD'; // 2020-01-05

export const DefaultDateFormatReverse = 'DD-MM-YYYY'; // 05-01-2020

export const AltDateFormat = 'YYYY/MM/DD'; // 2020/01/05

export const AltDateFormatReverse = 'DD/MM/YYYY'; // 05/01/2020

/*
* Time formats.
*/
export const DefaultTimeFormat = 'HH:mm:ss'; // 23:00:00

/*
* Datetime formats.
*/
export const DefaultDateTimeFormat = `${DefaultDateFormat}T${DefaultTimeFormat}`; // 2020-01-05T23:00:00
2 changes: 1 addition & 1 deletion api/src/models/project-survey-attachments.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { default as dayjs } from 'dayjs';
import dayjs from 'dayjs';
import { ATTACHMENT_TYPE } from '../constants/attachments';
import { getLogger } from '../utils/logger';
import { SurveySupplementaryData } from './survey-view';
Expand Down
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;
}
23 changes: 17 additions & 6 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 @@ -60,19 +61,27 @@ export const observervationsWithSubcountDataSchema: OpenAPIV3.SchemaObject = {
nullable: true
},
latitude: {
type: 'number'
type: 'number',
nullable: true,
minimum: -90,
maximum: 90
},
longitude: {
type: 'number'
type: 'number',
nullable: true,
minimum: -180,
maximum: 180
},
count: {
type: 'integer'
},
observation_date: {
type: 'string'
type: 'string',
nullable: true
},
observation_time: {
type: 'string'
type: 'string',
nullable: true
},
survey_sample_site_name: {
type: 'string',
Expand Down Expand Up @@ -217,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 @@ -404,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
@@ -1,6 +1,7 @@
import dayjs from 'dayjs';
import { RequestHandler } from 'express';
import { Operation } from 'express-openapi';
import { DefaultDateFormat, DefaultTimeFormat } from '../../../../../../constants/dates';
import { PROJECT_PERMISSION, SYSTEM_ROLE } from '../../../../../../constants/roles';
import { getDBConnection } from '../../../../../../database/db';
import { getDeploymentSchema } from '../../../../../../openapi/schemas/deployment';
Expand Down Expand Up @@ -204,16 +205,16 @@ export function getDeploymentsInSurvey(): RequestHandler {
assignment_id: matchingBctwDeployments[0].assignment_id,
collar_id: matchingBctwDeployments[0].collar_id,
attachment_start_date: matchingBctwDeployments[0].attachment_start
? dayjs(matchingBctwDeployments[0].attachment_start).format('YYYY-MM-DD')
? dayjs(matchingBctwDeployments[0].attachment_start).format(DefaultDateFormat)
: null,
attachment_start_time: matchingBctwDeployments[0].attachment_start
? dayjs(matchingBctwDeployments[0].attachment_start).format('HH:mm:ss')
? dayjs(matchingBctwDeployments[0].attachment_start).format(DefaultTimeFormat)
: null,
attachment_end_date: matchingBctwDeployments[0].attachment_end
? dayjs(matchingBctwDeployments[0].attachment_end).format('YYYY-MM-DD')
? dayjs(matchingBctwDeployments[0].attachment_end).format(DefaultDateFormat)
: null,
attachment_end_time: matchingBctwDeployments[0].attachment_end
? dayjs(matchingBctwDeployments[0].attachment_end).format('HH:mm:ss')
? dayjs(matchingBctwDeployments[0].attachment_end).format(DefaultTimeFormat)
: null,
bctw_deployment_id: matchingBctwDeployments[0].deployment_id,
device_id: matchingBctwDeployments[0].device_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AxiosError } from 'axios';
import dayjs from 'dayjs';
import { RequestHandler } from 'express';
import { Operation } from 'express-openapi';
import { DefaultDateFormat, DefaultTimeFormat } from '../../../../../../../constants/dates';
import { PROJECT_PERMISSION, SYSTEM_ROLE } from '../../../../../../../constants/roles';
import { getDBConnection } from '../../../../../../../database/db';
import { HTTP400 } from '../../../../../../../errors/http-error';
Expand Down Expand Up @@ -211,16 +212,16 @@ export function getDeploymentById(): RequestHandler {
assignment_id: matchingBctwDeployments[0].assignment_id,
collar_id: matchingBctwDeployments[0].collar_id,
attachment_start_date: matchingBctwDeployments[0].attachment_start
? dayjs(matchingBctwDeployments[0].attachment_start).format('YYYY-MM-DD')
? dayjs(matchingBctwDeployments[0].attachment_start).format(DefaultDateFormat)
: null,
attachment_start_time: matchingBctwDeployments[0].attachment_start
? dayjs(matchingBctwDeployments[0].attachment_start).format('HH:mm:ss')
? dayjs(matchingBctwDeployments[0].attachment_start).format(DefaultTimeFormat)
: null,
attachment_end_date: matchingBctwDeployments[0].attachment_end
? dayjs(matchingBctwDeployments[0].attachment_end).format('YYYY-MM-DD')
? dayjs(matchingBctwDeployments[0].attachment_end).format(DefaultDateFormat)
: null,
attachment_end_time: matchingBctwDeployments[0].attachment_end
? dayjs(matchingBctwDeployments[0].attachment_end).format('HH:mm:ss')
? dayjs(matchingBctwDeployments[0].attachment_end).format(DefaultTimeFormat)
: null,
bctw_deployment_id: matchingBctwDeployments[0].deployment_id,
device_id: matchingBctwDeployments[0].device_id,
Expand Down
Loading

0 comments on commit 57df62a

Please sign in to comment.