2021-03-08 18:12:59 +05:30
|
|
|
const unwrapGroups = (stages) => {
|
|
|
|
return stages.map((stage) => {
|
2021-02-22 17:27:13 +05:30
|
|
|
const {
|
|
|
|
groups: { nodes: groups },
|
|
|
|
} = stage;
|
|
|
|
return { ...stage, groups };
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const unwrapNodesWithName = (jobArray, prop, field = 'name') => {
|
2021-03-08 18:12:59 +05:30
|
|
|
return jobArray.map((job) => {
|
|
|
|
return { ...job, [prop]: job[prop].nodes.map((item) => item[field]) };
|
2021-02-22 17:27:13 +05:30
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const unwrapJobWithNeeds = (denodedJobArray) => {
|
2021-02-22 17:27:13 +05:30
|
|
|
return unwrapNodesWithName(denodedJobArray, 'needs');
|
|
|
|
};
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const unwrapStagesWithNeeds = (denodedStages) => {
|
2021-02-22 17:27:13 +05:30
|
|
|
const unwrappedNestedGroups = unwrapGroups(denodedStages);
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const nodes = unwrappedNestedGroups.map((node) => {
|
2021-02-22 17:27:13 +05:30
|
|
|
const { groups } = node;
|
2021-03-08 18:12:59 +05:30
|
|
|
const groupsWithJobs = groups.map((group) => {
|
2021-02-22 17:27:13 +05:30
|
|
|
const jobs = unwrapJobWithNeeds(group.jobs.nodes);
|
|
|
|
return { ...group, jobs };
|
|
|
|
});
|
|
|
|
|
|
|
|
return { ...node, groups: groupsWithJobs };
|
|
|
|
});
|
|
|
|
|
|
|
|
return nodes;
|
|
|
|
};
|
|
|
|
|
|
|
|
export { unwrapGroups, unwrapNodesWithName, unwrapJobWithNeeds, unwrapStagesWithNeeds };
|