From 98a226dae9ef68abb62ea221b4a3deb8585ddc9d Mon Sep 17 00:00:00 2001 From: Prateek Banga Date: Tue, 25 Jul 2023 00:03:58 +0530 Subject: [PATCH] adds collection and database calls for better error messages --- app/controllers/api/databases.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index cf4a1bd349..f09ed55020 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -1664,6 +1664,19 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/attributes') ->inject('dbForProject') ->action(function (string $databaseId, string $collectionId, array $queries, Response $response, Database $dbForProject) { + $database = Authorization::skip(fn() => $dbForProject->getDocument('databases', $databaseId)); + + if ($database->isEmpty()) { + throw new Exception(Exception::DATABASE_NOT_FOUND); + } + + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + + + if ($collection->isEmpty()) { + throw new Exception(Exception::COLLECTION_NOT_FOUND); + } + $queries = Query::parseQueries($queries); foreach ($queries as $query) { if ($query->getMethod() === Query::TYPE_SELECT) { @@ -2522,6 +2535,18 @@ App::get('/v1/databases/:databaseId/collections/:collectionId/indexes') ->inject('dbForProject') ->action(function (string $databaseId, string $collectionId, array $queries, Response $response, Database $dbForProject) { + $database = Authorization::skip(fn() => $dbForProject->getDocument('databases', $databaseId)); + + if ($database->isEmpty()) { + throw new Exception(Exception::DATABASE_NOT_FOUND); + } + + $collection = $dbForProject->getDocument('database_' . $database->getInternalId(), $collectionId); + + if ($collection->isEmpty()) { + throw new Exception(Exception::COLLECTION_NOT_FOUND); + } + $queries = Query::parseQueries($queries); foreach ($queries as $query) { if ($query->getMethod() === Query::TYPE_SEARCH) {