Binrushd-Medical-Center commited on
Commit
742d105
ยท
verified ยท
1 Parent(s): f3e2734

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +32 -14
main.py CHANGED
@@ -1105,21 +1105,34 @@ def create_booking(body: BookingIn, payload=Depends(require_scopes(["user"]))):
1105
  # ====== My Bookings ======
1106
  from typing import Optional
1107
 
 
 
 
 
 
 
 
 
 
 
 
 
1108
  @app.get("/api/bookings/by-contact")
1109
  def bookings_by_contact(
1110
- payload=Depends(require_scopes(["user"])), # ู„ุงุฒู… ุชูˆูƒู† ุฏุฎูˆู„ ุนุงุฏูŠ
1111
- client_mobile: Optional[str] = Query(None),
1112
- client_email: Optional[str] = Query(None),
1113
- select: str = Query("*"),
1114
- order: str = Query("created_at.desc"),
1115
- limit: int = Query(100, ge=1, le=1000),
1116
- offset: int = Query(0, ge=0),
1117
  ):
1118
  """
1119
- ู…ุทุงุจู‚ ู„ุทุฑูŠู‚ุฉ Supabase REST:
1120
- - ูŠุฏุนู… select, order, limit, offset
1121
- - client_mobile ูˆ/ุฃูˆ client_email ุจูู„ุชุฑุฉ eq
1122
- - AND logic ู„ูˆ ุงู„ุงุชู†ูŠู† ู…ูุฑุณู„ูŠู†
 
1123
  """
1124
  if not client_mobile and not client_email:
1125
  raise HTTPException(400, "ุฃุฑุณู„ client_mobile ุฃูˆ client_email ุนู„ู‰ ุงู„ุฃู‚ู„")
@@ -1130,13 +1143,18 @@ def bookings_by_contact(
1130
  "limit": str(limit),
1131
  "offset": str(offset),
1132
  }
 
1133
  if client_mobile:
1134
- params.update(eq("client_mobile", client_mobile))
1135
  if client_email:
1136
- params.update(eq("client_email", client_email))
1137
 
1138
  rows = supa_select("bookings", params)
1139
- return {"message": "Bookings fetched successfully", "count": len(rows), "data": rows}
 
 
 
 
1140
 
1141
  # ====== Referral Sources (static list) ======
1142
  @app.get("/api/referral-sources")
 
1105
  # ====== My Bookings ======
1106
  from typing import Optional
1107
 
1108
+ def _ensure_op(val: Optional[str]) -> Optional[str]:
1109
+ """ู„ูˆ ุงู„ู‚ูŠู…ุฉ ู…ุงููŠู‡ุง ู…ุนุงู…ู„ PostgREST (eq./ilike./in./โ€ฆ)ุŒ ู†ุฒูˆุฏ eq."""
1110
+ if not val:
1111
+ return val
1112
+ ops = ("eq.", "neq.", "gt.", "gte.", "lt.", "lte.", "like.", "ilike.", "is.",
1113
+ "in.", "cs.", "cd.", "sl.", "sr.", "nxr.", "nxl.", "adj.", "ov.",
1114
+ "fts(", "plfts(", "phfts(", "wfts(")
1115
+ v = val.strip()
1116
+ if v.startswith(ops):
1117
+ return v
1118
+ return "eq." + v
1119
+
1120
  @app.get("/api/bookings/by-contact")
1121
  def bookings_by_contact(
1122
+ payload=Depends(require_scopes(["user"])), # โ† ู„ุงุฒู… ุชูˆูƒู†
1123
+ select: str = "*",
1124
+ client_mobile: Optional[str] = None,
1125
+ client_email: Optional[str] = None,
1126
+ order: str = "created_at.desc",
1127
+ limit: int = 100,
1128
+ offset: int = 0,
1129
  ):
1130
  """
1131
+ ูŠุทุงุจู‚ ุดูƒู„ ูƒูŠุฑู„ุงุช Supabase ุจุงู„ุถุจุท:
1132
+ select=*, client_mobile=eq.+966..., client_email=eq.foo@bar.com, order=..., limit=...
1133
+ - ู„ูˆ ุงุชุจุนุช ู‚ูŠู…ุฉ ุจุฏูˆู† ู…ูุนุงู…ู„ (eq./ilike/โ€ฆ): ู‡ู†ุถูŠู eq. ุชู„ู‚ุงุฆูŠู‹ุง.
1134
+ - ู„ูˆ ุงุชุจุนุช ู…ูุนุงู…ู„ ุฃุตู„ุงู‹ุŒ ู‡ู†ุนุฏู‘ูŠู‡ุง ูƒู…ุง ู‡ูŠ.
1135
+ - ู„ูˆ ู…ุจุนูˆุชุด ุฃูŠ ู…ู† mobile/email ู‡ู†ุฑุฌู‘ุน 400.
1136
  """
1137
  if not client_mobile and not client_email:
1138
  raise HTTPException(400, "ุฃุฑุณู„ client_mobile ุฃูˆ client_email ุนู„ู‰ ุงู„ุฃู‚ู„")
 
1143
  "limit": str(limit),
1144
  "offset": str(offset),
1145
  }
1146
+
1147
  if client_mobile:
1148
+ params["client_mobile"] = _ensure_op(client_mobile)
1149
  if client_email:
1150
+ params["client_email"] = _ensure_op(client_email)
1151
 
1152
  rows = supa_select("bookings", params)
1153
+ return {
1154
+ "message": "Bookings fetched successfully",
1155
+ "count": len(rows),
1156
+ "data": rows
1157
+ }
1158
 
1159
  # ====== Referral Sources (static list) ======
1160
  @app.get("/api/referral-sources")