From 82c8d9fa712c6d9e65fda8b11b4a563a0eb79d81 Mon Sep 17 00:00:00 2001 From: Macgregor Aubertin-Young <108430771+mauberti-bc@users.noreply.github.com> Date: Tue, 3 Dec 2024 10:11:45 -0800 Subject: [PATCH 1/3] BugFix: Change Date Format from UTC to Local Time in combineDatetime (#1441) change UTC to local time in date format string --- app/src/utils/datetime.test.ts | 6 +++--- app/src/utils/datetime.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/src/utils/datetime.test.ts b/app/src/utils/datetime.test.ts index 582fcd1e72..c9257c9a10 100644 --- a/app/src/utils/datetime.test.ts +++ b/app/src/utils/datetime.test.ts @@ -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', () => { diff --git a/app/src/utils/datetime.ts b/app/src/utils/datetime.ts index 7984ce88f8..60eca541fa 100644 --- a/app/src/utils/datetime.ts +++ b/app/src/utils/datetime.ts @@ -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); From bd62fe6c3a7c264e52bcd12b7d706bedf025757e Mon Sep 17 00:00:00 2001 From: Macgregor Aubertin-Young <108430771+mauberti-bc@users.noreply.github.com> Date: Tue, 3 Dec 2024 10:36:39 -0800 Subject: [PATCH 2/3] BugFix: Allow Geojson of Survey Blocks to be Null (#1442) allow block geojson to be null --- api/src/openapi/schemas/survey.ts | 3 ++- api/src/repositories/survey-block-repository.ts | 2 +- app/src/interfaces/useSurveyApi.interface.ts | 2 +- .../src/seeds/03_basic_project_survey_setup.ts | 14 ++++++++++++++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/api/src/openapi/schemas/survey.ts b/api/src/openapi/schemas/survey.ts index 2969919818..51b61d27f2 100644 --- a/api/src/openapi/schemas/survey.ts +++ b/api/src/openapi/schemas/survey.ts @@ -507,7 +507,8 @@ export const surveyBlockSchema: OpenAPIV3.SchemaObject = { }, geojson: { description: 'Geojson', - type: 'object' + type: 'object', + nullable: true }, sample_block_count: { description: 'Sample block count', diff --git a/api/src/repositories/survey-block-repository.ts b/api/src/repositories/survey-block-repository.ts index 0d9f37f3fc..863d3e44c0 100644 --- a/api/src/repositories/survey-block-repository.ts +++ b/api/src/repositories/survey-block-repository.ts @@ -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; diff --git a/app/src/interfaces/useSurveyApi.interface.ts b/app/src/interfaces/useSurveyApi.interface.ts index 5ac2daf906..28c0958d07 100644 --- a/app/src/interfaces/useSurveyApi.interface.ts +++ b/app/src/interfaces/useSurveyApi.interface.ts @@ -140,7 +140,7 @@ export interface IGetSurveyBlock { name: string; description: string; revision_count: number; - geojson: Feature; + geojson: Feature | null; sample_block_count: number; } diff --git a/database/src/seeds/03_basic_project_survey_setup.ts b/database/src/seeds/03_basic_project_survey_setup.ts index 89eef14992..efcf50b1bd 100644 --- a/database/src/seeds/03_basic_project_survey_setup.ts +++ b/database/src/seeds/03_basic_project_survey_setup.ts @@ -92,6 +92,7 @@ export async function seed(knex: Knex): Promise { ${insertMethodTechnique(surveyId)} ${insertSurveySamplingMethodData(surveyId)} ${insertSurveySamplePeriodData(surveyId)} + ${insertSurveyBlockData(surveyId)} `); // Insert regions into surveys @@ -182,6 +183,19 @@ 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)}', + NULL + ) + ; +`; + /** * SQL to insert Survey Proprietor data * From a7bcd49663b1003606f5c86db7bcc64ff6c983f8 Mon Sep 17 00:00:00 2001 From: Mac Deluca <99926243+MacQSL@users.noreply.github.com> Date: Wed, 4 Dec 2024 11:57:07 -0800 Subject: [PATCH 3/3] Bugfix: Survey block Openapi schema (#1443) - Get survey optimization - Update survey block seed data (geojson) --- api/src/openapi/schemas/survey.ts | 4 +-- .../{projectId}/survey/{surveyId}/view.ts | 7 ++-- .../seeds/03_basic_project_survey_setup.ts | 32 ++++++++++++++++++- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/api/src/openapi/schemas/survey.ts b/api/src/openapi/schemas/survey.ts index 51b61d27f2..035cb5212c 100644 --- a/api/src/openapi/schemas/survey.ts +++ b/api/src/openapi/schemas/survey.ts @@ -1,4 +1,5 @@ import { OpenAPIV3 } from 'openapi-types'; +import { GeoJSONFeature } from './geoJson'; import { updateCreateUserPropertiesSchema } from './user'; export const surveyDetailsSchema: OpenAPIV3.SchemaObject = { @@ -506,8 +507,7 @@ export const surveyBlockSchema: OpenAPIV3.SchemaObject = { nullable: true }, geojson: { - description: 'Geojson', - type: 'object', + ...(GeoJSONFeature as object), nullable: true }, sample_block_count: { diff --git a/api/src/paths/project/{projectId}/survey/{surveyId}/view.ts b/api/src/paths/project/{projectId}/survey/{surveyId}/view.ts index ae16257db4..07efd3e67c 100644 --- a/api/src/paths/project/{projectId}/survey/{surveyId}/view.ts +++ b/api/src/paths/project/{projectId}/survey/{surveyId}/view.ts @@ -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(); diff --git a/database/src/seeds/03_basic_project_survey_setup.ts b/database/src/seeds/03_basic_project_survey_setup.ts index efcf50b1bd..29af40b074 100644 --- a/database/src/seeds/03_basic_project_survey_setup.ts +++ b/database/src/seeds/03_basic_project_survey_setup.ts @@ -191,7 +191,37 @@ const insertSurveyBlockData = (surveyId: number) => ` ${surveyId}, '${faker.lorem.words(2)}', '${faker.lorem.words(10)}', - NULL + '{ + "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": {} + }' ) ; `;