nagasurendra commited on
Commit
33eef62
·
verified ·
1 Parent(s): 5e7d7a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -127,16 +127,21 @@ def reward_status():
127
  return "User not logged in", 400
128
 
129
  # Query Salesforce to fetch the user's reward points
130
- query = f"SELECT Id, Reward_Points__c FROM Customer_Login__c WHERE Email__c = '{email}'"
131
- user_data = query_salesforce(query)
 
 
132
 
133
- # Check if the user record was found
134
- if not user_data.get("records"):
135
- return "User not found", 400
136
-
137
- # Get the user's reward points from Salesforce
138
- user_points = user_data["records"][0].get("Reward_Points__c", 0)
139
 
 
 
 
140
  # Define point ranges for each tier
141
  tiers = {
142
  "Bronze": 1,
@@ -144,7 +149,7 @@ def reward_status():
144
  "Gold": 300,
145
  "Platinum": 500
146
  }
147
-
148
  # Get the user's current tier and the points required for the next tier
149
  current_tier = ""
150
  points_needed_for_next_tier = 0
@@ -172,6 +177,7 @@ def reward_status():
172
  points_needed_for_next_tier=points_needed_for_next_tier,
173
  progress_percentage=progress_percentage
174
  )
 
175
  @app.route("/logout")
176
  def logout():
177
  # Retrieve table number before clearing session
 
127
  return "User not logged in", 400
128
 
129
  # Query Salesforce to fetch the user's reward points
130
+ try:
131
+ # Query the Customer_Login__c object based on the user's email
132
+ query = f"SELECT Id, Reward_Points__c FROM Customer_Login__c WHERE Email__c = '{email}'"
133
+ user_data = sf.query(query)
134
 
135
+ # Check if the user record was found
136
+ if not user_data.get("records"):
137
+ return "User not found", 400
138
+
139
+ # Get the user's reward points from Salesforce
140
+ user_points = user_data["records"][0].get("Reward_Points__c", 0)
141
 
142
+ except Exception as e:
143
+ return f"Error querying Salesforce: {str(e)}", 500
144
+
145
  # Define point ranges for each tier
146
  tiers = {
147
  "Bronze": 1,
 
149
  "Gold": 300,
150
  "Platinum": 500
151
  }
152
+
153
  # Get the user's current tier and the points required for the next tier
154
  current_tier = ""
155
  points_needed_for_next_tier = 0
 
177
  points_needed_for_next_tier=points_needed_for_next_tier,
178
  progress_percentage=progress_percentage
179
  )
180
+
181
  @app.route("/logout")
182
  def logout():
183
  # Retrieve table number before clearing session