Skip to content

Commit

Permalink
Merge pull request #3568 from LiteFarmOrg/custom-tasks-with-animals-e2e
Browse files Browse the repository at this point in the history
format animal ids for custom tasks
  • Loading branch information
kathyavini authored Dec 5, 2024
2 parents 137f8f7 + 27de87d commit 74d9682
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 8 additions & 1 deletion packages/webapp/src/containers/Task/saga.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ import {
} from '../../util/siteMapConstants';
import { setFormData } from '../hooks/useHookFormPersist/hookFormPersistSlice';
import { formatSoilAmendmentProductToDBStructure, getSubtaskName } from '../../util/task';
import { getEndpoint, getMovementTaskBody } from './sagaUtils';
import { formatAnimalIdsForReqBody, getEndpoint, getMovementTaskBody } from './sagaUtils';

const taskTypeEndpoint = [
'cleaning_task',
Expand Down Expand Up @@ -420,6 +420,13 @@ export const getPostTaskBody = (data, endpoint, managementPlanWithCurrentLocatio
.planting_management_plan_id,
}));
delete data['show_wild_crop'];
if (data.animalIds) {
// Format animalIds for the request body
const { related_animal_ids, related_batch_ids } = formatAnimalIdsForReqBody(data.animalIds);
data.related_animal_ids = related_animal_ids;
data.related_batch_ids = related_batch_ids;
delete data['animalIds'];
}
}),
);
};
Expand Down
10 changes: 2 additions & 8 deletions packages/webapp/src/containers/Task/sagaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ export const formatAnimalIdsForReqBody = (ids) => {
return { related_animal_ids: animalIds, related_batch_ids: batchIds };
};

export const formatAnimalTask = (data, endpoint) => {
const { animalIds, managementPlans, ...formattedData } = getPostTaskBody(data, endpoint);

// Remove managementPlans from the data and format animalIds for the request body
return { ...formattedData, ...formatAnimalIdsForReqBody(animalIds) };
};

export const formatMovementTask = (movementTask) => {
if (!movementTask || !('purpose' in movementTask)) {
return { animal_movement_task: {} };
Expand All @@ -64,6 +57,7 @@ export const formatMovementTask = (movementTask) => {
};

export const getMovementTaskBody = (data, endpoint) => {
const { movement_task, ...formattedData } = formatAnimalTask(data, endpoint);
const { movement_task, managementPlans, ...formattedData } = getPostTaskBody(data, endpoint);
// Remove managementPlans from the data
return { ...formattedData, ...formatMovementTask(movement_task) };
};

0 comments on commit 74d9682

Please sign in to comment.