setup customer agent healthcheck (#70)
taylor_socfortress committed
Jul 26, 2023 at 10:25 UTC
f9a8fed8c43657a43baaaeff0486fa9238e1e21d
1 file changed
+23
backend/app/routes/customers.py
+23
@@ -275,3 +275,26 @@ def read_customer_and_meta_details(id: int):
275
if customer and customer_meta:
276
return jsonify({"customer": customer, "customer_meta": customer_meta, "message": "Customer details fetched.", "success": True}), 200
277
return jsonify({"message": "Customer or Customer Meta not found", "success": False}), 404
278
+
279
+
280
+@bp.route("/customers/healthcheck/agents/<int:id>", methods=["GET"])
281
+def read_customer_healthcheck(id: int):
282
+ """
283
+ Endpoint to fetch the `customerCode` from the `customers_meta` table for the given customer id.
284
+ Then, it uses the customer code to fetch all agents from the `agent_metadata` table where the `customerCode`
285
+ is a wildcard match on the `label` column within the `agent_metadata` table.
286
+
287
+ Returns:
288
+ Tuple[jsonify, int]: A Tuple where the first element is a JSON response
289
+ containing the customer code and the list of agents, and the second element is
290
+ the HTTP status code.
291
+ """
292
+ logger.info(f"Received request to get customer healthcheck with id {id}")
293
+ customer_meta = UniversalCustomersMeta.read_by_id(id)
294
+ if customer_meta:
295
+ customer_code = customer_meta["customerCode"]
296
+ logger.info(f"Customer code for customer id {id} is {customer_code}")
297
+ exit(0)
298
+ agents = UniversalCustomersMeta.read_agents_by_customer_code(customer_code)
299
+ return jsonify({"customerCode": customer_code, "agents": agents, "message": "Customer healthcheck fetched.", "success": True}), 200
300
+ return jsonify({"message": "Customer Meta not found", "success": False}), 404