This commit is contained in:
Jake Barnby 2025-08-15 02:01:44 +12:00
parent ef8d1b525d
commit 237263a194
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
9 changed files with 15 additions and 16 deletions

View file

@ -87,12 +87,12 @@ class Decrement extends Action
public function action(string $databaseId, string $collectionId, string $documentId, string $attribute, int|float $value, int|float|null $min, ?string $transactionId, UtopiaResponse $response, Database $dbForProject, Event $queueForEvents, StatsUsage $queueForStatsUsage, array $plan): void
{
$database = Authorization::skip(fn() => $dbForProject->getDocument('databases', $databaseId));
$database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId));
if ($database->isEmpty()) {
throw new Exception(Exception::DATABASE_NOT_FOUND);
}
$collection = Authorization::skip(fn() => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId));
$collection = Authorization::skip(fn () => $dbForProject->getDocument('database_' . $database->getSequence(), $collectionId));
if ($collection->isEmpty()) {
throw new Exception($this->getParentNotFoundException());
}

View file

@ -109,7 +109,7 @@ class Update extends Action
$hasRelationships = \array_filter(
$collection->getAttribute('attributes', []),
fn($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP
fn ($attribute) => $attribute->getAttribute('type') === Database::VAR_RELATIONSHIP
);
if ($hasRelationships) {

View file

@ -402,7 +402,7 @@ class Create extends Action
'databaseInternalId' => $database->getSequence(),
'collectionInternalId' => $collection->getSequence(),
'transactionInternalId' => $transaction->getSequence(),
'documentId' => $isBulk ? null: $documentId,
'documentId' => $isBulk ? null : $documentId,
'action' => $isBulk ? 'bulkCreate' : 'create',
'data' => $isBulk ? $documents : $documents[0],
]);
@ -476,7 +476,7 @@ class Create extends Action
->addMetric(str_replace('{databaseInternalId}', $database->getSequence(), METRIC_DATABASE_ID_OPERATIONS_WRITES), \max(1, $operations)); // per collection
$response->setStatusCode(SwooleResponse::STATUS_CODE_CREATED);
if ($isBulk) {
$response->dynamic(new Document([
'total' => count($documents),

View file

@ -69,4 +69,4 @@ class Create extends Action
->setStatusCode(SwooleResponse::STATUS_CODE_CREATED)
->dynamic($transaction, UtopiaResponse::MODEL_TRANSACTION);
}
}
}

View file

@ -73,4 +73,4 @@ class Delete extends Action
$response->noContent();
}
}
}

View file

@ -66,4 +66,4 @@ class Get extends Action
->setStatusCode(SwooleResponse::STATUS_CODE_OK)
->dynamic($transaction, UtopiaResponse::MODEL_TRANSACTION);
}
}
}

View file

@ -114,4 +114,4 @@ class Create extends Action
->setStatusCode(SwooleResponse::STATUS_CODE_CREATED)
->dynamic($transaction, UtopiaResponse::MODEL_TRANSACTION);
}
}
}

View file

@ -15,7 +15,6 @@ use Utopia\Database\Document;
use Utopia\Database\Exception\Conflict as ConflictException;
use Utopia\Database\Exception\Duplicate as DuplicateException;
use Utopia\Database\Exception\Transaction as TransactionException;
use Utopia\Database\Helpers\ID;
use Utopia\Database\Query;
use Utopia\Database\Validator\UID;
use Utopia\Swoole\Response as SwooleResponse;
@ -127,11 +126,11 @@ class Update extends Action
$document = new Document($data);
$dbForProject->createOrUpdateDocuments($collectionId, [$document]);
break;
case 'delete':
$dbForProject->deleteDocument($collectionId, $documentId);
break;
case 'increment':
$dbForProject->increaseDocumentAttribute(
collection: $collectionId,
@ -141,7 +140,7 @@ class Update extends Action
max: $data['max'] ?? null
);
break;
case 'decrement':
$dbForProject->decreaseDocumentAttribute(
collection: $collectionId,
@ -175,7 +174,7 @@ class Update extends Action
}
$dbForProject->createOrUpdateDocuments($collectionId, $documents);
break;
case 'bulkDelete':
$dbForProject->deleteDocuments(
$collectionId,
@ -224,4 +223,4 @@ class Update extends Action
->setStatusCode(SwooleResponse::STATUS_CODE_OK)
->dynamic($transaction, UtopiaResponse::MODEL_TRANSACTION);
}
}
}

View file

@ -70,4 +70,4 @@ class XList extends Action
'total' => $dbForProject->count('transactions', $queries),
]), UtopiaResponse::MODEL_TRANSACTION_LIST);
}
}
}