import { convertObjectsToInputFormat, convertStepsToSimple } from "@utils/step-conversion.utils";
/**
* Converts an investigation from the database/model format to a simple DTO format
* suitable for API input or further processing.
* @category Helpers
* @param {IInvestigation} investigation The investigation in the model format.
* @returns {ICreateInvestigationDto} The investigation converted to a simple ICreateInvestigationDto format.
*/
export function convertInvestigationFromModel(investigation) {
return {
title: investigation.title?.value,
curriculum: investigation.curriculum?.value,
unitNumberAndTitle: investigation.unitNumberAndTitle?.value,
grade: investigation.grade?.value,
lessonNumberAndTitle: investigation.lessonNumberAndTitle?.value,
objectives: investigation.objectives?.value,
ngss: investigation.ngss?.value,
analyticalFacts: investigation.analyticalFacts?.value,
goals: investigation.goals?.value,
day: investigation.day?.value,
steps: convertStepsToSimple(investigation.steps || []),
objects: convertObjectsToInputFormat(investigation.objects || []),
};
}
/**
* Removes the current investigation objects' coordinates
* @category Helpers
* @param {IInvestigation} investigation The investigation in the model format.
* @returns {IInvestigationWithoutObjectsCoordinatesDto} The investigation converted to a simple ICreateInvestigationDto format.
*/
export function removeInvestigationObjectCoordinates(investigation) {
return {
title: investigation.title?.value,
curriculum: investigation.curriculum?.value,
unitNumberAndTitle: investigation.unitNumberAndTitle?.value,
grade: investigation.grade?.value,
lessonNumberAndTitle: investigation.lessonNumberAndTitle?.value,
objectives: investigation.objectives?.value,
ngss: investigation.ngss?.value,
analyticalFacts: investigation.analyticalFacts?.value,
goals: investigation.goals?.value,
day: investigation.day?.value,
steps: convertStepsToSimple(investigation.steps || []),
objects: convertObjectsToInputFormat(investigation.objects || [], false),
};
}
Source