@@ -6754,42 +6754,67 @@ public function getLimitForIndexes(): int
67546754 * @param array<Query> $queries
67556755 * @return array<Query>
67566756 * @throws QueryException
6757- * @throws Exception
6757+ * @throws \Utopia\Database\Exception
6758+ */
6759+ public static function convertQueries (Document $ collection , array $ queries ): array
6760+ {
6761+ foreach ($ queries as $ index => $ query ) {
6762+ if ($ query ->isNested ()) {
6763+ $ values = self ::convertQueries ($ collection , $ query ->getValues ());
6764+ $ query ->setValues ($ values );
6765+ }
6766+
6767+ $ query = self ::convertQuery ($ collection , $ query );
6768+
6769+ $ queries [$ index ] = $ query ;
6770+ }
6771+
6772+ return $ queries ;
6773+ }
6774+
6775+ /**
6776+ * @param Document $collection
6777+ * @param Query $query
6778+ * @return Query
6779+ * @throws QueryException
6780+ * @throws \Utopia\Database\Exception
67586781 */
6759- public function convertQueries (Document $ collection , array $ queries ): array
6782+ public static function convertQuery (Document $ collection , Query $ query ): Query
67606783 {
6784+ /**
6785+ * @var array<Document> $attributes
6786+ */
67616787 $ attributes = $ collection ->getAttribute ('attributes ' , []);
67626788
67636789 foreach (Database::INTERNAL_ATTRIBUTES as $ attribute ) {
67646790 $ attributes [] = new Document ($ attribute );
67656791 }
67666792
6767- foreach ( $ attributes as $ attribute ) {
6768- foreach ( $ queries as $ query ) {
6769- if ( $ query -> getAttribute () === $ attribute -> getId () ) {
6770- $ query -> setOnArray ( $ attribute ->getAttribute (' array ' , false ));
6771- }
6793+ $ attribute = new Document ();
6794+
6795+ foreach ( $ attributes as $ attr ) {
6796+ if ( $ attr -> getId () === $ query ->getAttribute ()) {
6797+ $ attribute = $ attr ;
67726798 }
6799+ }
6800+
6801+ if (! $ attribute ->isEmpty ()) {
6802+ $ query ->setOnArray ($ attribute ->getAttribute ('array ' , false ));
67736803
67746804 if ($ attribute ->getAttribute ('type ' ) == Database::VAR_DATETIME ) {
6775- foreach ($ queries as $ index => $ query ) {
6776- if ($ query ->getAttribute () === $ attribute ->getId ()) {
6777- $ values = $ query ->getValues ();
6778- foreach ($ values as $ valueIndex => $ value ) {
6779- try {
6780- $ values [$ valueIndex ] = DateTime::setTimezone ($ value );
6781- } catch (\Throwable $ e ) {
6782- throw new QueryException ($ e ->getMessage (), $ e ->getCode (), $ e );
6783- }
6784- }
6785- $ query ->setValues ($ values );
6786- $ queries [$ index ] = $ query ;
6805+ $ values = $ query ->getValues ();
6806+ foreach ($ values as $ valueIndex => $ value ) {
6807+ try {
6808+ $ values [$ valueIndex ] = DateTime::setTimezone ($ value );
6809+ } catch (\Throwable $ e ) {
6810+ throw new QueryException ($ e ->getMessage (), $ e ->getCode (), $ e );
67876811 }
67886812 }
6813+ $ query ->setValues ($ values );
67896814 }
67906815 }
67916816
6792- return $ queries ;
6817+ return $ query ;
67936818 }
67946819
67956820 /**
0 commit comments