Skip to content

Commit

Permalink
Merge branch 'dev' into SIMSBIOHUB-644
Browse files Browse the repository at this point in the history
  • Loading branch information
mauberti-bc authored Dec 6, 2024
2 parents 160bd65 + a7bcd49 commit a838b55
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 11 deletions.
5 changes: 3 additions & 2 deletions api/src/openapi/schemas/survey.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { OpenAPIV3 } from 'openapi-types';
import { GeoJSONFeature } from './geoJson';
import { updateCreateUserPropertiesSchema } from './user';

export const surveyDetailsSchema: OpenAPIV3.SchemaObject = {
Expand Down Expand Up @@ -506,8 +507,8 @@ export const surveyBlockSchema: OpenAPIV3.SchemaObject = {
nullable: true
},
geojson: {
description: 'Geojson',
type: 'object'
...(GeoJSONFeature as object),
nullable: true
},
sample_block_count: {
description: 'Sample block count',
Expand Down
7 changes: 4 additions & 3 deletions api/src/paths/project/{projectId}/survey/{surveyId}/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ export function getSurvey(): RequestHandler {

const surveyService = new SurveyService(connection);

const surveyData = await surveyService.getSurveyById(surveyId);

// @TODO safe to delete survey supplementary data code?
const surveySupplementaryData = await surveyService.getSurveySupplementaryDataById(Number(req.params.surveyId));
const [surveyData, surveySupplementaryData] = await Promise.all([
surveyService.getSurveyById(surveyId),
surveyService.getSurveySupplementaryDataById(surveyId)
]);

await connection.commit();

Expand Down
2 changes: 1 addition & 1 deletion api/src/repositories/survey-block-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const SurveyBlockRecord = z.object({
survey_id: z.number(),
name: z.string(),
description: z.string(),
geojson: z.any(),
geojson: z.any().nullable(),
revision_count: z.number()
});
export type SurveyBlockRecord = z.infer<typeof SurveyBlockRecord>;
Expand Down
2 changes: 1 addition & 1 deletion app/src/interfaces/useSurveyApi.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ export interface IGetSurveyBlock {
name: string;
description: string;
revision_count: number;
geojson: Feature;
geojson: Feature | null;
sample_block_count: number;
}

Expand Down
6 changes: 3 additions & 3 deletions app/src/utils/datetime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ import { combineDateTime, formatTimeDifference } from './datetime';
describe('combineDateTime', () => {
it('combines date and time into an ISO string', () => {
const result = combineDateTime('2024-01-01', '12:30:00');
expect(result).toEqual('2024-01-01T12:30:00.000Z');
expect(result).toEqual('2024-01-01T12:30:00');
});

it('combines date without time into an ISO string', () => {
const result = combineDateTime('2024-01-01');
expect(result).toEqual('2024-01-01T00:00:00.000Z');
expect(result).toEqual('2024-01-01T00:00:00');
});

it('returns ISO string for a different date and time', () => {
const result = combineDateTime('2023-12-31', '23:59:59');
expect(result).toEqual('2023-12-31T23:59:59.000Z');
expect(result).toEqual('2023-12-31T23:59:59');
});

it('handles invalid date formats gracefully', () => {
Expand Down
2 changes: 1 addition & 1 deletion app/src/utils/datetime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import dayjs from 'dayjs';
import duration, { DurationUnitType } from 'dayjs/plugin/duration';
import { pluralize } from './Utils';

const TIMESTAMP_FORMAT = 'YYYY-MM-DDTHH:mm:ss.SSS[Z]';
const TIMESTAMP_FORMAT = 'YYYY-MM-DDTHH:mm:ss';

dayjs.extend(duration);

Expand Down
44 changes: 44 additions & 0 deletions database/src/seeds/03_basic_project_survey_setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ export async function seed(knex: Knex): Promise<void> {
${insertMethodTechnique(surveyId)}
${insertSurveySamplingMethodData(surveyId)}
${insertSurveySamplePeriodData(surveyId)}
${insertSurveyBlockData(surveyId)}
`);

// Insert regions into surveys
Expand Down Expand Up @@ -182,6 +183,49 @@ const insertSurveyParticipationData = (surveyId: number) => `
;
`;

const insertSurveyBlockData = (surveyId: number) => `
INSERT into survey_block
( survey_id, name, description, geojson )
VALUES
(
${surveyId},
'${faker.lorem.words(2)}',
'${faker.lorem.words(10)}',
'{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
-121.904297,
50.930738
],
[
-121.904297,
51.971346
],
[
-120.19043,
51.971346
],
[
-120.19043,
50.930738
],
[
-121.904297,
50.930738
]
]
]
},
"properties": {}
}'
)
;
`;

/**
* SQL to insert Survey Proprietor data
*
Expand Down

0 comments on commit a838b55

Please sign in to comment.