MinervaFrontend/src/hooks/sundry/parseListBlock.js
kuwsh1n e4dba30177
All checks were successful
publish-main / release-image (push) Successful in 6m56s
fix ticket 6, 10, 15
2024-05-08 22:08:25 +03:00

57 lines
1.4 KiB
JavaScript

// function sortListBlock(data) {
// return data.sort((itemOne, itemTwo) => itemOne.order - itemTwo.order)
// };
function responseDataToListBlock(data) {
const result = []
for (let block of data) {
const newParam = {
id: block.id,
formId: block.form_id,
order: block.order
}
for (let param of block.data) {
if (Array.isArray(param.Value) && param.Value.length) {
newParam[param.Key] = param.Value.map(item => ({
id: item.find(obj => obj.Key === "id").Value,
text: item.find(obj => obj.Key === "text").Value
}))
}
else {
newParam[param.Key] = param.Value
}
}
result.push(newParam)
}
return result.sort((itemOne, itemTwo) => itemOne.order - itemTwo.order)
};
function dateTimeParse(date) {
let newDate = "";
for (let symbol of date) {
if (symbol === "T") {
newDate += " ";
}
else if (symbol === ".") {
break;
}
else {
newDate += symbol;
}
}
return newDate
};
function numberingBlocks(list, key, increase = 0) {
list.forEach((value, i) => list[i][key] = i + increase)
return list
}
export { responseDataToListBlock, dateTimeParse, numberingBlocks }