From 5e55d7838317081e245fcd2a411479c1e98eab02 Mon Sep 17 00:00:00 2001 From: Mac Deluca Date: Mon, 17 Jun 2024 17:00:32 -0700 Subject: [PATCH] fix: mortality -> mortalities for bulkUpdate --- .../components/CaptureDetails.tsx | 6 ++-- .../components/ReleaseDetails.tsx | 6 ++-- .../mortality-form/edit/EditMortalityPage.tsx | 28 ++++++++++--------- .../surveys/view/survey-animals/animal.ts | 11 ++++---- app/src/interfaces/useCritterApi.interface.ts | 14 ++++++++++ app/src/utils/datetime.ts | 13 +++++++++ 6 files changed, 55 insertions(+), 23 deletions(-) create mode 100644 app/src/utils/datetime.ts diff --git a/app/src/features/surveys/animals/profile/captures/components/capture-card-details/components/CaptureDetails.tsx b/app/src/features/surveys/animals/profile/captures/components/capture-card-details/components/CaptureDetails.tsx index 321957f25a..f27ce6db96 100644 --- a/app/src/features/surveys/animals/profile/captures/components/capture-card-details/components/CaptureDetails.tsx +++ b/app/src/features/surveys/animals/profile/captures/components/capture-card-details/components/CaptureDetails.tsx @@ -3,6 +3,7 @@ import Stack from '@mui/material/Stack'; import Typography from '@mui/material/Typography'; import { DATE_FORMAT } from 'constants/dateTimeFormats'; import { ICaptureWithSupplementaryData } from 'features/surveys/animals/profile/captures/AnimalCaptureContainer'; +import { combineDateTime } from 'utils/datetime'; import { getFormattedDate } from 'utils/Utils'; interface ICaptureDetailsProps { @@ -19,6 +20,7 @@ export const CaptureDetails = (props: ICaptureDetailsProps) => { const { capture } = props; const captureDate = capture.capture_date; + const captureTime = capture.capture_time; const captureLocation = capture.capture_location; const captureComment = capture.capture_comment; @@ -35,10 +37,10 @@ export const CaptureDetails = (props: ICaptureDetailsProps) => { fontWeight={700} fontSize="0.75rem" sx={{ textTransform: 'uppercase', mb: 0.5 }}> - Capture time + Capture date - {getFormattedDate(DATE_FORMAT.MediumDateTimeFormat, captureDate)} + {getFormattedDate(DATE_FORMAT.MediumDateTimeFormat, combineDateTime(captureDate, captureTime))} diff --git a/app/src/features/surveys/animals/profile/captures/components/capture-card-details/components/ReleaseDetails.tsx b/app/src/features/surveys/animals/profile/captures/components/capture-card-details/components/ReleaseDetails.tsx index 81af0c3677..989d5ce5ba 100644 --- a/app/src/features/surveys/animals/profile/captures/components/capture-card-details/components/ReleaseDetails.tsx +++ b/app/src/features/surveys/animals/profile/captures/components/capture-card-details/components/ReleaseDetails.tsx @@ -3,6 +3,7 @@ import Stack from '@mui/material/Stack'; import Typography from '@mui/material/Typography'; import { DATE_FORMAT } from 'constants/dateTimeFormats'; import { ICaptureWithSupplementaryData } from 'features/surveys/animals/profile/captures/AnimalCaptureContainer'; +import { combineDateTime } from 'utils/datetime'; import { getFormattedDate } from 'utils/Utils'; interface IReleaseDetailsProps { @@ -19,6 +20,7 @@ export const ReleaseDetails = (props: IReleaseDetailsProps) => { const { capture } = props; const releaseDate = capture.release_date; + const releaseTime = capture.release_time; const releaseLocation = capture.release_location; const releaseComment = capture.release_comment; @@ -36,10 +38,10 @@ export const ReleaseDetails = (props: IReleaseDetailsProps) => { fontWeight={700} fontSize="0.75rem" sx={{ textTransform: 'uppercase', mb: 0.5 }}> - Release time + Release date - {getFormattedDate(DATE_FORMAT.MediumDateTimeFormat, releaseDate)} + {getFormattedDate(DATE_FORMAT.MediumDateTimeFormat, combineDateTime(releaseDate, releaseTime))} )} diff --git a/app/src/features/surveys/animals/profile/mortality/mortality-form/edit/EditMortalityPage.tsx b/app/src/features/surveys/animals/profile/mortality/mortality-form/edit/EditMortalityPage.tsx index 201f894129..bc4b6e567d 100644 --- a/app/src/features/surveys/animals/profile/mortality/mortality-form/edit/EditMortalityPage.tsx +++ b/app/src/features/surveys/animals/profile/mortality/mortality-form/edit/EditMortalityPage.tsx @@ -135,19 +135,21 @@ export const EditMortalityPage = () => { // Update existing critter information const response = await critterbaseApi.critters.bulkUpdate({ - mortality: { - critter_id: critterbaseCritterId, - mortality_id: values.mortality.mortality_id, - location: mortalityLocation, - mortality_timestamp: mortalityTimestamp, - mortality_comment: values.mortality.mortality_comment, - proximate_cause_of_death_id: values.mortality.proximate_cause_of_death_id, - proximate_cause_of_death_confidence: values.mortality.proximate_cause_of_death_confidence, - proximate_predated_by_itis_tsn: values.mortality.proximate_predated_by_itis_tsn, - ultimate_cause_of_death_id: values.mortality.ultimate_cause_of_death_id, - ultimate_cause_of_death_confidence: values.mortality.ultimate_cause_of_death_confidence, - ultimate_predated_by_itis_tsn: values.mortality.ultimate_predated_by_itis_tsn - }, + mortalities: [ + { + critter_id: critterbaseCritterId, + mortality_id: values.mortality.mortality_id, + location: mortalityLocation, + mortality_timestamp: mortalityTimestamp, + mortality_comment: values.mortality.mortality_comment, + proximate_cause_of_death_id: values.mortality.proximate_cause_of_death_id, + proximate_cause_of_death_confidence: values.mortality.proximate_cause_of_death_confidence, + proximate_predated_by_itis_tsn: values.mortality.proximate_predated_by_itis_tsn, + ultimate_cause_of_death_id: values.mortality.ultimate_cause_of_death_id, + ultimate_cause_of_death_confidence: values.mortality.ultimate_cause_of_death_confidence, + ultimate_predated_by_itis_tsn: values.mortality.ultimate_predated_by_itis_tsn + } + ], markings: [...markingsForUpdate, ...markingsForDelete], qualitative_measurements: [...qualitativeMeasurementsForUpdate, ...qualitativeMeasurementsForDelete], quantitative_measurements: [...quantitativeMeasurementsForUpdate, ...quantitativeMeasurementsForDelete] diff --git a/app/src/features/surveys/view/survey-animals/animal.ts b/app/src/features/surveys/view/survey-animals/animal.ts index 5cbfbc9a90..4f7ca9645a 100644 --- a/app/src/features/surveys/view/survey-animals/animal.ts +++ b/app/src/features/surveys/view/survey-animals/animal.ts @@ -2,7 +2,6 @@ import { DATE_LIMIT } from 'constants/dateTimeFormats'; import { default as dayjs } from 'dayjs'; import { ICritterDetailedResponse, - ICritterSimpleResponse, IQualitativeMeasurementCreate, IQualitativeMeasurementUpdate, IQuantitativeMeasurementCreate, @@ -237,10 +236,10 @@ export type ICreateCritterFamily = InferType; export type ICreateCritterMortality = InferType; /** - * Adding data to a critter in bulk + * Adding data to a critters in bulk */ export type IBulkCreate = { - critter?: ICritterSimpleResponse; + critters?: ICreateCritter[]; qualitative_measurements?: IQualitativeMeasurementCreate[]; quantitative_measurements?: IQuantitativeMeasurementCreate[]; captures?: ICreateCritterCapture[]; @@ -250,14 +249,14 @@ export type IBulkCreate = { }; /** - * Editing data for a critter in bulk + * Editing data for a critters in bulk */ export type IBulkUpdate = { - critter?: ICritterSimpleResponse; + critters?: ICreateCritter[]; qualitative_measurements?: IQualitativeMeasurementUpdate[]; quantitative_measurements?: IQuantitativeMeasurementUpdate[]; captures?: ICreateCritterCapture[]; - mortality?: ICreateCritterMortality; + mortalities?: ICreateCritterMortality[]; markings?: ICreateCritterMarking[]; collections?: ICreateCritterCollectionUnit[]; }; diff --git a/app/src/interfaces/useCritterApi.interface.ts b/app/src/interfaces/useCritterApi.interface.ts index b62ba7a067..5e704aac64 100644 --- a/app/src/interfaces/useCritterApi.interface.ts +++ b/app/src/interfaces/useCritterApi.interface.ts @@ -2,6 +2,16 @@ import { ICreateCritterCollectionUnit } from 'features/surveys/view/survey-anima import { Feature } from 'geojson'; import { ITaxonomy } from './useTaxonomyApi.interface'; +export interface ICritterCreate { + critter_id?: string; + wlh_id?: string | null; + animal_id?: string | null; + sex: string; + itis_tsn: number; + responsible_region_nr_id?: string | null; + critter_comment?: string | null; +} + export interface ICreateEditAnimalRequest { critter_id?: string; nickname: string; @@ -191,6 +201,10 @@ export type IQuantitativeMeasurementCreate = { measured_timestamp?: string | null; }; +export type ICritterUpdate = ICritterCreate & { + critter_id: string; +}; + export type IQualitativeMeasurementUpdate = IQualitativeMeasurementCreate & { measurement_qualitative_id: string; }; diff --git a/app/src/utils/datetime.ts b/app/src/utils/datetime.ts new file mode 100644 index 0000000000..1c05ef7e0d --- /dev/null +++ b/app/src/utils/datetime.ts @@ -0,0 +1,13 @@ +/** + * Combine date and time and return ISO string. + * + * @param {string} date - String date ie: '2024-01-01' + * @param {string | null} [time] - Optional time ie: '00:10:10' + * @returns {string} ISO date string + */ +export const combineDateTime = (date: string, time?: string | null) => { + if (date && time) { + return new Date(`${date}T${time}`).toISOString(); + } + return new Date(date).toISOString(); +};