- Implemented subscription creation, updating, and rendering in script_9.js. - Added functions for handling subscription line items, product selection, and total calculations. - Integrated AnyDesk API for session management in test_anydesk.py. - Created REST client test requests for API endpoints in api.http. - Developed a script to check ESET machine status and save details in tmp_check_eset_machine.py.
91 lines
2.7 KiB
Python
91 lines
2.7 KiB
Python
from fastapi import APIRouter, Query
|
|
from app.core.database import execute_query
|
|
|
|
router = APIRouter()
|
|
|
|
@router.get("/search/customers")
|
|
async def search_customers(q: str = Query(..., min_length=2)):
|
|
"""
|
|
Autocomplete search for customers.
|
|
Returns list of {id, name, cvr_nummer, email}
|
|
"""
|
|
sql = """
|
|
SELECT id, name, cvr_number as cvr_nummer, email
|
|
FROM customers
|
|
WHERE (name ILIKE %s OR cvr_number ILIKE %s)
|
|
AND deleted_at IS NULL
|
|
AND is_active = true
|
|
ORDER BY name ASC
|
|
LIMIT 20
|
|
"""
|
|
term = f"%{q}%"
|
|
results = execute_query(sql, (term, term))
|
|
return results
|
|
|
|
@router.get("/search/contacts")
|
|
async def search_contacts(q: str = Query(..., min_length=2)):
|
|
"""
|
|
Autocomplete search for contacts.
|
|
Returns list of {id, first_name, last_name, email}
|
|
Supports: first name, last name, email, combined "Fornavn Efternavn", phone, mobile.
|
|
"""
|
|
sql = """
|
|
SELECT id, first_name, last_name, email
|
|
FROM contacts
|
|
WHERE
|
|
first_name ILIKE %s
|
|
OR last_name ILIKE %s
|
|
OR email ILIKE %s
|
|
OR CONCAT(first_name, ' ', last_name) ILIKE %s
|
|
OR phone ILIKE %s
|
|
OR mobile ILIKE %s
|
|
ORDER BY first_name ASC, last_name ASC
|
|
LIMIT 20
|
|
"""
|
|
term = f"%{q}%"
|
|
results = execute_query(sql, (term, term, term, term, term, term))
|
|
return results
|
|
|
|
@router.get("/search/hardware")
|
|
async def search_hardware(q: str = Query(..., min_length=2)):
|
|
"""
|
|
Autocomplete search for hardware.
|
|
Returns list of {id, brand, model, serial_number, internal_asset_id}
|
|
"""
|
|
sql = """
|
|
SELECT id, brand, model, serial_number, internal_asset_id
|
|
FROM hardware_assets
|
|
WHERE
|
|
(brand ILIKE %s OR
|
|
model ILIKE %s OR
|
|
serial_number ILIKE %s OR
|
|
internal_asset_id ILIKE %s)
|
|
AND deleted_at IS NULL
|
|
ORDER BY brand ASC, model ASC
|
|
LIMIT 20
|
|
"""
|
|
term = f"%{q}%"
|
|
results = execute_query(sql, (term, term, term, term))
|
|
return results
|
|
|
|
@router.get("/search/locations")
|
|
async def search_locations(q: str = Query(..., min_length=2)):
|
|
"""
|
|
Autocomplete search for locations.
|
|
Returns list of {id, name, address_street, address_city}
|
|
"""
|
|
sql = """
|
|
SELECT id, name, address_street, address_city
|
|
FROM locations_locations
|
|
WHERE
|
|
(name ILIKE %s OR
|
|
address_street ILIKE %s OR
|
|
address_city ILIKE %s)
|
|
AND deleted_at IS NULL
|
|
ORDER BY name ASC
|
|
LIMIT 20
|
|
"""
|
|
term = f"%{q}%"
|
|
results = execute_query(sql, (term, term, term))
|
|
return results
|