From e5a64a67f1a245fbca7a93d2de01b170f52fa196 Mon Sep 17 00:00:00 2001 From: Akshata Katwal Date: Wed, 11 Dec 2024 22:58:58 +0530 Subject: [PATCH] Issue feat: optimize formatted district code and remove formatted state function --- src/services/formatedCohorts.ts | 71 ++++++--------------------------- 1 file changed, 12 insertions(+), 59 deletions(-) diff --git a/src/services/formatedCohorts.ts b/src/services/formatedCohorts.ts index 57e1749..bf7f7a4 100644 --- a/src/services/formatedCohorts.ts +++ b/src/services/formatedCohorts.ts @@ -53,23 +53,23 @@ export const formatedDistricts = async () => { //console.log(blockFieldId) const result = optionReadResponse?.result?.values; console.log(cohortDetails) - console.log(result) - const matchedCohorts = result?.map((value: any) => { + const uniqueResults = result.reduce((acc: any, current: any) => { + const isDuplicate = acc.some((item: any) => item.label === current.label); + if (!isDuplicate) { + acc.push(current); + } + return acc; + }, [] as typeof result); + + console.log(uniqueResults); + const matchedCohorts = uniqueResults?.map((value: any) => { const cohortMatch = cohortDetails.find((cohort: any) => cohort?.name?.toLowerCase() === value?.label?.toLowerCase()); return cohortMatch ? { ...value } : null; }).filter(Boolean); - const uniqueMatchedCohorts = matchedCohorts.reduce((acc: any[], current: any) => { - const isDuplicate = acc.some( - (item) => item.label.toLowerCase() === current.label.toLowerCase() - ); - if (!isDuplicate) { - acc.push(current); - } - return acc; - }, []); + - return uniqueMatchedCohorts; + return matchedCohorts; } catch (error) { console.error("Error in getting District Details", error); @@ -131,51 +131,4 @@ export const formatedBlocks = async (districtCode: string) => { }; -export const formatedStates = async () => { - // const adminState = JSON.parse( - // localStorage.getItem("adminInfo") || "{}" - // ).customFields.find( - // (field: any) => field.label === "STATES" - // ); - try { - const reqParams = { - limit: 0, - offset: 0, - filters: { - // name: searchKeyword, - - type: CohortTypes.STATE, - status: ["active"], - }, - sort: ["name", "asc"], - }; - - const response = await getCohortList(reqParams); - const cohortDetails = response?.results?.cohortDetails || []; - const object = { - fieldName: "states", - }; - const optionReadResponse = await getStateBlockDistrictList(object); - const StateFieldId=optionReadResponse?.result?.fieldId; - localStorage.setItem("stateFieldId", StateFieldId); - const result = optionReadResponse?.result?.values; - - console.log(cohortDetails); - console.log(result); - - const matchedCohorts = result - ?.map((value: any) => { - const cohortMatch = cohortDetails.find( - (cohort: any) => cohort?.name?.toLowerCase() === value?.label?.toLowerCase() - ); - return cohortMatch ? { ...value, cohortId: cohortMatch.cohortId } : null; - }) - .filter(Boolean); - - return matchedCohorts; - } catch (error) { - console.log("Error in getting Channel Details", error); - return error; - } -};