Closed aleksa-krolls closed 1 year ago
From Slack thread: https://openfn.slack.com/archives/C017ELVRSM8/p1666007345359699?thread_ts=1665420539.586769&cid=C017ELVRSM8
Job assuming an input like this {organization: { casedata, services: [ {s1}, {s2}]}}
fn(state => {
const { cases } = state;
const transformedCases = [];
cases.map(wrapper => {
wrapper.organization.services_section.map(s => {
transformedCases.push({
...wrapper,
organization: { ...wrapper.organization, services_section: [s] },
});
});
});
return { ...state, cases: transformedCases };
});
this returns this output:
{
"references": [],
"data": null,
"cases": [
{
"organization": {
"case_id": 1,
"services_section": [
{
"s": 1,
"name": "some person"
}
]
}
},
{
"organization": {
"case_id": 1,
"services_section": [
{
"s": 2,
"name": "someone else"
}
]
}
}
]
}
Request
Assuming an input state like this, where there is an array of cases... where 1 case has 2 services.
Can you please write a
fn(...)
block that takes this input and returns an output like this ... so that 1 case is never sent with 2 services, but rather a separate request will be sent for each service. (Meaning that the services should be split across 2 different instances, but the case data will be the same across both instances.)Input: https://github.com/OpenFn/unicef-cambodia/blob/master/sample_data/primero_2referrals_input.json Desired output: https://github.com/OpenFn/unicef-cambodia/blob/master/sample_data/primero_2referrals_output.json