From 8d7b4a9c2d45d737953babc180a957398259a348 Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Fri, 27 Aug 2021 19:42:24 -0400 Subject: [PATCH] Get proper attribute models in collection document --- .../Utopia/Response/Model/Collection.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Response/Model/Collection.php b/src/Appwrite/Utopia/Response/Model/Collection.php index 398bcf770f..f023be261f 100644 --- a/src/Appwrite/Utopia/Response/Model/Collection.php +++ b/src/Appwrite/Utopia/Response/Model/Collection.php @@ -4,6 +4,7 @@ namespace Appwrite\Utopia\Response\Model; use Appwrite\Utopia\Response; use Appwrite\Utopia\Response\Model; +use Utopia\Database\Document; use stdClass; class Collection extends Model @@ -48,7 +49,21 @@ class Collection extends Model 'description' => 'Collection attributes.', 'default' => [], 'example' => new stdClass, - 'array' => true + 'array' => true, + 'getNestedType' => function(Document $attribute) { + return match($attribute->getAttribute('type')) { + self::TYPE_BOOLEAN => Response::MODEL_ATTRIBUTE_BOOLEAN, + self::TYPE_INTEGER => Response::MODEL_ATTRIBUTE_INTEGER, + self::TYPE_FLOAT => Response::MODEL_ATTRIBUTE_FLOAT, + self::TYPE_STRING => match($attribute->getAttribute('format')) { + APP_DATABASE_ATTRIBUTE_EMAIL => Response::MODEL_ATTRIBUTE_EMAIL, + APP_DATABASE_ATTRIBUTE_IP => Response::MODEL_ATTRIBUTE_IP, + APP_DATABASE_ATTRIBUTE_URL => Response::MODEL_ATTRIBUTE_URL, + default => Response::MODEL_ATTRIBUTE_STRING, + }, + default => Response::MODEL_ATTRIBUTE, + }; + }, ]) ->addRule('indexes', [ 'type' => Response::MODEL_INDEX,