Skip to content

Commit

Permalink
fix: mortality -> mortalities for bulkUpdate
Browse files Browse the repository at this point in the history
  • Loading branch information
MacQSL committed Jun 18, 2024
1 parent d04b466 commit 5e55d78
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -19,6 +20,7 @@ export const CaptureDetails = (props: ICaptureDetailsProps) => {
const { capture } = props;

const captureDate = capture.capture_date;
const captureTime = capture.capture_time;

Check warning on line 23 in app/src/features/surveys/animals/profile/captures/components/capture-card-details/components/CaptureDetails.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/animals/profile/captures/components/capture-card-details/components/CaptureDetails.tsx#L22-L23

Added lines #L22 - L23 were not covered by tests
const captureLocation = capture.capture_location;
const captureComment = capture.capture_comment;

Expand All @@ -35,10 +37,10 @@ export const CaptureDetails = (props: ICaptureDetailsProps) => {
fontWeight={700}
fontSize="0.75rem"
sx={{ textTransform: 'uppercase', mb: 0.5 }}>
Capture time
Capture date
</Typography>
<Typography color="textSecondary" variant="body2">
{getFormattedDate(DATE_FORMAT.MediumDateTimeFormat, captureDate)}
{getFormattedDate(DATE_FORMAT.MediumDateTimeFormat, combineDateTime(captureDate, captureTime))}
</Typography>
</Box>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -19,6 +20,7 @@ export const ReleaseDetails = (props: IReleaseDetailsProps) => {
const { capture } = props;

const releaseDate = capture.release_date;
const releaseTime = capture.release_time;

Check warning on line 23 in app/src/features/surveys/animals/profile/captures/components/capture-card-details/components/ReleaseDetails.tsx

View check run for this annotation

Codecov / codecov/patch

app/src/features/surveys/animals/profile/captures/components/capture-card-details/components/ReleaseDetails.tsx#L22-L23

Added lines #L22 - L23 were not covered by tests
const releaseLocation = capture.release_location;
const releaseComment = capture.release_comment;

Expand All @@ -36,10 +38,10 @@ export const ReleaseDetails = (props: IReleaseDetailsProps) => {
fontWeight={700}
fontSize="0.75rem"
sx={{ textTransform: 'uppercase', mb: 0.5 }}>
Release time
Release date
</Typography>
<Typography color="textSecondary" variant="body2">
{getFormattedDate(DATE_FORMAT.MediumDateTimeFormat, releaseDate)}
{getFormattedDate(DATE_FORMAT.MediumDateTimeFormat, combineDateTime(releaseDate, releaseTime))}
</Typography>
</Box>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 5 additions & 6 deletions app/src/features/surveys/view/survey-animals/animal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { DATE_LIMIT } from 'constants/dateTimeFormats';
import { default as dayjs } from 'dayjs';
import {
ICritterDetailedResponse,
ICritterSimpleResponse,
IQualitativeMeasurementCreate,
IQualitativeMeasurementUpdate,
IQuantitativeMeasurementCreate,
Expand Down Expand Up @@ -237,10 +236,10 @@ export type ICreateCritterFamily = InferType<typeof CreateCritterFamilySchema>;
export type ICreateCritterMortality = InferType<typeof CreateCritterMortalitySchema>;

/**
* 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[];
Expand All @@ -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[];
};
14 changes: 14 additions & 0 deletions app/src/interfaces/useCritterApi.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down
13 changes: 13 additions & 0 deletions app/src/utils/datetime.ts
Original file line number Diff line number Diff line change
@@ -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) => {

Check warning on line 8 in app/src/utils/datetime.ts

View check run for this annotation

Codecov / codecov/patch

app/src/utils/datetime.ts#L8

Added line #L8 was not covered by tests
if (date && time) {
return new Date(`${date}T${time}`).toISOString();

Check warning on line 10 in app/src/utils/datetime.ts

View check run for this annotation

Codecov / codecov/patch

app/src/utils/datetime.ts#L10

Added line #L10 was not covered by tests
}
return new Date(date).toISOString();

Check warning on line 12 in app/src/utils/datetime.ts

View check run for this annotation

Codecov / codecov/patch

app/src/utils/datetime.ts#L12

Added line #L12 was not covered by tests
};

0 comments on commit 5e55d78

Please sign in to comment.