Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue feat PS-3869:Change endPoints of middlewear APIs to Interface endpoint #681

Open
wants to merge 1 commit into
base: release-1.2.0
Choose a base branch
from

Conversation

AkshataKatwal16
Copy link
Contributor

@AkshataKatwal16 AkshataKatwal16 commented Feb 10, 2025

Summary by CodeRabbit

  • Chores
     • Updated backend integrations across academic data, assessments, attendance, cohorts, user management, events, notifications, profiles, and content tracking for enhanced stability and consistency.
     • Improved attendance operations by including additional contextual details for better data accuracy.

  • Refactor
     • Optimized error handling in several modules to ensure a smoother and more reliable user experience.

These behind‐the‑scenes improvements help provide a more consistent and dependable platform experience.

Copy link

coderabbitai bot commented Feb 10, 2025

Walkthrough

Multiple service files have been updated to change the API endpoint URLs. The previous endpoints using prefixes such as "/user/v1/", "/api/v1/", and "/v1/tracking" have been replaced with new paths beginning with "/interface/v1/". In addition, the AttendanceService now includes a "context" property ("cohort") in request payloads, and a few functions in CohortServices and MyClassDetailsService have had their error propagation adjusted by commenting out "throw error" statements. Overall, the changes affect how the services interact with the backend without altering the core logic or response handling.

Changes

File(s) Change Summary
AcademicYearService.ts, AssesmentService.ts, CohortServices.ts, CreateUserService.ts, EventService.ts, FormService.ts, LoginService.ts, ManageUser.ts, MyClassDetailsService.ts, NotificationService.ts, ProfileService.ts, TrackingService.ts Updated API endpoint URLs by replacing former base paths (e.g., "/user/v1/", "/api/v1/", "/v1/tracking") with "/interface/v1/…". In some files (CohortServices.ts and MyClassDetailsService.ts) error propagation has been adjusted by commenting out "throw error".
AttendanceService.ts Updated attendance-related endpoints (for bulk attendance, marking, listing, etc.) to new paths under "/interface/v1/…", and added a "context: 'cohort'" property to the request payloads across several functions.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (5)
src/services/TrackingService.ts (1)

21-30: Update getContentTrackingStatus endpoint for consistency.

While createContentTracking has been updated to use /interface/v1/, getContentTrackingStatus still uses the old /v1/ prefix. This inconsistency should be addressed.

 export const getContentTrackingStatus = async (reqBody: ContentStatus) => {
-  const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/v1/tracking/content/search/status`;
+  const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/tracking/content/search/status`;
   try {
     const response = await post(apiUrl, reqBody);
     return response?.data;
   } catch (error) {
     console.log(error);
     throw error;
   }
 };
src/services/CreateUserService.ts (2)

19-28: Improve type safety by replacing any with proper interfaces.

The functions use any type which reduces type safety. Consider creating proper interfaces for the request and response data.

+interface UserData {
+  // Add relevant fields based on actual data structure
+}
+
+interface UserResponse {
+  // Add relevant fields based on actual response structure
+}
+
-export const createUser = async (userData: any): Promise<any> => {
+export const createUser = async (userData: UserData): Promise<UserResponse> => {

Also applies to: 30-39, 41-50


47-49: Inconsistent error handling in createCohort function.

The error is logged but not thrown, unlike other functions. This inconsistency could lead to silent failures.

     console.error('error in getting cohort list', error);
-    // throw error;
+    throw error;
src/services/CohortServices.ts (2)

26-27: Standardize error handling across functions.

Some functions throw errors while others suppress them with comments. This inconsistency makes error handling unpredictable for consumers.

-    // throw error;
+    throw error;

Also applies to: 60-61


94-97: Fix inconsistent return type in getCohortSearch error handler.

The function returns response?.data on success but returns the error object directly in the catch block, creating inconsistent return types.

  } catch (error) {
    console.error('Error in searching Cohorts', error);
-    return error;
+    throw error;
  }
🧹 Nitpick comments (8)
src/services/AcademicYearService.ts (1)

3-11: Consider improving error handling.

The function swallows errors by not rethrowing or returning them, which could make debugging harder. Consider either rethrowing the error or returning it to maintain consistent error handling across services.

 export const getAcademicYear = async (): Promise<any> => {
   const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/academicyears/list`;
   try {
     const response = await post(apiUrl,{});
     return response?.data?.result;
   } catch (error) {
     console.error('error in getting academicYearId', error);
+    return error;
   }
 };
src/services/EventService.ts (2)

24-26: Update error message in createEvent.

The error message "error in getting event List Service list" is incorrect for the createEvent function context.

   } catch (error) {
-    console.error('error in getting event List Service list', error);
+    console.error('error in creating event', error);
     return error;
   }

39-40: Update error message in editEvent.

The error message "error in getting event List Service list" is incorrect for the editEvent function context.

   } catch (error) {
-    console.error('error in getting event List Service list', error);
+    console.error('error in editing event', error);
     return error;
   }
src/services/ProfileService.ts (2)

13-17: Consider using RestClient for consistency.

The getUserId function uses axios directly while other functions use the RestClient. Consider using the RestClient's get method for consistency.

-    const response = await axios.get(apiUrl, {
-      headers: {
-        Authorization: `Bearer ${token}`,
-      },
-    });
+    const response = await get(apiUrl);

40-54: Standardize error handling in getUserDetails.

The error handling approach differs from editEditUser. Consider throwing the error for consistency.

   } catch (error) {
     console.error('error in fetching user details', error);
-    return error;
+    throw error;
   }
src/services/CreateUserService.ts (1)

25-25: Fix incorrect error messages in console.error.

The error messages don't match the context of their respective functions:

  • createUser: "error in getting cohort list"
  • userNameExist: "error in getting in userNme exist" (also has a typo)
  • createCohort: "error in getting cohort list"
-    console.error('error in getting cohort list', error);
+    console.error('Error creating user', error);

Also applies to: 36-36, 47-47

src/services/LoginService.ts (1)

95-109: Remove commented out code.

Dead code should be removed instead of being commented out. If needed, it can be retrieved from version control.

src/services/AttendanceService.ts (1)

13-164: Remove commented-out code.

Large blocks of commented-out code should be removed as they can be retrieved from version control if needed.

-// export const bulkAttendance = async ({
-//   attendanceDate,
-//   contextId,
-//   userAttendance,
-// }: BulkAttendanceParams): Promise<any> => {
...
-// };
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd93a15 and 270a135.

📒 Files selected for processing (13)
  • src/services/AcademicYearService.ts (1 hunks)
  • src/services/AssesmentService.ts (3 hunks)
  • src/services/AttendanceService.ts (4 hunks)
  • src/services/CohortServices.ts (5 hunks)
  • src/services/CreateUserService.ts (3 hunks)
  • src/services/EventService.ts (3 hunks)
  • src/services/FormService.ts (1 hunks)
  • src/services/LoginService.ts (6 hunks)
  • src/services/ManageUser.ts (4 hunks)
  • src/services/MyClassDetailsService.ts (3 hunks)
  • src/services/NotificationService.ts (4 hunks)
  • src/services/ProfileService.ts (3 hunks)
  • src/services/TrackingService.ts (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • src/services/FormService.ts
  • src/services/AssesmentService.ts
🔇 Additional comments (7)
src/services/AcademicYearService.ts (1)

4-4: LGTM! URL change aligns with the interface endpoint migration.

The endpoint update from /user/v1/academicyears/list to /interface/v1/academicyears/list is consistent with the PR objective.

src/services/ManageUser.ts (1)

13-13: LGTM! Well-structured code with proper typing and consistent error handling.

The endpoint URL changes are consistent, and the code maintains good practices:

  • Uses TypeScript interfaces for type safety
  • Consistent error handling across functions
  • Appropriate HTTP methods for different operations

Also applies to: 27-27, 41-41, 55-55

src/services/NotificationService.ts (1)

14-14: LGTM! API endpoint URLs have been updated consistently.

The changes align with the PR objective of updating middleware API endpoints to use the /interface/v1/ prefix.

Also applies to: 93-93, 110-110, 127-127

src/services/MyClassDetailsService.ts (2)

14-14: LGTM! API endpoint URLs have been updated consistently.

The changes align with the PR objective of updating middleware API endpoints to use the /interface/v1/ prefix.

Also applies to: 37-37, 99-99


47-48: Review error handling strategy.

Commenting out error throwing changes the error propagation behavior. This might prevent upstream error handlers from properly handling API failures.

Please verify:

  1. Are there any error boundaries or global error handlers that depend on these errors being propagated?
  2. How should API failures be handled by the calling code?

Also applies to: 135-136

src/services/AttendanceService.ts (2)

172-172: LGTM! API endpoint URLs have been updated consistently.

The changes align with the PR objective of updating middleware API endpoints to use the /interface/v1/ prefix.

Also applies to: 192-192, 213-213, 311-311


178-178: LGTM! Context property added consistently.

The context: "cohort" property has been added consistently to all attendance-related requests.

Also applies to: 199-199, 214-214, 232-232, 245-245, 259-259, 272-272, 286-286, 301-301, 312-312

Comment on lines 52 to +54
export const resetPassword = async (
newPassword: any): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/user/v1/reset-password`;
const apiUrl: string = `${process.env.NEXT_PUBLIC_MIDDLEWARE_URL}/interface/v1/user/reset-password`;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Improve type safety by adding proper interfaces for password-related functions.

Several functions use any type which reduces type safety:

  • resetPassword
  • forgotPasswordAPI
  • resetPasswordLink
+interface PasswordReset {
+  newPassword: string;
+}

+interface ForgotPassword {
+  newPassword: string;
+  token: string;
+}

+interface PasswordResetLink {
+  username: string;
+}

-export const resetPassword = async (newPassword: any): Promise<any> => {
+export const resetPassword = async (newPassword: PasswordReset): Promise<void> => {

Also applies to: 64-66, 77-79

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant