sdsad
This commit is contained in:
@@ -265,6 +265,10 @@ final class Router
|
||||
Http::json(['data' => $this->saveCostPlan($projectKey, Http::input())], 201);
|
||||
}
|
||||
|
||||
if (preg_match('~^cost-plans/(\d+)$~', $resource, $matches) && $method === 'PATCH') {
|
||||
Http::json(['data' => $this->updateCostPlan($projectKey, (int) $matches[1], Http::input())]);
|
||||
}
|
||||
|
||||
if ($resource === 'payouts' && $method === 'GET') {
|
||||
Http::json(['data' => $this->payouts($projectKey)]);
|
||||
}
|
||||
@@ -1912,6 +1916,24 @@ final class Router
|
||||
]);
|
||||
}
|
||||
|
||||
private function updateCostPlan(string $projectKey, int $planId, array $input): array
|
||||
{
|
||||
$plan = $this->repository()->getCostPlan($projectKey, $planId);
|
||||
if (!is_array($plan)) {
|
||||
throw new ApiException('Manuell eingetragener Miner nicht gefunden.', 404);
|
||||
}
|
||||
|
||||
if (!array_key_exists('auto_renew', $input)) {
|
||||
throw new ApiException('Es kann aktuell nur auto_renew geaendert werden.', 422, ['field' => 'auto_renew']);
|
||||
}
|
||||
|
||||
return $this->repository()->updateCostPlanAutoRenew(
|
||||
$projectKey,
|
||||
$planId,
|
||||
!empty($input['auto_renew'])
|
||||
);
|
||||
}
|
||||
|
||||
private function savePayout(string $projectKey, array $input): array
|
||||
{
|
||||
$transferMode = $this->enumValue($input['transfer_mode'] ?? 'manual', ['manual', 'full_latest'], 'transfer_mode');
|
||||
|
||||
@@ -267,6 +267,70 @@ final class MiningRepository
|
||||
return $this->normalizeRow($fetch->fetch() ?: []);
|
||||
}
|
||||
|
||||
public function getCostPlan(string $projectKey, int $planId): ?array
|
||||
{
|
||||
$stmt = $this->pdo->prepare(
|
||||
'SELECT * FROM ' . $this->table('cost_plans') . ' WHERE project_key = :project_key AND owner_sub = :owner_sub AND id = :id LIMIT 1'
|
||||
);
|
||||
$stmt->execute([
|
||||
'project_key' => $projectKey,
|
||||
'owner_sub' => $this->ownerSub,
|
||||
'id' => $planId,
|
||||
]);
|
||||
$row = $stmt->fetch();
|
||||
if (is_array($row)) {
|
||||
return $this->normalizeRow($row);
|
||||
}
|
||||
|
||||
$legacyStmt = $this->pdo->prepare(
|
||||
'SELECT * FROM ' . $this->table('cost_plans') . ' WHERE project_key = :project_key AND id = :id LIMIT 1'
|
||||
);
|
||||
$legacyStmt->execute([
|
||||
'project_key' => $projectKey,
|
||||
'id' => $planId,
|
||||
]);
|
||||
$legacyRow = $legacyStmt->fetch();
|
||||
return is_array($legacyRow) ? $this->normalizeRow($legacyRow) : null;
|
||||
}
|
||||
|
||||
public function updateCostPlanAutoRenew(string $projectKey, int $planId, bool $autoRenew): array
|
||||
{
|
||||
$stmt = $this->pdo->prepare(
|
||||
'UPDATE ' . $this->table('cost_plans') . '
|
||||
SET auto_renew = :auto_renew
|
||||
WHERE project_key = :project_key AND owner_sub = :owner_sub AND id = :id'
|
||||
);
|
||||
$stmt->execute([
|
||||
'auto_renew' => $autoRenew ? 1 : 0,
|
||||
'project_key' => $projectKey,
|
||||
'owner_sub' => $this->ownerSub,
|
||||
'id' => $planId,
|
||||
]);
|
||||
|
||||
if ($stmt->rowCount() === 0) {
|
||||
$legacyUpdate = $this->pdo->prepare(
|
||||
'UPDATE ' . $this->table('cost_plans') . '
|
||||
SET auto_renew = :auto_renew
|
||||
WHERE project_key = :project_key AND id = :id'
|
||||
);
|
||||
$legacyUpdate->execute([
|
||||
'auto_renew' => $autoRenew ? 1 : 0,
|
||||
'project_key' => $projectKey,
|
||||
'id' => $planId,
|
||||
]);
|
||||
}
|
||||
|
||||
$fetch = $this->pdo->prepare(
|
||||
'SELECT * FROM ' . $this->table('cost_plans') . ' WHERE project_key = :project_key AND owner_sub = :owner_sub AND id = :id LIMIT 1'
|
||||
);
|
||||
$fetch->execute([
|
||||
'project_key' => $projectKey,
|
||||
'owner_sub' => $this->ownerSub,
|
||||
'id' => $planId,
|
||||
]);
|
||||
return $this->normalizeRow($fetch->fetch() ?: []);
|
||||
}
|
||||
|
||||
public function listMeasurements(string $projectKey, int $limit = 200): array
|
||||
{
|
||||
$stmt = $this->pdo->prepare(
|
||||
@@ -915,7 +979,19 @@ final class MiningRepository
|
||||
'id' => $minerId,
|
||||
]);
|
||||
$row = $stmt->fetch();
|
||||
return is_array($row) ? $this->normalizeRow($row) : null;
|
||||
if (is_array($row)) {
|
||||
return $this->normalizeRow($row);
|
||||
}
|
||||
|
||||
$legacyStmt = $this->pdo->prepare(
|
||||
'SELECT * FROM ' . $this->table('purchased_miners') . ' WHERE project_key = :project_key AND id = :id LIMIT 1'
|
||||
);
|
||||
$legacyStmt->execute([
|
||||
'project_key' => $projectKey,
|
||||
'id' => $minerId,
|
||||
]);
|
||||
$legacyRow = $legacyStmt->fetch();
|
||||
return is_array($legacyRow) ? $this->normalizeRow($legacyRow) : null;
|
||||
}
|
||||
|
||||
public function purchaseMiner(string $projectKey, ?int $offerId, array $payload): array
|
||||
@@ -1027,6 +1103,19 @@ final class MiningRepository
|
||||
'id' => $minerId,
|
||||
]);
|
||||
|
||||
if ($stmt->rowCount() === 0) {
|
||||
$legacyUpdate = $this->pdo->prepare(
|
||||
'UPDATE ' . $this->table('purchased_miners') . '
|
||||
SET auto_renew = :auto_renew
|
||||
WHERE project_key = :project_key AND id = :id'
|
||||
);
|
||||
$legacyUpdate->execute([
|
||||
'auto_renew' => $autoRenew ? 1 : 0,
|
||||
'project_key' => $projectKey,
|
||||
'id' => $minerId,
|
||||
]);
|
||||
}
|
||||
|
||||
$fetch = $this->pdo->prepare(
|
||||
'SELECT * FROM ' . $this->table('purchased_miners') . ' WHERE project_key = :project_key AND owner_sub = :owner_sub AND id = :id LIMIT 1'
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user