Ensure empty team prefs returns as JSON object rather array

This commit is contained in:
Steven Nguyen 2023-04-12 12:06:48 -07:00
parent e5fa4883b2
commit bb2b48193f
No known key found for this signature in database

View file

@ -4,6 +4,7 @@ namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
use Utopia\Database\Document;
class Team extends Model
{
@ -49,6 +50,24 @@ class Team extends Model
;
}
/**
* Process Document before returning it to the client
*
* @return Document
*/
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
*