debug
All checks were successful
Deploy / deploy-staging (push) Successful in 6s
Deploy / deploy-production (push) Has been skipped

This commit is contained in:
2026-04-24 23:12:19 +02:00
parent 92c9bed5bb
commit 739e4d4c42
6 changed files with 352 additions and 29 deletions

View File

@@ -291,6 +291,16 @@ $mm->registerFunction($moduleName, 'bavest_request', static function (
$method = in_array($method, ['GET', 'POST'], true) ? $method : 'POST';
if ($apiKey === '') {
module_debug_push('boersenchecker', [
'label' => 'Bavest Request',
'type' => 'api:error',
'request' => [
'method' => $method,
'path' => $path,
'payload' => $payload,
],
'message' => 'Bavest-API-Key fehlt. Bitte im Modul-Setup hinterlegen.',
]);
return [
'ok' => false,
'message' => 'Bavest-API-Key fehlt. Bitte im Modul-Setup hinterlegen.',
@@ -366,6 +376,21 @@ $mm->registerFunction($moduleName, 'bavest_request', static function (
}
if (!is_string($responseBody) || $responseBody === '') {
module_debug_push('boersenchecker', [
'label' => 'Bavest Request',
'type' => 'api:error',
'request' => [
'method' => $method,
'url' => $url,
'payload' => $payload,
],
'response' => [
'http_code' => $httpCode,
'curl_error' => $curlError,
'body' => null,
],
'message' => 'Bavest Anfrage fehlgeschlagen.',
]);
return [
'ok' => false,
'message' => 'Bavest Anfrage fehlgeschlagen.'
@@ -376,6 +401,20 @@ $mm->registerFunction($moduleName, 'bavest_request', static function (
$decoded = json_decode($responseBody, true);
if (!is_array($decoded)) {
module_debug_push('boersenchecker', [
'label' => 'Bavest Request',
'type' => 'api:error',
'request' => [
'method' => $method,
'url' => $url,
'payload' => $payload,
],
'response' => [
'http_code' => $httpCode,
'body_preview' => substr($responseBody, 0, 4000),
],
'message' => 'Bavest Antwort ist kein gueltiges JSON.',
]);
return [
'ok' => false,
'message' => 'Bavest Antwort ist kein gueltiges JSON.',
@@ -385,6 +424,20 @@ $mm->registerFunction($moduleName, 'bavest_request', static function (
foreach (['error', 'message', 'detail'] as $errorKey) {
if (isset($decoded[$errorKey]) && is_string($decoded[$errorKey]) && trim($decoded[$errorKey]) !== '') {
module_debug_push('boersenchecker', [
'label' => 'Bavest Request',
'type' => 'api:error',
'request' => [
'method' => $method,
'url' => $url,
'payload' => $payload,
],
'response' => [
'http_code' => $httpCode,
'body' => $decoded,
],
'message' => trim((string) $decoded[$errorKey]),
]);
return [
'ok' => false,
'message' => trim((string) $decoded[$errorKey]),
@@ -393,6 +446,20 @@ $mm->registerFunction($moduleName, 'bavest_request', static function (
}
}
module_debug_push('boersenchecker', [
'label' => 'Bavest Request',
'type' => 'api:response',
'request' => [
'method' => $method,
'url' => $url,
'payload' => $payload,
],
'response' => [
'http_code' => $httpCode,
'body' => $decoded,
],
]);
return [
'ok' => true,
'data' => $decoded,
@@ -769,3 +836,77 @@ $mm->registerFunction($moduleName, 'bavest_fetch_chart_series', static function
'source' => 'bavest:timeseries/history',
];
});
$mm->registerFunction($moduleName, 'store_market_quote', static function (
int $instrumentId,
float $price,
string $currency,
string $quotedAt,
string $source
): array {
$pdo = module_fn('boersenchecker', 'pdo');
$quoteTable = module_fn('boersenchecker', 'table', 'quotes');
$quotedAt = trim($quotedAt);
$currency = strtoupper(trim($currency)) ?: 'EUR';
$source = trim($source) !== '' ? trim($source) : 'bavest:quote';
$checkStmt = $pdo->prepare(
'SELECT id
FROM ' . $quoteTable . '
WHERE instrument_id = :instrument_id
AND price = :price
AND currency = :currency
AND quoted_at = :quoted_at
AND source = :source
LIMIT 1'
);
$checkStmt->execute([
'instrument_id' => $instrumentId,
'price' => $price,
'currency' => $currency,
'quoted_at' => $quotedAt,
'source' => $source,
]);
$existingId = (int) $checkStmt->fetchColumn();
if ($existingId > 0) {
module_debug_push('boersenchecker', [
'label' => 'Quote Store',
'type' => 'quote:reuse',
'instrument_id' => $instrumentId,
'price' => $price,
'currency' => $currency,
'quoted_at' => $quotedAt,
'source' => $source,
'message' => 'Identischer Snapshot bereits vorhanden.',
]);
return ['ok' => true, 'inserted' => false, 'id' => $existingId];
}
$insertStmt = $pdo->prepare(
'INSERT INTO ' . $quoteTable . ' (instrument_id, price, currency, quoted_at, source)
VALUES (:instrument_id, :price, :currency, :quoted_at, :source)'
);
$insertStmt->execute([
'instrument_id' => $instrumentId,
'price' => $price,
'currency' => $currency,
'quoted_at' => $quotedAt,
'source' => $source,
]);
$insertedId = (int) $pdo->lastInsertId();
module_debug_push('boersenchecker', [
'label' => 'Quote Store',
'type' => 'quote:insert',
'instrument_id' => $instrumentId,
'price' => $price,
'currency' => $currency,
'quoted_at' => $quotedAt,
'source' => $source,
'inserted_id' => $insertedId,
'message' => 'Neuer Snapshot gespeichert.',
]);
return ['ok' => true, 'inserted' => true, 'id' => $insertedId];
});