From c2fd75fd2ea4cdc8a1b0fc3cd37325c43ee7524d Mon Sep 17 00:00:00 2001 From: Arif-tekdi-technologies Date: Tue, 3 Dec 2024 15:33:03 +0530 Subject: [PATCH] Issue #0000 feat: Course planner targettedSolution fixes --- src/pages/importCsv.tsx | 10 +- src/services/coursePlanner.ts | 267 +++++++++++++++++----------------- src/utils/Interfaces.ts | 2 +- 3 files changed, 143 insertions(+), 136 deletions(-) diff --git a/src/pages/importCsv.tsx b/src/pages/importCsv.tsx index 415081aa..bf0a2da4 100644 --- a/src/pages/importCsv.tsx +++ b/src/pages/importCsv.tsx @@ -75,9 +75,9 @@ const ImportCsv = () => { const response = await getTargetedSolutions({ subject: tstore?.taxonomySubject, class: tstore?.taxonomyGrade, - state: tstore?.state, + state: localStorage.getItem("selectedState") || tstore?.state, board: tstore?.board, - type: tstore?.taxonomyType, + courseType: tstore?.taxonomyType, medium: tstore?.taxonomyMedium, }); @@ -115,9 +115,9 @@ const ImportCsv = () => { const updatedResponse = await getTargetedSolutions({ subject: tstore?.taxonomySubject, class: tstore?.taxonomyGrade, - state: tstore?.state, + state: localStorage.getItem("selectedState") || tstore?.state, board: tstore?.board, - type: tstore?.taxonomyType, + courseType: tstore?.taxonomyType, medium: tstore?.taxonomyMedium, }); setLoading(false); @@ -185,7 +185,7 @@ const ImportCsv = () => { const metaData: CoursePlannerMetaData = { subject: tstore?.taxonomySubject, class: tstore?.taxonomyGrade, - state: tstore?.state, + state: localStorage.getItem("selectedState") || tstore?.state, board: tstore?.board, type: tstore?.taxonomyType, medium: tstore?.taxonomyMedium, diff --git a/src/services/coursePlanner.ts b/src/services/coursePlanner.ts index 8087a453..45402da7 100644 --- a/src/services/coursePlanner.ts +++ b/src/services/coursePlanner.ts @@ -1,11 +1,14 @@ -import { CoursePlannerMetaData, GetSolutionDetailsParams, GetTargetedSolutionsParams, GetUserProjectTemplateParams } from "@/utils/Interfaces"; +import { + CoursePlannerMetaData, + GetSolutionDetailsParams, + GetTargetedSolutionsParams, + GetUserProjectTemplateParams, +} from "@/utils/Interfaces"; import { get, post } from "./RestClient"; -import axios from 'axios'; +import axios from "axios"; import { FRAMEWORK_ID } from "../../app.config"; import { URL_CONFIG } from "@/utils/url.config"; - - export const getChannelDetails = async (): Promise => { const apiUrl: string = `/api/framework/v1/read/${FRAMEWORK_ID}`; @@ -13,159 +16,163 @@ export const getChannelDetails = async (): Promise => { const response = await axios.get(apiUrl); return response?.data; } catch (error) { - console.error('Error in getting Channel Details', error); + console.error("Error in getting Channel Details", error); return error; } }; -export const getFrameworkDetails = async (frameworkId: string): Promise => { +export const getFrameworkDetails = async ( + frameworkId: string +): Promise => { const apiUrl: string = `/api/framework/v1/read/${frameworkId}?categories=gradeLevel,medium,class,subject`; try { const response = await axios.get(apiUrl); return response?.data; } catch (error) { - console.error('Error in getting Framework Details', error); + console.error("Error in getting Framework Details", error); return error; } }; -export const uploadCoursePlanner = async (file: File, metaData: CoursePlannerMetaData): Promise => { - const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/prathamservice/v1/course-planner/upload`; - const formData = new FormData(); - formData.append('file', file); - formData.append('metaData', JSON.stringify(metaData)); - try { - const response = await post(apiUrl, formData, { - }); - return response?.data; - } catch (error) { - console.error('Error uploading course planner', error); - throw error; - } - }; +export const uploadCoursePlanner = async ( + file: File, + metaData: CoursePlannerMetaData +): Promise => { + const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/prathamservice/v1/course-planner/upload`; + const formData = new FormData(); + formData.append("file", file); + formData.append("metaData", JSON.stringify(metaData)); + try { + const response = await post(apiUrl, formData, {}); + return response?.data; + } catch (error) { + console.error("Error uploading course planner", error); + throw error; + } +}; + +export const getTargetedSolutions = async ({ + subject, + state, + medium, + class: className, + board, + courseType, +}: GetTargetedSolutionsParams): Promise => { + const apiUrl: string = `${process.env.NEXT_PUBLIC_COURSE_PLANNER_API_URL}/solutions/targetedSolutions?type=improvementProject¤tScopeOnly=true`; + const headers = { + "X-auth-token": localStorage.getItem("token"), + "Content-Type": "application/json", + }; - export const getTargetedSolutions = async ({ + const data = { subject, state, medium, class: className, board, - type, - }: GetTargetedSolutionsParams): Promise => { - const apiUrl: string = `${process.env.NEXT_PUBLIC_COURSE_PLANNER_API_URL}/solutions/targetedSolutions?type=improvementProject¤tScopeOnly=true`; - - const headers = { - 'X-auth-token': localStorage.getItem('token'), - 'Content-Type': 'application/json', - }; - - const data = { - subject, - state, - - medium, - class: className, - board, - type, - }; - - try { - const response = await axios.post(apiUrl, data, { headers }); - return response?.data; - } catch (error) { - console.error('Error in getting Targeted Solutions', error); - return error; - } + courseType, }; - interface GetUserProjectDetailsParams { - id: string; + + try { + const response = await axios.post(apiUrl, data, { headers }); + return response?.data; + } catch (error) { + console.error("Error in getting Targeted Solutions", error); + return error; } - - export const getUserProjectDetails = async ({ id }: GetUserProjectDetailsParams): Promise => { - const apiUrl: string = `${process.env.NEXT_PUBLIC_COURSE_PLANNER_API_URL}/userProjects/details/${id}`; - - const headers = { - 'Authorization': localStorage.getItem('token'), - 'Content-Type': 'application/json', - 'x-auth-token': localStorage.getItem('token'), - - }; - - try { - const response = await axios.post(apiUrl, {}, { headers }); - return response?.data; - } catch (error) { - console.error('Error in getting User Project Details', error); - return error; - } +}; +interface GetUserProjectDetailsParams { + id: string; +} + +export const getUserProjectDetails = async ({ + id, +}: GetUserProjectDetailsParams): Promise => { + const apiUrl: string = `${process.env.NEXT_PUBLIC_COURSE_PLANNER_API_URL}/userProjects/details/${id}`; + + const headers = { + Authorization: localStorage.getItem("token"), + "Content-Type": "application/json", + "x-auth-token": localStorage.getItem("token"), }; - - - export const getSolutionDetails = async ({ id, role }: GetSolutionDetailsParams): Promise => { - const apiUrl: string = `${process.env.NEXT_PUBLIC_COURSE_PLANNER_API_URL}/solutions/details/${id}`; - - const headers = { - 'X-auth-token': localStorage.getItem('token'), - 'Content-Type': 'application/json', - }; - - const data = { - role, - }; - - try { - const response = await axios.post(apiUrl, data, { headers }); - return response?.data; - } catch (error) { - console.error('Error in getting Solution Details', error); - return error; - } + + try { + const response = await axios.post(apiUrl, {}, { headers }); + return response?.data; + } catch (error) { + console.error("Error in getting User Project Details", error); + return error; + } +}; + +export const getSolutionDetails = async ({ + id, + role, +}: GetSolutionDetailsParams): Promise => { + const apiUrl: string = `${process.env.NEXT_PUBLIC_COURSE_PLANNER_API_URL}/solutions/details/${id}`; + + const headers = { + "X-auth-token": localStorage.getItem("token"), + "Content-Type": "application/json", }; - - export const getUserProjectTemplate = async ({ - templateId, - solutionId, + + const data = { role, - }: GetUserProjectTemplateParams): Promise => { - const apiUrl: string = `${process.env.NEXT_PUBLIC_COURSE_PLANNER_API_URL}/userProjects/details?templateId=${templateId}&solutionId=${solutionId}`; - - const headers = { - 'X-auth-token': localStorage.getItem('token'), - 'Content-Type': 'application/json', - }; - - const data = { - role, - }; - - try { - const response = await axios.post(apiUrl, data, { headers }); - return response?.data; - } catch (error) { - console.error('Error in getting User Project Details', error); - throw error; - } }; - - export const getContentHierarchy = async ({ - doId, - }: { - doId: string; - }): Promise => { - const apiUrl: string = `${URL_CONFIG.API.CONTENT_HIERARCHY}/${doId}`; - - try { - console.log('Request data', apiUrl); - const response = await get(apiUrl); - // console.log('response', response); - return response; - } catch (error) { - console.error('Error in getContentHierarchy Service', error); - throw error; - } + + try { + const response = await axios.post(apiUrl, data, { headers }); + return response?.data; + } catch (error) { + console.error("Error in getting Solution Details", error); + return error; + } +}; + +export const getUserProjectTemplate = async ({ + templateId, + solutionId, + role, +}: GetUserProjectTemplateParams): Promise => { + const apiUrl: string = `${process.env.NEXT_PUBLIC_COURSE_PLANNER_API_URL}/userProjects/details?templateId=${templateId}&solutionId=${solutionId}`; + + const headers = { + "X-auth-token": localStorage.getItem("token"), + "Content-Type": "application/json", + }; + + const data = { + role, }; - \ No newline at end of file + + try { + const response = await axios.post(apiUrl, data, { headers }); + return response?.data; + } catch (error) { + console.error("Error in getting User Project Details", error); + throw error; + } +}; + +export const getContentHierarchy = async ({ + doId, +}: { + doId: string; +}): Promise => { + const apiUrl: string = `${URL_CONFIG.API.CONTENT_HIERARCHY}/${doId}`; + + try { + console.log("Request data", apiUrl); + const response = await get(apiUrl); + // console.log('response', response); + return response; + } catch (error) { + console.error("Error in getContentHierarchy Service", error); + throw error; + } +}; diff --git a/src/utils/Interfaces.ts b/src/utils/Interfaces.ts index 7a0b3f04..d8dea478 100644 --- a/src/utils/Interfaces.ts +++ b/src/utils/Interfaces.ts @@ -97,7 +97,7 @@ export interface GetTargetedSolutionsParams { medium: string; class: string; board: string; - type: string; + courseType: string; } export interface GetSolutionDetailsParams {