Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…lfinance into feature/optimization
  • Loading branch information
Vaibhav sasulkar committed Oct 10, 2024
2 parents 72ede2c + 2dd4204 commit d0e1219
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
17 changes: 10 additions & 7 deletions blocks/homeloancalculator/homeloancalculator.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { renderCalculatorData } from '../emiandeligiblitycalc/renderhpcal.js';
import { homeLoanCalcFunc } from '../emiandeligiblitycalc/homeloancalculators.js';
import { CalcHTM } from '../emiandeligiblitycalc/templatehtml1.js';
import { firstTabActive } from '../emiandeligiblitycalc/commonfile.js';
import { fetchAPI, targetObject } from '../../scripts/scripts.js';
import { renderCalculatorData } from "../emiandeligiblitycalc/renderhpcal.js";
import { homeLoanCalcFunc } from "../emiandeligiblitycalc/homeloancalculators.js";
import { CalcHTM } from "../emiandeligiblitycalc/templatehtml1.js";
import { firstTabActive } from "../emiandeligiblitycalc/commonfile.js";
import { calculatorFlatStrLogic, fetchAPI, targetObject } from "../../scripts/scripts.js";

let calculatorType; let emiCalDiv; let emiOverlay; let
overlay;
Expand All @@ -11,8 +11,11 @@ export default async function decorate(block) {
const cfURL = block.textContent.trim();

const cfRepsonse = await CFApiCall(cfURL);
const repsonseData = cfRepsonse.data[0].data;
const jsonResponseData = JSON.parse(repsonseData);
/* const repsonseData = cfRepsonse.data[0].data;
const jsonResponseData = JSON.parse(repsonseData) */

const repsonseData = cfRepsonse.data;
const jsonResponseData = calculatorFlatStrLogic(repsonseData);

/* const callJson = {
total: 1,
Expand Down
36 changes: 36 additions & 0 deletions scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -935,5 +935,41 @@ export function selectBranchDetails(block) {
} catch (error) {
console.warn(error);
}
})
}

export function calculatorFlatStrLogic(data) {
var mainObj = {};

data.forEach(function (eachData) {
const { Fieldset, Name, Type, Value, ID } = eachData;

if (Fieldset) {
if (!mainObj[Fieldset]) {
mainObj[Fieldset] = {};
}

if (Type === "loanamout") {
if (!mainObj[Fieldset].loanamout) {
mainObj[Fieldset].loanamout = [];
}

let loanItem = mainObj[Fieldset].loanamout[ID];
if (!loanItem) {
loanItem = {};
mainObj[Fieldset].loanamout[ID] = loanItem;
}

loanItem[Name] = Value;
} else if (Type === "array") {
mainObj[Fieldset][Name] = [];
} else {
mainObj[Fieldset][Name] = Value;
}
} else {
mainObj[Name] = Value;
}
});

return mainObj;
}

0 comments on commit d0e1219

Please sign in to comment.