Spaces:
Sleeping
Sleeping
| import axios from 'axios'; | |
| import { API_BASE_URL } from '../config'; | |
| import { | |
| AppraisalCycle, | |
| AppraisalCycleCreateRequest, | |
| AppraisalCycleUpdateRequest, | |
| Appraisal, | |
| AppraisalCreateRequest, | |
| AppraisalUpdateRequest, | |
| AssessmentArea, | |
| AssessmentAreaCreateRequest, | |
| AssessmentAreaUpdateRequest, | |
| RoleAssessmentQuestion, | |
| RoleAssessmentQuestionCreateRequest, | |
| RoleAssessmentQuestionUpdateRequest, | |
| AssessmentAnswer, | |
| AssessmentAnswerCreateRequest, | |
| AssessmentAnswerUpdateRequest, | |
| Competency, | |
| CompetencyCreateRequest, | |
| CompetencyUpdateRequest, | |
| CompetencyIndicator, | |
| CompetencyIndicatorCreateRequest, | |
| CompetencyIndicatorUpdateRequest, | |
| CompetencyRating, | |
| CompetencyRatingCreateRequest, | |
| CompetencyRatingUpdateRequest, | |
| TrainingNeed, | |
| TrainingNeedCreateRequest, | |
| TrainingNeedUpdateRequest, | |
| HrRemark, | |
| HrRemarkCreateRequest, | |
| HrRemarkUpdateRequest, | |
| ResponseData, | |
| ManagementRemark, | |
| ManagementRemarkCreateRequest, | |
| ManagementRemarkUpdateRequest, | |
| } from '../types'; | |
| // This should match other API calls in the codebase | |
| const BASE_URL = `${API_BASE_URL}/api`; | |
| // Appraisal Cycles | |
| export const getAppraisalCycles = async (): Promise<ResponseData<AppraisalCycle[]>> => { | |
| try { | |
| const apiUrl = `${BASE_URL}/AppraisalCycle`; | |
| console.log("Calling API: GET", apiUrl); | |
| const response = await axios.get<any>(apiUrl); | |
| console.log("Raw API response:", response); | |
| // Check if response has data property | |
| if (!response.data) { | |
| console.error("API response is missing data"); | |
| return { | |
| data: [], | |
| success: false, | |
| message: "API response is missing data" | |
| }; | |
| } | |
| // Check if response.data already has the expected structure | |
| if (typeof response.data.success !== 'undefined') { | |
| console.log("Response already in expected format:", response.data); | |
| return response.data as ResponseData<AppraisalCycle[]>; | |
| } | |
| // If response.data is an array, assume it's the cycles data | |
| if (Array.isArray(response.data)) { | |
| console.log("Response is an array, wrapping in success structure"); | |
| return { | |
| data: response.data as AppraisalCycle[], | |
| success: true | |
| }; | |
| } | |
| // If we reach here, we have data but it's in an unexpected format | |
| console.warn("API returned data in an unexpected format:", response.data); | |
| return { | |
| data: [], | |
| success: false, | |
| message: "API returned data in an unexpected format" | |
| }; | |
| } catch (error) { | |
| console.error("Error in getAppraisalCycles:", error); | |
| return { | |
| data: [], | |
| success: false, | |
| message: error instanceof Error ? error.message : "Unknown error occurred" | |
| }; | |
| } | |
| }; | |
| export const getAppraisalCycleById = async (cycleId: number): Promise<ResponseData<AppraisalCycle>> => { | |
| try { | |
| const apiUrl = `${BASE_URL}/AppraisalCycle/${cycleId}`; | |
| console.log("Calling API: GET", apiUrl); | |
| const response = await axios.get<any>(apiUrl); | |
| // Similar error handling as in getAppraisalCycles | |
| if (!response.data) { | |
| return { | |
| data: {} as AppraisalCycle, | |
| success: false, | |
| message: "API response is missing data" | |
| }; | |
| } | |
| // Check if response.data already has the expected structure | |
| if (typeof response.data.success !== 'undefined') { | |
| return response.data as ResponseData<AppraisalCycle>; | |
| } | |
| // Assume response.data is the cycle object | |
| return { | |
| data: response.data as AppraisalCycle, | |
| success: true | |
| }; | |
| } catch (error) { | |
| console.error("Error in getAppraisalCycleById:", error); | |
| return { | |
| data: {} as AppraisalCycle, | |
| success: false, | |
| message: error instanceof Error ? error.message : "Unknown error occurred" | |
| }; | |
| } | |
| }; | |
| export const createAppraisalCycle = async (cycle: AppraisalCycleCreateRequest): Promise<ResponseData<AppraisalCycle>> => { | |
| const response = await axios.post(`${API_BASE_URL}/api/AppraisalCycle`, cycle); | |
| return response.data; | |
| }; | |
| export const updateAppraisalCycle = async (cycle: AppraisalCycleUpdateRequest): Promise<ResponseData<AppraisalCycle>> => { | |
| const response = await axios.put(`${API_BASE_URL}/api/AppraisalCycle/${cycle.cycleId}`, cycle); | |
| return response.data; | |
| }; | |
| export const deleteAppraisalCycle = async (cycleId: number): Promise<ResponseData<boolean>> => { | |
| const response = await axios.delete(`${API_BASE_URL}/api/AppraisalCycle/${cycleId}`); | |
| return { | |
| data: response.status === 200, | |
| success: response.status === 200 | |
| }; | |
| }; | |
| // Appraisals | |
| export const getAppraisals = async (): Promise<ResponseData<Appraisal[]>> => { | |
| const response = await axios.get(`${API_BASE_URL}/api/Appraisal`); | |
| return response.data; | |
| }; | |
| export const getAppraisalById = async (appraisalId: number): Promise<ResponseData<Appraisal>> => { | |
| const response = await axios.get(`${API_BASE_URL}/api/Appraisal/${appraisalId}`); | |
| return response.data; | |
| }; | |
| export const getAppraisalsByEmployeeId = async (employeeId: number): Promise<ResponseData<Appraisal[]>> => { | |
| try { | |
| const apiUrl = `${BASE_URL}/Appraisal/employee/${employeeId}`; | |
| console.log("Calling API: GET", apiUrl); | |
| const response = await axios.get<any>(apiUrl); | |
| console.log("My Appraisals API response:", response); | |
| // Check if response has data property | |
| if (!response.data) { | |
| console.error("API response is missing data"); | |
| return { | |
| data: [], | |
| success: false, | |
| message: "API response is missing data" | |
| }; | |
| } | |
| // Check if response.data already has the expected structure | |
| if (typeof response.data.success !== 'undefined') { | |
| console.log("Response already in expected format:", response.data); | |
| return response.data as ResponseData<Appraisal[]>; | |
| } | |
| // If response.data is an array, assume it's the appraisals data | |
| if (Array.isArray(response.data)) { | |
| console.log("Response is an array, wrapping in success structure"); | |
| return { | |
| data: response.data as Appraisal[], | |
| success: true | |
| }; | |
| } | |
| // If we reach here, we have data but it's in an unexpected format | |
| console.warn("API returned data in an unexpected format:", response.data); | |
| return { | |
| data: [], | |
| success: false, | |
| message: "API returned data in an unexpected format" | |
| }; | |
| } catch (error) { | |
| console.error("Error in getAppraisalsByEmployeeId:", error); | |
| return { | |
| data: [], | |
| success: false, | |
| message: error instanceof Error ? error.message : "Unknown error occurred" | |
| }; | |
| } | |
| }; | |
| export const getAppraisalsByAppraiserId = async (appraiserId: number): Promise<ResponseData<Appraisal[]>> => { | |
| const appraisals = await getAppraisals(); | |
| const filteredAppraisals = appraisals.data.filter(appraisal => appraisal.appraiserId === appraiserId); | |
| return { | |
| data: filteredAppraisals, | |
| success: true | |
| }; | |
| }; | |
| export const getAppraisalsByCycleId = async (cycleId: number): Promise<ResponseData<Appraisal[]>> => { | |
| const appraisals = await getAppraisals(); | |
| const filteredAppraisals = appraisals.data.filter(appraisal => appraisal.cycleId === cycleId); | |
| return { | |
| data: filteredAppraisals, | |
| success: true | |
| }; | |
| }; | |
| export const createAppraisal = async (appraisal: AppraisalCreateRequest): Promise<ResponseData<Appraisal>> => { | |
| const response = await axios.post(`${API_BASE_URL}/api/Appraisal`, appraisal); | |
| return response.data; | |
| }; | |
| export const updateAppraisal = async (appraisal: AppraisalUpdateRequest): Promise<ResponseData<Appraisal>> => { | |
| const response = await axios.put(`${API_BASE_URL}/api/Appraisal/${appraisal.appraisalId}`, appraisal); | |
| return response.data; | |
| }; | |
| export const deleteAppraisal = async (appraisalId: number): Promise<ResponseData<boolean>> => { | |
| const response = await axios.delete(`${API_BASE_URL}/api/Appraisal/${appraisalId}`); | |
| return { | |
| data: response.status === 200, | |
| success: response.status === 200 | |
| }; | |
| }; | |
| // Assessment Areas | |
| export const getAssessmentAreas = async (): Promise<ResponseData<AssessmentArea[]>> => { | |
| try { | |
| const apiUrl = `${BASE_URL}/AssessmentArea`; | |
| console.log("Calling API: GET", apiUrl); | |
| const response = await axios.get<any>(apiUrl); | |
| console.log("Raw Assessment Areas API response:", response); | |
| // Check if response has data property | |
| if (!response.data) { | |
| console.error("API response is missing data"); | |
| return { | |
| data: [], | |
| success: false, | |
| message: "API response is missing data" | |
| }; | |
| } | |
| // Check if response.data already has the expected structure | |
| if (typeof response.data.success !== 'undefined') { | |
| console.log("Response already in expected format:", response.data); | |
| return response.data as ResponseData<AssessmentArea[]>; | |
| } | |
| // If response.data is an array, assume it's the areas data | |
| if (Array.isArray(response.data)) { | |
| console.log("Response is an array, wrapping in success structure"); | |
| return { | |
| data: response.data as AssessmentArea[], | |
| success: true | |
| }; | |
| } | |
| // If we reach here, we have data but it's in an unexpected format | |
| console.warn("API returned data in an unexpected format:", response.data); | |
| return { | |
| data: [], | |
| success: false, | |
| message: "API returned data in an unexpected format" | |
| }; | |
| } catch (error) { | |
| console.error("Error in getAssessmentAreas:", error); | |
| return { | |
| data: [], | |
| success: false, | |
| message: error instanceof Error ? error.message : "Unknown error occurred" | |
| }; | |
| } | |
| }; | |
| export const getAssessmentAreaById = async (areaId: number): Promise<ResponseData<AssessmentArea>> => { | |
| try { | |
| const apiUrl = `${BASE_URL}/AssessmentArea/${areaId}`; | |
| console.log("Calling API: GET", apiUrl); | |
| const response = await axios.get<any>(apiUrl); | |
| // Check if response has data property | |
| if (!response.data) { | |
| return { | |
| data: {} as AssessmentArea, | |
| success: false, | |
| message: "API response is missing data" | |
| }; | |
| } | |
| // Check if response.data already has the expected structure | |
| if (typeof response.data.success !== 'undefined') { | |
| return response.data as ResponseData<AssessmentArea>; | |
| } | |
| // Assume response.data is the assessment area object | |
| return { | |
| data: response.data as AssessmentArea, | |
| success: true | |
| }; | |
| } catch (error) { | |
| console.error("Error in getAssessmentAreaById:", error); | |
| return { | |
| data: {} as AssessmentArea, | |
| success: false, | |
| message: error instanceof Error ? error.message : "Unknown error occurred" | |
| }; | |
| } | |
| }; | |
| export const createAssessmentArea = async (area: AssessmentAreaCreateRequest): Promise<ResponseData<AssessmentArea>> => { | |
| try { | |
| const apiUrl = `${BASE_URL}/AssessmentArea`; | |
| console.log("Calling API: POST", apiUrl, area); | |
| const response = await axios.post<any>(apiUrl, area); | |
| if (typeof response.data.success !== 'undefined') { | |
| return response.data as ResponseData<AssessmentArea>; | |
| } | |
| return { | |
| data: response.data as AssessmentArea, | |
| success: true | |
| }; | |
| } catch (error) { | |
| console.error("Error in createAssessmentArea:", error); | |
| return { | |
| data: {} as AssessmentArea, | |
| success: false, | |
| message: error instanceof Error ? error.message : "Unknown error occurred" | |
| }; | |
| } | |
| }; | |
| export const updateAssessmentArea = async (area: AssessmentAreaUpdateRequest): Promise<ResponseData<AssessmentArea>> => { | |
| try { | |
| const apiUrl = `${BASE_URL}/AssessmentArea/${area.areaId}`; | |
| console.log("Calling API: PUT", apiUrl, area); | |
| const response = await axios.put<any>(apiUrl, area); | |
| if (typeof response.data.success !== 'undefined') { | |
| return response.data as ResponseData<AssessmentArea>; | |
| } | |
| return { | |
| data: response.data as AssessmentArea, | |
| success: true | |
| }; | |
| } catch (error) { | |
| console.error("Error in updateAssessmentArea:", error); | |
| return { | |
| data: {} as AssessmentArea, | |
| success: false, | |
| message: error instanceof Error ? error.message : "Unknown error occurred" | |
| }; | |
| } | |
| }; | |
| export const deleteAssessmentArea = async (areaId: number): Promise<ResponseData<boolean>> => { | |
| try { | |
| const apiUrl = `${BASE_URL}/AssessmentArea/${areaId}`; | |
| console.log("Calling API: DELETE", apiUrl); | |
| const response = await axios.delete(apiUrl); | |
| if (typeof response.data.success !== 'undefined') { | |
| return response.data as ResponseData<boolean>; | |
| } | |
| return { | |
| data: response.status === 200, | |
| success: response.status === 200 | |
| }; | |
| } catch (error) { | |
| console.error("Error in deleteAssessmentArea:", error); | |
| return { | |
| data: false, | |
| success: false, | |
| message: error instanceof Error ? error.message : "Unknown error occurred" | |
| }; | |
| } | |
| }; | |
| // Role Assessment Questions | |
| export const getRoleAssessmentQuestions = async (): Promise<ResponseData<RoleAssessmentQuestion[]>> => { | |
| try { | |
| const apiUrl = `${BASE_URL}/RoleAssessmentQuestion`; | |
| console.log("Calling API: GET", apiUrl); | |
| const response = await axios.get<any>(apiUrl); | |
| console.log("Raw Role Assessment Questions API response:", response); | |
| // Check if response has data property | |
| if (!response.data) { | |
| console.error("API response is missing data"); | |
| return { | |
| data: [], | |
| success: false, | |
| message: "API response is missing data" | |
| }; | |
| } | |
| // Check if response.data already has the expected structure | |
| if (typeof response.data.success !== 'undefined') { | |
| console.log("Response already in expected format:", response.data); | |
| return response.data as ResponseData<RoleAssessmentQuestion[]>; | |
| } | |
| // If response.data is an array, assume it's the questions data | |
| if (Array.isArray(response.data)) { | |
| console.log("Response is an array, wrapping in success structure"); | |
| return { | |
| data: response.data as RoleAssessmentQuestion[], | |
| success: true | |
| }; | |
| } | |
| // If we reach here, we have data but it's in an unexpected format | |
| console.warn("API returned data in an unexpected format:", response.data); | |
| return { | |
| data: [], | |
| success: false, | |
| message: "API returned data in an unexpected format" | |
| }; | |
| } catch (error) { | |
| console.error("Error in getRoleAssessmentQuestions:", error); | |
| return { | |
| data: [], | |
| success: false, | |
| message: error instanceof Error ? error.message : "Unknown error occurred" | |
| }; | |
| } | |
| }; | |
| export const getRoleAssessmentQuestionsByRoleId = async (roleId: number): Promise<ResponseData<RoleAssessmentQuestion[]>> => { | |
| const questions = await getRoleAssessmentQuestions(); | |
| const filteredQuestions = questions.data.filter(question => question.roleId === roleId); | |
| return { | |
| data: filteredQuestions, | |
| success: true | |
| }; | |
| }; | |
| export const getRoleAssessmentQuestionById = async (questionId: number): Promise<ResponseData<RoleAssessmentQuestion>> => { | |
| const response = await axios.get(`${API_BASE_URL}/api/RoleAssessmentQuestion/${questionId}`); | |
| return response.data; | |
| }; | |
| export const createRoleAssessmentQuestion = async ( | |
| questionData: RoleAssessmentQuestionCreateRequest | |
| ): Promise<ResponseData<RoleAssessmentQuestion>> => { | |
| try { | |
| const apiUrl = `${BASE_URL}/RoleAssessmentQuestion`; | |
| console.log("Calling API: POST", apiUrl, questionData); | |
| const response = await axios.post<any>(apiUrl, questionData); | |
| console.log("Create Role Assessment Question API response:", response); | |
| if (!response.data) { | |
| console.error("API response is missing data"); | |
| return { | |
| data: null, | |
| success: false, | |
| message: "API response is missing data" | |
| }; | |
| } | |
| // Check if response.data already has the expected structure | |
| if (typeof response.data.success !== 'undefined') { | |
| console.log("Response already in expected format:", response.data); | |
| return response.data as ResponseData<RoleAssessmentQuestion>; | |
| } | |
| // Assume the response.data is the created question | |
| return { | |
| data: response.data as RoleAssessmentQuestion, | |
| success: true | |
| }; | |
| } catch (error) { | |
| console.error("Error in createRoleAssessmentQuestion:", error); | |
| return { | |
| data: null, | |
| success: false, | |
| message: error instanceof Error ? error.message : "Unknown error occurred" | |
| }; | |
| } | |
| }; | |
| export const updateRoleAssessmentQuestion = async ( | |
| questionData: RoleAssessmentQuestionUpdateRequest | |
| ): Promise<ResponseData<RoleAssessmentQuestion>> => { | |
| const url = `${BASE_URL}/RoleAssessmentQuestion/${questionData.questionId}`; | |
| console.log("Calling API: PUT", url, questionData); | |
| try { | |
| const response = await axios.put<ResponseData<RoleAssessmentQuestion>>(url, questionData); | |
| // Check if response has data property | |
| if (!response.data) { | |
| console.error("API response is missing data"); | |
| return { | |
| data: {} as RoleAssessmentQuestion, | |
| success: false, | |
| message: "API response is missing data" | |
| }; | |
| } | |
| // Check if API response is in expected format | |
| if (response.data.success === undefined) { | |
| console.error("API response is not in expected format:", response.data); | |
| return { | |
| data: {} as RoleAssessmentQuestion, | |
| success: false, | |
| message: "API response is not in expected format" | |
| }; | |
| } | |
| return response.data; | |
| } catch (error) { | |
| console.error("Error updating role assessment question:", error); | |
| return { | |
| data: {} as RoleAssessmentQuestion, | |
| success: false, | |
| message: error instanceof Error ? error.message : "An unknown error occurred" | |
| }; | |
| } | |
| }; | |
| export const deleteRoleAssessmentQuestion = async (questionId: number): Promise<ResponseData<boolean>> => { | |
| const response = await axios.delete(`${API_BASE_URL}/api/RoleAssessmentQuestion/${questionId}`); | |
| return { | |
| data: response.status === 200, | |
| success: response.status === 200 | |
| }; | |
| }; | |
| // Assessment Answers | |
| export const getAssessmentAnswers = async (): Promise<ResponseData<AssessmentAnswer[]>> => { | |
| const response = await axios.get(`${API_BASE_URL}/api/AssessmentAnswer`); | |
| return response.data; | |
| }; | |
| export const getAssessmentAnswersByAppraisalId = async (appraisalId: number): Promise<ResponseData<AssessmentAnswer[]>> => { | |
| const answers = await getAssessmentAnswers(); | |
| // Handle case when answers.data is undefined | |
| if (!answers.success || !answers.data) { | |
| console.warn("No assessment answers data available"); | |
| return { | |
| data: [], | |
| success: true | |
| }; | |
| } | |
| const filteredAnswers = answers.data.filter(answer => answer.appraisalId === appraisalId); | |
| return { | |
| data: filteredAnswers, | |
| success: true | |
| }; | |
| }; | |
| export const getAssessmentAnswerById = async (answerId: number): Promise<ResponseData<AssessmentAnswer>> => { | |
| const response = await axios.get(`${API_BASE_URL}/api/AssessmentAnswer/${answerId}`); | |
| return response.data; | |
| }; | |
| export const createAssessmentAnswer = async (answer: AssessmentAnswerCreateRequest): Promise<ResponseData<AssessmentAnswer>> => { | |
| const response = await axios.post(`${API_BASE_URL}/api/AssessmentAnswer`, answer); | |
| return response.data; | |
| }; | |
| export const updateAssessmentAnswer = async (answer: AssessmentAnswerUpdateRequest): Promise<ResponseData<AssessmentAnswer>> => { | |
| const response = await axios.put(`${API_BASE_URL}/api/AssessmentAnswer/${answer.answerId}`, answer); | |
| return response.data; | |
| }; | |
| export const deleteAssessmentAnswer = async (answerId: number): Promise<ResponseData<boolean>> => { | |
| const response = await axios.delete(`${API_BASE_URL}/api/AssessmentAnswer/${answerId}`); | |
| return { | |
| data: response.status === 200, | |
| success: response.status === 200 | |
| }; | |
| }; | |
| // Competencies | |
| export const getCompetencies = async (): Promise<ResponseData<Competency[]>> => { | |
| try { | |
| const apiUrl = `${BASE_URL}/Competency`; | |
| console.log("Calling API: GET", apiUrl); | |
| const response = await axios.get<any>(apiUrl); | |
| console.log("Raw Competencies API response:", response); | |
| // Check if response has data property | |
| if (!response.data) { | |
| console.error("API response is missing data"); | |
| return { | |
| data: [], | |
| success: false, | |
| message: "API response is missing data" | |
| }; | |
| } | |
| // Check if response.data already has the expected structure | |
| if (typeof response.data.success !== 'undefined') { | |
| console.log("Response already in expected format:", response.data); | |
| return response.data as ResponseData<Competency[]>; | |
| } | |
| // If response.data is an array, assume it's the competencies data | |
| if (Array.isArray(response.data)) { | |
| console.log("Response is an array, wrapping in success structure"); | |
| return { | |
| data: response.data as Competency[], | |
| success: true | |
| }; | |
| } | |
| // If we reach here, we have data but it's in an unexpected format | |
| console.warn("API returned data in an unexpected format:", response.data); | |
| return { | |
| data: [], | |
| success: false, | |
| message: "API returned data in an unexpected format" | |
| }; | |
| } catch (error) { | |
| console.error("Error in getCompetencies:", error); | |
| return { | |
| data: [], | |
| success: false, | |
| message: error instanceof Error ? error.message : "Unknown error occurred" | |
| }; | |
| } | |
| }; | |
| export const getCompetencyById = async (competencyId: number): Promise<ResponseData<Competency>> => { | |
| try { | |
| const apiUrl = `${BASE_URL}/Competency/${competencyId}`; | |
| console.log("Calling API: GET", apiUrl); | |
| const response = await axios.get<any>(apiUrl); | |
| // Check if response has data property | |
| if (!response.data) { | |
| return { | |
| data: {} as Competency, | |
| success: false, | |
| message: "API response is missing data" | |
| }; | |
| } | |
| // Check if response.data already has the expected structure | |
| if (typeof response.data.success !== 'undefined') { | |
| return response.data as ResponseData<Competency>; | |
| } | |
| // Assume response.data is the competency object | |
| return { | |
| data: response.data as Competency, | |
| success: true | |
| }; | |
| } catch (error) { | |
| console.error("Error in getCompetencyById:", error); | |
| return { | |
| data: {} as Competency, | |
| success: false, | |
| message: error instanceof Error ? error.message : "Unknown error occurred" | |
| }; | |
| } | |
| }; | |
| export const createCompetency = async (competency: CompetencyCreateRequest): Promise<ResponseData<Competency>> => { | |
| try { | |
| const apiUrl = `${BASE_URL}/Competency`; | |
| console.log("Calling API: POST", apiUrl, competency); | |
| const response = await axios.post<any>(apiUrl, competency); | |
| if (typeof response.data.success !== 'undefined') { | |
| return response.data as ResponseData<Competency>; | |
| } | |
| return { | |
| data: response.data as Competency, | |
| success: true | |
| }; | |
| } catch (error) { | |
| console.error("Error in createCompetency:", error); | |
| return { | |
| data: {} as Competency, | |
| success: false, | |
| message: error instanceof Error ? error.message : "Unknown error occurred" | |
| }; | |
| } | |
| }; | |
| export const updateCompetency = async (competency: CompetencyUpdateRequest): Promise<ResponseData<Competency>> => { | |
| try { | |
| const apiUrl = `${BASE_URL}/Competency/${competency.competencyId}`; | |
| console.log("Calling API: PUT", apiUrl, competency); | |
| const response = await axios.put<any>(apiUrl, competency); | |
| if (typeof response.data.success !== 'undefined') { | |
| return response.data as ResponseData<Competency>; | |
| } | |
| return { | |
| data: response.data as Competency, | |
| success: true | |
| }; | |
| } catch (error) { | |
| console.error("Error in updateCompetency:", error); | |
| return { | |
| data: {} as Competency, | |
| success: false, | |
| message: error instanceof Error ? error.message : "Unknown error occurred" | |
| }; | |
| } | |
| }; | |
| export const deleteCompetency = async (competencyId: number): Promise<ResponseData<boolean>> => { | |
| try { | |
| const apiUrl = `${BASE_URL}/Competency/${competencyId}`; | |
| console.log("Calling API: DELETE", apiUrl); | |
| const response = await axios.delete(apiUrl); | |
| if (typeof response.data.success !== 'undefined') { | |
| return response.data as ResponseData<boolean>; | |
| } | |
| return { | |
| data: response.status === 200, | |
| success: response.status === 200 | |
| }; | |
| } catch (error) { | |
| console.error("Error in deleteCompetency:", error); | |
| return { | |
| data: false, | |
| success: false, | |
| message: error instanceof Error ? error.message : "Unknown error occurred" | |
| }; | |
| } | |
| }; | |
| // Competency Indicators | |
| export const getCompetencyIndicators = async (): Promise<ResponseData<CompetencyIndicator[]>> => { | |
| const response = await axios.get(`${API_BASE_URL}/api/CompetencyIndicator`); | |
| return response.data; | |
| }; | |
| export const getCompetencyIndicatorsByCompetencyId = async (competencyId: number): Promise<ResponseData<CompetencyIndicator[]>> => { | |
| const indicators = await getCompetencyIndicators(); | |
| const filteredIndicators = indicators.data.filter(indicator => indicator.competencyId === competencyId); | |
| return { | |
| data: filteredIndicators, | |
| success: true | |
| }; | |
| }; | |
| export const getCompetencyIndicatorById = async (indicatorId: number): Promise<ResponseData<CompetencyIndicator>> => { | |
| const response = await axios.get(`${API_BASE_URL}/api/CompetencyIndicator/${indicatorId}`); | |
| return response.data; | |
| }; | |
| export const createCompetencyIndicator = async (indicator: CompetencyIndicatorCreateRequest): Promise<ResponseData<CompetencyIndicator>> => { | |
| const response = await axios.post(`${API_BASE_URL}/api/CompetencyIndicator`, indicator); | |
| return response.data; | |
| }; | |
| export const updateCompetencyIndicator = async (indicator: CompetencyIndicatorUpdateRequest): Promise<ResponseData<CompetencyIndicator>> => { | |
| const response = await axios.put(`${API_BASE_URL}/api/CompetencyIndicator/${indicator.indicatorId}`, indicator); | |
| return response.data; | |
| }; | |
| export const deleteCompetencyIndicator = async (indicatorId: number): Promise<ResponseData<boolean>> => { | |
| const response = await axios.delete(`${API_BASE_URL}/api/CompetencyIndicator/${indicatorId}`); | |
| return { | |
| data: response.status === 200, | |
| success: response.status === 200 | |
| }; | |
| }; | |
| // Competency Ratings | |
| export const getCompetencyRatings = async (): Promise<ResponseData<CompetencyRating[]>> => { | |
| const response = await axios.get(`${API_BASE_URL}/api/CompetencyRating`); | |
| return response.data; | |
| }; | |
| export const getCompetencyRatingsByAppraisalId = async (appraisalId: number): Promise<ResponseData<CompetencyRating[]>> => { | |
| const ratings = await getCompetencyRatings(); | |
| // Handle case when ratings.data is undefined | |
| if (!ratings.success || !ratings.data) { | |
| console.warn("No competency ratings data available"); | |
| return { | |
| data: [], | |
| success: true | |
| }; | |
| } | |
| const filteredRatings = ratings.data.filter(rating => rating.appraisalId === appraisalId); | |
| return { | |
| data: filteredRatings, | |
| success: true | |
| }; | |
| }; | |
| export const getCompetencyRatingById = async (ratingId: number): Promise<ResponseData<CompetencyRating>> => { | |
| const response = await axios.get(`${API_BASE_URL}/api/CompetencyRating/${ratingId}`); | |
| return response.data; | |
| }; | |
| export const createCompetencyRating = async (rating: CompetencyRatingCreateRequest): Promise<ResponseData<CompetencyRating>> => { | |
| const response = await axios.post(`${API_BASE_URL}/api/CompetencyRating`, rating); | |
| return response.data; | |
| }; | |
| export const updateCompetencyRating = async (rating: CompetencyRatingUpdateRequest): Promise<ResponseData<CompetencyRating>> => { | |
| const response = await axios.put(`${API_BASE_URL}/api/CompetencyRating/${rating.ratingId}`, rating); | |
| return response.data; | |
| }; | |
| export const deleteCompetencyRating = async (ratingId: number): Promise<ResponseData<boolean>> => { | |
| const response = await axios.delete(`${API_BASE_URL}/api/CompetencyRating/${ratingId}`); | |
| return { | |
| data: response.status === 200, | |
| success: response.status === 200 | |
| }; | |
| }; | |
| // Training Needs | |
| export const getTrainingNeeds = async (): Promise<ResponseData<TrainingNeed[]>> => { | |
| const response = await axios.get(`${API_BASE_URL}/api/TrainingNeed`); | |
| return response.data; | |
| }; | |
| export const getTrainingNeedsByAppraisalId = async (appraisalId: number): Promise<ResponseData<TrainingNeed[]>> => { | |
| const trainingNeeds = await getTrainingNeeds(); | |
| // Handle case when trainingNeeds.data is undefined | |
| if (!trainingNeeds.success || !trainingNeeds.data) { | |
| console.warn("No training needs data available"); | |
| return { | |
| data: [], | |
| success: true | |
| }; | |
| } | |
| const filteredNeeds = trainingNeeds.data.filter(need => need.appraisalId === appraisalId); | |
| return { | |
| data: filteredNeeds, | |
| success: true | |
| }; | |
| }; | |
| export const getTrainingNeedById = async (trainingId: number): Promise<ResponseData<TrainingNeed>> => { | |
| const response = await axios.get(`${API_BASE_URL}/api/TrainingNeed/${trainingId}`); | |
| return response.data; | |
| }; | |
| export const createTrainingNeed = async (trainingNeed: TrainingNeedCreateRequest): Promise<ResponseData<TrainingNeed>> => { | |
| const response = await axios.post(`${API_BASE_URL}/api/TrainingNeed`, trainingNeed); | |
| return response.data; | |
| }; | |
| export const updateTrainingNeed = async (trainingNeed: TrainingNeedUpdateRequest): Promise<ResponseData<TrainingNeed>> => { | |
| const response = await axios.put(`${API_BASE_URL}/api/TrainingNeed/${trainingNeed.trainingId}`, trainingNeed); | |
| return response.data; | |
| }; | |
| export const deleteTrainingNeed = async (trainingId: number): Promise<ResponseData<boolean>> => { | |
| const response = await axios.delete(`${API_BASE_URL}/api/TrainingNeed/${trainingId}`); | |
| return { | |
| data: response.status === 200, | |
| success: response.status === 200 | |
| }; | |
| }; | |
| // HR Remarks | |
| export const getHrRemarks = async (): Promise<ResponseData<HrRemark[]>> => { | |
| const response = await axios.get(`${API_BASE_URL}/api/HrRemark`); | |
| return response.data; | |
| }; | |
| export const getHrRemarksByAppraisalId = async (appraisalId: number): Promise<ResponseData<HrRemark[]>> => { | |
| const hrRemarks = await getHrRemarks(); | |
| const filteredRemarks = hrRemarks.data.filter(remark => remark.appraisalId === appraisalId); | |
| return { | |
| data: filteredRemarks, | |
| success: true | |
| }; | |
| }; | |
| export const getHrRemarkById = async (hrRemarkId: number): Promise<ResponseData<HrRemark>> => { | |
| const response = await axios.get(`${API_BASE_URL}/api/HrRemark/${hrRemarkId}`); | |
| return response.data; | |
| }; | |
| export const createHrRemark = async (hrRemark: HrRemarkCreateRequest): Promise<ResponseData<HrRemark>> => { | |
| const response = await axios.post(`${API_BASE_URL}/api/HrRemark`, hrRemark); | |
| return response.data; | |
| }; | |
| export const updateHrRemark = async (hrRemark: HrRemarkUpdateRequest): Promise<ResponseData<HrRemark>> => { | |
| const response = await axios.put(`${API_BASE_URL}/api/HrRemark/${hrRemark.hrRemarkId}`, hrRemark); | |
| return response.data; | |
| }; | |
| export const deleteHrRemark = async (hrRemarkId: number): Promise<ResponseData<boolean>> => { | |
| const response = await axios.delete(`${API_BASE_URL}/api/HrRemark/${hrRemarkId}`); | |
| return { | |
| data: response.status === 200, | |
| success: response.status === 200 | |
| }; | |
| }; | |
| // Reporting | |
| export const generateAppraisalReport = async (appraisalId: number): Promise<Blob> => { | |
| const response = await axios.get(`${API_BASE_URL}/api/Appraisal/report/${appraisalId}`, { | |
| responseType: 'blob' | |
| }); | |
| return response.data; | |
| }; | |
| // Statistics | |
| export const getAppraisalStatistics = async (cycleId?: number): Promise<ResponseData<any>> => { | |
| const url = cycleId | |
| ? `${API_BASE_URL}/api/Appraisal/statistics?cycleId=${cycleId}` | |
| : `${API_BASE_URL}/api/Appraisal/statistics`; | |
| const response = await axios.get(url); | |
| return response.data; | |
| }; | |
| // Management Remarks | |
| export const getManagementRemarks = async (): Promise<ResponseData<ManagementRemark[]>> => { | |
| const response = await axios.get(`${API_BASE_URL}/api/ManagementRemark`); | |
| return response.data; | |
| }; | |
| export const getManagementRemarksByAppraisalId = async (appraisalId: number): Promise<ResponseData<ManagementRemark[]>> => { | |
| const remarks = await getManagementRemarks(); | |
| // Handle case when remarks.data is undefined | |
| if (!remarks.success || !remarks.data) { | |
| console.warn("No management remarks data available"); | |
| return { | |
| data: [], | |
| success: true | |
| }; | |
| } | |
| const filteredRemarks = remarks.data.filter(remark => remark.appraisalId === appraisalId); | |
| return { | |
| data: filteredRemarks, | |
| success: true | |
| }; | |
| }; | |
| export const getManagementRemarkById = async (id: number): Promise<ResponseData<ManagementRemark>> => { | |
| const response = await axios.get(` |