Merge branch 'feat-database-indexing' of https://github.com/appwrite/appwrite into feat-database-indexing
This commit is contained in:
commit
8a12fdc2b2
|
@ -4,6 +4,7 @@ namespace Appwrite\Utopia\Response\Model;
|
|||
|
||||
use Appwrite\Utopia\Response;
|
||||
use Appwrite\Utopia\Response\Model;
|
||||
use Utopia\Database\Document;
|
||||
|
||||
class User extends Model
|
||||
{
|
||||
|
@ -61,6 +62,24 @@ class User extends Model
|
|||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Collection
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function filter(Document $document): Document
|
||||
{
|
||||
$prefs = $document->getAttribute('prefs');
|
||||
if($prefs instanceof Document) {
|
||||
$prefs = $prefs->getArrayCopy();
|
||||
}
|
||||
|
||||
if(is_array($prefs) && empty($prefs)) {
|
||||
$document->setAttribute('prefs', new stdClass);
|
||||
}
|
||||
return $document;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Name
|
||||
*
|
||||
|
|
|
@ -151,10 +151,11 @@ class Client
|
|||
* @param string $path
|
||||
* @param array $params
|
||||
* @param array $headers
|
||||
* @param bool $decode
|
||||
* @return array|string
|
||||
* @throws Exception
|
||||
*/
|
||||
public function call(string $method, string $path = '', array $headers = [], array $params = [])
|
||||
public function call(string $method, string $path = '', array $headers = [], array $params = [], bool $decode = true)
|
||||
{
|
||||
$headers = array_merge($this->headers, $headers);
|
||||
$ch = curl_init($this->endpoint . $path . (($method == self::METHOD_GET && !empty($params)) ? '?' . http_build_query($params) : ''));
|
||||
|
@ -216,17 +217,19 @@ class Client
|
|||
$responseType = $responseHeaders['content-type'] ?? '';
|
||||
$responseStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
||||
|
||||
switch (substr($responseType, 0, strpos($responseType, ';'))) {
|
||||
case 'application/json':
|
||||
$json = json_decode($responseBody, true);
|
||||
|
||||
if ($json === null) {
|
||||
throw new Exception('Failed to parse response: '.$responseBody);
|
||||
}
|
||||
|
||||
$responseBody = $json;
|
||||
$json = null;
|
||||
break;
|
||||
if($decode) {
|
||||
switch (substr($responseType, 0, strpos($responseType, ';'))) {
|
||||
case 'application/json':
|
||||
$json = json_decode($responseBody, true);
|
||||
|
||||
if ($json === null) {
|
||||
throw new Exception('Failed to parse response: '.$responseBody);
|
||||
}
|
||||
|
||||
$responseBody = $json;
|
||||
$json = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((curl_errno($ch)/* || 200 != $responseStatus*/)) {
|
||||
|
|
|
@ -20,13 +20,20 @@ trait UsersBase
|
|||
'email' => 'cristiano.ronaldo@manchester-united.co.uk',
|
||||
'password' => 'password',
|
||||
'name' => 'Cristiano Ronaldo',
|
||||
]);
|
||||
], false);
|
||||
|
||||
// Test empty prefs is object not array
|
||||
$bodyString = $user['body'];
|
||||
$prefs = substr($bodyString, strpos($bodyString, '"prefs":')+8,2);
|
||||
$this->assertEquals('{}', $prefs);
|
||||
|
||||
$body = json_decode($bodyString, true);
|
||||
|
||||
$this->assertEquals($user['headers']['status-code'], 201);
|
||||
$this->assertEquals($user['body']['name'], 'Cristiano Ronaldo');
|
||||
$this->assertEquals($user['body']['email'], 'cristiano.ronaldo@manchester-united.co.uk');
|
||||
$this->assertEquals($user['body']['status'], true);
|
||||
$this->assertGreaterThan(0, $user['body']['registration']);
|
||||
$this->assertEquals($body['name'], 'Cristiano Ronaldo');
|
||||
$this->assertEquals($body['email'], 'cristiano.ronaldo@manchester-united.co.uk');
|
||||
$this->assertEquals($body['status'], true);
|
||||
$this->assertGreaterThan(0, $body['registration']);
|
||||
|
||||
/**
|
||||
* Test Create with Custom ID for SUCCESS
|
||||
|
@ -48,7 +55,7 @@ trait UsersBase
|
|||
$this->assertEquals(true, $res['body']['status']);
|
||||
$this->assertGreaterThan(0, $res['body']['registration']);
|
||||
|
||||
return ['userId' => $user['body']['$id']];
|
||||
return ['userId' => $body['$id']];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue