From bb2b48193f33b5ff076759a957609b108597acf8 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Wed, 12 Apr 2023 12:06:48 -0700 Subject: [PATCH] Ensure empty team prefs returns as JSON object rather array --- src/Appwrite/Utopia/Response/Model/Team.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Appwrite/Utopia/Response/Model/Team.php b/src/Appwrite/Utopia/Response/Model/Team.php index 62df089438..d080a82bb1 100644 --- a/src/Appwrite/Utopia/Response/Model/Team.php +++ b/src/Appwrite/Utopia/Response/Model/Team.php @@ -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 *