Skip to content

Billing Details Controller

The billingDetailsController in your application manages operations related to billing details. Here’s an overview of each function:

  1. getAllBillingDetails: Fetches all billing details associated with a specific user. It uses pagination to limit the results to 5 per page. The function checks if the user exists before retrieving their billing details.

  2. addBillingDetails: Adds new billing details for a user. It validates the input using a JSON schema, translates country names to codes, and saves the new billing details in the database.

  3. editBillingDetails: Updates existing billing details for a user. It first checks if the user exists and the billing details to be updated belong to the user. It then validates the update data using a JSON schema and performs the update.

  4. deleteBillingDetails: Deletes a specific billing detail entry. It checks the existence of the user and ensures that the billing details belong to the user before deletion.

Each function performs necessary validation and returns appropriate responses, including success messages and data (where applicable). The error handling mechanism throws specific errors if required conditions are not met, ensuring data integrity and authorized access.