Currently the response that are being sent back to client side looks like this:
[
{
"categoryName": "Orders",
"categorySettings": ...the rest
},
{
"categoryName": "Notifications",
"categorySettings": ...the rest
},
{
"categoryName": "Personalisation",
"categorySettings": ...the rest
}
]
However, the expected layout is:
[
{
"categoryName": "Personalisation",
"categorySettings": ...the rest
},
{
"categoryName": "Notifications",
"categorySettings": ...the rest
},
{
"categoryName": "Orders",
"categorySettings": ...the rest
}
]
How do I sort the categoryName to match the order that I expected? I am thinking about matching the sort order to an array of object with “categoryName” and “sequence” properties, but I am stuck at the code.
My current code is as below:
const groupedData = _.chain(allData)
.groupBy('sectionName')
.map((allData, sectionName) => ({
categoryName: sectionName,
categorySettings: _.chain(allData)
.groupBy('group')
.map((groupSettings, group) => ({
group: group,
groupSettings: _.chain(groupSettings)
.sortBy('ordering')
.groupBy('title')
.map((titleSettings, title) => ({
settingName: title,
settingDescription: titleSettings[0].description,
settingInputs: _.map(titleSettings, ({name, value, inputSetting}) => ({
inputName: name,
inputValue: value,
inputConfig: inputSetting,
})),
}))
.value(),
}))
.value(),
}))
.value();