Skip to content

Supplier Functions

Documentation for Supplier Management Functions

Overview

This collection of functions provides a variety of operations related to managing supplier information within a Firebase Firestore database. These operations include fetching supplier details, updating supplier information, and managing specific fields related to supplier activities and statuses.

Function Descriptions

  1. get_supplier_by_user_id(user_id)

    • Retrieves a supplier’s profile information based on the user ID.
    • Parameters:
      • user_id: The unique identifier of the user.
    • Returns:
      • The supplier’s profile information as a dictionary if found; otherwise, None.
  2. update_supplier_pan_token(user_id, pan_token)

    • Updates the PAN token for a specific supplier.
    • Parameters:
      • user_id: The document ID in the supplierprofileinformation collection.
      • pan_token: The new PAN token to be stored.
  3. update_supplier_tier(user_id, tier)

    • Updates the subscription tier of a supplier.
    • Parameters:
      • user_id: The document ID.
      • tier: The new tier to assign to the supplier.
  4. update_supplier_search_count(user_id, new_count)

    • Updates the count of semantic searches performed by a supplier.
    • Parameters:
      • user_id: The supplier’s user ID.
      • new_count: The new count of semantic searches.
  5. get_free_suppliers()

    • Fetches a list of suppliers who are on a free subscription tier.
    • Returns:
      • A list of dictionaries, each representing a supplier on the free tier.
  6. get_paid_suppliers()

    • Retrieves a list of suppliers on paid or complementary subscription tiers.
    • Returns:
      • A list of dictionaries, each representing a supplier on a paid or complementary tier.
  7. update_supplier_proposals_generated_count(user_id, new_count)

    • Updates the number of proposals generated by a supplier.
    • Parameters:
      • user_id: The supplier’s user ID.
      • new_count: The new count to update.
  8. add_proposals_generated_field()

    • Adds a numberOfProposalsGenerated field to all supplier documents, initialized to 0.
    • Useful for setting up new database fields or ensuring data consistency across documents.
  9. add_clicked_apply_for_the_month_field()

    • Adds a field to track monthly clicks on the “apply” button by suppliers.
    • Initializes this count to 0 for all suppliers.
  10. get_all_suppliers()

    • Retrieves a list of all suppliers in the database.
    • Returns:
      • A list of all suppliers as dictionaries.
  11. reset_supplier_applyBtnClickedForTheMonth_count(user_id)

    • Resets the monthly “apply” button click count for a specific supplier.
    • Parameters:
      • user_id: The supplier’s user ID.
  12. add_total_engagement_score_field()

    • Adds a totalEngagementScore field with a value of 0 to all supplier documents.
    • Useful for tracking engagement scores across supplier profiles.
  13. reset_all_engagement_scores()

    • Resets the totalEngagementScore to 0 for all suppliers in the database.
  14. calculate_average_engagement_score()

    • Calculates the average engagement score across all suppliers.
    • Returns:
      • The average engagement score if there are suppliers; otherwise, an informative message is printed if no suppliers are found.

Usage Example

# Update a supplier's tier
user_id = 'some_user_id'
new_tier = 'premium'
update_supplier_tier(user_id, new_tier)
# Fetch all suppliers on a free tier
free_suppliers = get_free_suppliers()
print(free_suppliers)
# Calculate and print the average engagement score
average_score = calculate_average_engagement_score()
print(f"Average Engagement Score: {average_score}")

These functions are integral for managing supplier-related data within applications that utilize Firebase Firestore for data management, ensuring that supplier interactions and statuses are accurately tracked and updated.