Korjaa saatavuuskyselyt: näytä kaikkien yritysten kyselyt
Endpoint näytti vain aktiivisen yrityksen kyselyt, mutta kyselyt tallennetaan API-avaimen yrityksen alle. Nyt näytetään kaikkien käyttäjän yritysten kyselyt + yrityssarake taulukkoon. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
18
api.php
18
api.php
@@ -1240,16 +1240,24 @@ switch ($action) {
|
||||
// ---------- SAATAVUUSKYSELYT ----------
|
||||
case 'availability_queries':
|
||||
requireAuth();
|
||||
$companyId = requireCompanyOrParam();
|
||||
$limit = (int)($_GET['limit'] ?? 100);
|
||||
$offset = (int)($_GET['offset'] ?? 0);
|
||||
if ($limit > 500) $limit = 500;
|
||||
|
||||
$total = (int)_dbFetchScalar("SELECT COUNT(*) FROM availability_queries WHERE company_id = ?", [$companyId]);
|
||||
// Näytä kaikkien käyttäjän yritysten kyselyt
|
||||
$userCompanyIds = $_SESSION['companies'] ?? [];
|
||||
if (empty($userCompanyIds)) {
|
||||
echo json_encode(['total' => 0, 'queries' => []]);
|
||||
break;
|
||||
}
|
||||
$placeholders = implode(',', array_fill(0, count($userCompanyIds), '?'));
|
||||
$total = (int)_dbFetchScalar("SELECT COUNT(*) FROM availability_queries WHERE company_id IN ($placeholders)", $userCompanyIds);
|
||||
$params = array_merge($userCompanyIds, [$limit, $offset]);
|
||||
$rows = _dbFetchAll(
|
||||
"SELECT id, osoite, postinumero, kaupunki, saatavilla, ip_address, referer, created_at
|
||||
FROM availability_queries WHERE company_id = ? ORDER BY created_at DESC LIMIT ? OFFSET ?",
|
||||
[$companyId, $limit, $offset]
|
||||
"SELECT aq.id, aq.company_id, c.nimi as company_nimi, aq.osoite, aq.postinumero, aq.kaupunki, aq.saatavilla, aq.ip_address, aq.referer, aq.created_at
|
||||
FROM availability_queries aq LEFT JOIN companies c ON c.id = aq.company_id
|
||||
WHERE aq.company_id IN ($placeholders) ORDER BY aq.created_at DESC LIMIT ? OFFSET ?",
|
||||
$params
|
||||
);
|
||||
echo json_encode(['total' => $total, 'queries' => $rows]);
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user