Update main.py
Browse files
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 |
-
|
| 1112 |
-
|
| 1113 |
-
|
| 1114 |
-
order: str =
|
| 1115 |
-
limit: int =
|
| 1116 |
-
offset: int =
|
| 1117 |
):
|
| 1118 |
"""
|
| 1119 |
-
|
| 1120 |
-
|
| 1121 |
-
|
| 1122 |
-
|
|
|
|
| 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
|
| 1135 |
if client_email:
|
| 1136 |
-
params
|
| 1137 |
|
| 1138 |
rows = supa_select("bookings", params)
|
| 1139 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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")
|