Add source maps to map plan properties to expected properties (#4933)

This commit is contained in:
Shefali Joshi 2022-03-11 10:40:05 -08:00 committed by GitHub
parent 5471e13d9e
commit bcd668594d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,6 +21,7 @@
*****************************************************************************/
export function getValidatedPlan(domainObject) {
let sourceMap = domainObject.sourceMap;
let body = domainObject.selectFile.body;
let json = {};
if (typeof body === 'string') {
@ -33,5 +34,33 @@ export function getValidatedPlan(domainObject) {
json = body;
}
return json;
if (sourceMap !== undefined && sourceMap.activities !== undefined && sourceMap.groupId !== undefined) {
let mappedJson = {};
json[sourceMap.activities].forEach((activity) => {
if (activity[sourceMap.groupId]) {
const groupIdKey = activity[sourceMap.groupId];
let groupActivity = {
...activity
};
if (sourceMap.start) {
groupActivity.start = activity[sourceMap.start];
}
if (sourceMap.end) {
groupActivity.end = activity[sourceMap.end];
}
if (!mappedJson[groupIdKey]) {
mappedJson[groupIdKey] = [];
}
mappedJson[groupIdKey].push(groupActivity);
}
});
return mappedJson;
} else {
return json;
}
}