Skip to content

Users and Payments API Guidelines

Documentation for API Helper Functions

Overview

These functions facilitate communication between the frontend and the backend APIs, handling various tasks like authentication, user management, and payment processing.

Function Descriptions

  1. findPayment, findAllPayments, createPayment, adminGetAllPayments: These functions manage payment-related operations. They handle retrieving specific payments, listing all payments for a user, creating new payments, and providing an admin view of all payments.

  2. loginUser: Handles user authentication. On successful login, it triggers a success toast; otherwise, it displays an error message.

  3. getAllPayments, getOnePayment: Used for fetching payment details - either all payments for a user or a specific payment.

  4. getAllUsers, createOneUser, getOneUser, updateUser, deleteUser: These functions manage user-related operations, including fetching all users, creating a new user, retrieving, updating, or deleting a specific user.

Response Structure

The typical response from the backend has the following structure:

{
message: "Descriptive message about the request",
data: requestedData
}

Error Handling

Each function includes try-catch blocks for error handling. In case of an error, they return the error object, allowing the calling component to handle it appropriately.

Security

For secure endpoints, these functions use Axios to send an Authorization header containing the user’s token, ensuring that the requests are authenticated.

Use in Components

These functions are designed to be imported and used in React components, providing a streamlined way to interact with the backend API, handle data, and display relevant notifications to users.