diff --git a/src/vm_api.py b/src/vm_api.py index 5937e47..db39c7b 100644 --- a/src/vm_api.py +++ b/src/vm_api.py @@ -582,53 +582,3 @@ def delete_all_contacts(vm_session: str = Cookie(default=None)): return {"ok": True} -class AddContactIn(BaseModel): - number: str = "" - name: str - email: str | None = None - - -@app.post("/api/add_contact") -async def add_contact(body: AddContactIn, vm_session: str = Cookie(default=None)): - mb = _current_user(vm_session)[0] - num = (body.number or "").strip() - name = (body.name or "").strip() - email = (body.email or "").strip() or None - if not name: - raise HTTPException(400, "Name is required") - normalized = vm_contacts.normalize_uk(vm_contacts.digits_of(num)) if num else None - con = vm_store.connect() - if normalized: - row = con.execute( - "SELECT id FROM contacts WHERE number_e164 = ?", (normalized,) - ).fetchone() - if row and row.get("id"): - con.execute( - "UPDATE contacts SET name=?, email=?, updated_at=NOW() WHERE id=?", - (name, email, row["id"]), - ) - else: - con.execute( - "INSERT INTO contacts (number_e164, name, email) VALUES (?, ?, ?)", - (normalized, name, email), - ) - con.execute( - "UPDATE messages SET contact_name=?, contact_email=? " - "WHERE (REPLACE(REPLACE(callerid, ' ', ''), '\"', '') LIKE ? " - " OR REPLACE(REPLACE(callerid, ' ', ''), '\"', '') LIKE ?) " - "AND (contact_name IS NULL OR contact_name = '')", - (name, email, "%%%s%%" % normalized, "%%%s%%" % normalized.replace("+44", "0"),), - ) - con.commit() - con.close() - return {"ok": True} - - -@app.post("/api/contacts/delete_all") -def delete_all_contacts(vm_session: str = Cookie(default=None)): - _current_user(vm_session) - con = vm_store.connect() - con.execute("DELETE FROM contacts") - con.commit() - con.close() - return {"ok": True}