Removed isDev global param
This commit is contained in:
parent
65c08825a5
commit
86e9d03e07
1 changed files with 15 additions and 17 deletions
|
@ -27,8 +27,6 @@ use GeoIp2\Database\Reader;
|
||||||
|
|
||||||
include_once __DIR__ . '/../shared/api.php';
|
include_once __DIR__ . '/../shared/api.php';
|
||||||
|
|
||||||
$isDev = (App::MODE_TYPE_PRODUCTION !== $utopia->getMode());
|
|
||||||
|
|
||||||
$utopia->post('/v1/database/collections')
|
$utopia->post('/v1/database/collections')
|
||||||
->desc('Create Collection')
|
->desc('Create Collection')
|
||||||
->label('webhook', 'database.collections.create')
|
->label('webhook', 'database.collections.create')
|
||||||
|
@ -180,7 +178,7 @@ $utopia->get('/v1/database/collections/:collectionId')
|
||||||
// ->param('collectionId', '', function () { return new UID(); }, 'Collection unique ID.')
|
// ->param('collectionId', '', function () { return new UID(); }, 'Collection unique ID.')
|
||||||
// ->action(
|
// ->action(
|
||||||
// function ($collectionId) use ($response, $register, $projectDB, $project) {
|
// function ($collectionId) use ($response, $register, $projectDB, $project) {
|
||||||
// $collection = $projectDB->getDocument($collectionId);
|
// $collection = $projectDB->getDocument($collectionId, false);
|
||||||
|
|
||||||
// if (empty($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
// if (empty($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
||||||
// throw new Exception('Collection not found', 404);
|
// throw new Exception('Collection not found', 404);
|
||||||
|
@ -370,7 +368,7 @@ $utopia->post('/v1/database/collections/:collectionId/documents')
|
||||||
throw new Exception('$id is not allowed for creating new documents, try update instead', 400);
|
throw new Exception('$id is not allowed for creating new documents, try update instead', 400);
|
||||||
}
|
}
|
||||||
|
|
||||||
$collection = $projectDB->getDocument($collectionId/*, $isDev*/);
|
$collection = $projectDB->getDocument($collectionId, false);
|
||||||
|
|
||||||
if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
||||||
throw new Exception('Collection not found', 404);
|
throw new Exception('Collection not found', 404);
|
||||||
|
@ -385,7 +383,7 @@ $utopia->post('/v1/database/collections/:collectionId/documents')
|
||||||
// Read parent document + validate not 404 + validate read / write permission like patch method
|
// Read parent document + validate not 404 + validate read / write permission like patch method
|
||||||
// Add payload to parent document property
|
// Add payload to parent document property
|
||||||
if ((!empty($parentDocument)) && (!empty($parentProperty))) {
|
if ((!empty($parentDocument)) && (!empty($parentProperty))) {
|
||||||
$parentDocument = $projectDB->getDocument($parentDocument);
|
$parentDocument = $projectDB->getDocument($parentDocument, false);
|
||||||
|
|
||||||
if (empty($parentDocument->getArrayCopy())) { // Check empty
|
if (empty($parentDocument->getArrayCopy())) { // Check empty
|
||||||
throw new Exception('No parent document found', 404);
|
throw new Exception('No parent document found', 404);
|
||||||
|
@ -480,8 +478,8 @@ $utopia->get('/v1/database/collections/:collectionId/documents')
|
||||||
->param('first', 0, function () { return new Range(0, 1); }, 'Return only the first document. Pass 1 for true or 0 for false. The default value is 0.', true)
|
->param('first', 0, function () { return new Range(0, 1); }, 'Return only the first document. Pass 1 for true or 0 for false. The default value is 0.', true)
|
||||||
->param('last', 0, function () { return new Range(0, 1); }, 'Return only the last document. Pass 1 for true or 0 for false. The default value is 0.', true)
|
->param('last', 0, function () { return new Range(0, 1); }, 'Return only the last document. Pass 1 for true or 0 for false. The default value is 0.', true)
|
||||||
->action(
|
->action(
|
||||||
function ($collectionId, $filters, $offset, $limit, $orderField, $orderType, $orderCast, $search, $first, $last) use ($response, $projectDB, $isDev) {
|
function ($collectionId, $filters, $offset, $limit, $orderField, $orderType, $orderCast, $search, $first, $last) use ($response, $projectDB, $utopia) {
|
||||||
$collection = $projectDB->getDocument($collectionId, $isDev);
|
$collection = $projectDB->getDocument($collectionId, false);
|
||||||
|
|
||||||
if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
if (\is_null($collection->getId()) || Database::SYSTEM_COLLECTION_COLLECTIONS != $collection->getCollection()) {
|
||||||
throw new Exception('Collection not found', 404);
|
throw new Exception('Collection not found', 404);
|
||||||
|
@ -504,7 +502,7 @@ $utopia->get('/v1/database/collections/:collectionId/documents')
|
||||||
if ($first || $last) {
|
if ($first || $last) {
|
||||||
$response->json((!empty($list) ? $list->getArrayCopy() : []));
|
$response->json((!empty($list) ? $list->getArrayCopy() : []));
|
||||||
} else {
|
} else {
|
||||||
if ($isDev) {
|
if ($utopia->isDevelopment()) {
|
||||||
$collection
|
$collection
|
||||||
->setAttribute('debug', $projectDB->getDebug())
|
->setAttribute('debug', $projectDB->getDebug())
|
||||||
->setAttribute('limit', $limit)
|
->setAttribute('limit', $limit)
|
||||||
|
@ -539,9 +537,9 @@ $utopia->get('/v1/database/collections/:collectionId/documents/:documentId')
|
||||||
->param('collectionId', null, function () { return new UID(); }, 'Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection).')
|
->param('collectionId', null, function () { return new UID(); }, 'Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection).')
|
||||||
->param('documentId', null, function () { return new UID(); }, 'Document unique ID.')
|
->param('documentId', null, function () { return new UID(); }, 'Document unique ID.')
|
||||||
->action(
|
->action(
|
||||||
function ($collectionId, $documentId) use ($response, $request, $projectDB, $isDev) {
|
function ($collectionId, $documentId) use ($response, $request, $projectDB) {
|
||||||
$document = $projectDB->getDocument($documentId, $isDev);
|
$document = $projectDB->getDocument($documentId, false);
|
||||||
$collection = $projectDB->getDocument($collectionId, $isDev);
|
$collection = $projectDB->getDocument($collectionId, false);
|
||||||
|
|
||||||
if (empty($document->getArrayCopy()) || $document->getCollection() != $collection->getId()) { // Check empty
|
if (empty($document->getArrayCopy()) || $document->getCollection() != $collection->getId()) { // Check empty
|
||||||
throw new Exception('No document found', 404);
|
throw new Exception('No document found', 404);
|
||||||
|
@ -588,9 +586,9 @@ $utopia->patch('/v1/database/collections/:collectionId/documents/:documentId')
|
||||||
->param('read', [], function () { return new ArrayList(new Text(64)); }, 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
|
->param('read', [], function () { return new ArrayList(new Text(64)); }, 'An array of strings with read permissions. By default no user is granted with any read permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
|
||||||
->param('write', [], function () { return new ArrayList(new Text(64)); }, 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
|
->param('write', [], function () { return new ArrayList(new Text(64)); }, 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
|
||||||
->action(
|
->action(
|
||||||
function ($collectionId, $documentId, $data, $read, $write) use ($response, $projectDB, &$output, $webhook, $audit, $isDev) {
|
function ($collectionId, $documentId, $data, $read, $write) use ($response, $projectDB, $webhook, $audit) {
|
||||||
$collection = $projectDB->getDocument($collectionId/*, $isDev*/);
|
$collection = $projectDB->getDocument($collectionId, false);
|
||||||
$document = $projectDB->getDocument($documentId, $isDev);
|
$document = $projectDB->getDocument($documentId, false);
|
||||||
|
|
||||||
$data = (\is_string($data)) ? \json_decode($data, true) : $data; // Cast to JSON array
|
$data = (\is_string($data)) ? \json_decode($data, true) : $data; // Cast to JSON array
|
||||||
|
|
||||||
|
@ -664,9 +662,9 @@ $utopia->delete('/v1/database/collections/:collectionId/documents/:documentId')
|
||||||
->param('collectionId', null, function () { return new UID(); }, 'Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection).')
|
->param('collectionId', null, function () { return new UID(); }, 'Collection unique ID. You can create a new collection with validation rules using the Database service [server integration](/docs/server/database#createCollection).')
|
||||||
->param('documentId', null, function () { return new UID(); }, 'Document unique ID.')
|
->param('documentId', null, function () { return new UID(); }, 'Document unique ID.')
|
||||||
->action(
|
->action(
|
||||||
function ($collectionId, $documentId) use ($response, $projectDB, $audit, $webhook, $isDev) {
|
function ($collectionId, $documentId) use ($response, $projectDB, $audit, $webhook) {
|
||||||
$collection = $projectDB->getDocument($collectionId, $isDev);
|
$collection = $projectDB->getDocument($collectionId, false);
|
||||||
$document = $projectDB->getDocument($documentId, $isDev);
|
$document = $projectDB->getDocument($documentId, false);
|
||||||
|
|
||||||
if (empty($document->getArrayCopy()) || $document->getCollection() != $collectionId) { // Check empty
|
if (empty($document->getArrayCopy()) || $document->getCollection() != $collectionId) { // Check empty
|
||||||
throw new Exception('No document found', 404);
|
throw new Exception('No document found', 404);
|
||||||
|
|
Loading…
Reference in a new issue