mirror of
https://github.com/appwrite/appwrite
synced 2026-05-22 00:18:25 +00:00
Update V15.php
This commit is contained in:
parent
80e60d9d95
commit
7d3829e35f
1 changed files with 74 additions and 0 deletions
|
|
@ -3,6 +3,7 @@
|
|||
namespace Appwrite\Utopia\Request\Filters;
|
||||
|
||||
use Appwrite\Utopia\Request\Filter;
|
||||
use Utopia\Database\Query;
|
||||
|
||||
class V15 extends Filter
|
||||
{
|
||||
|
|
@ -10,8 +11,81 @@ class V15 extends Filter
|
|||
public function parse(array $content, string $model): array
|
||||
{
|
||||
switch ($model) {
|
||||
// Old Query -> New Query
|
||||
case "account.logs":
|
||||
$content = $this->handleAccountLogs($content);
|
||||
break;
|
||||
case "account.initials":
|
||||
$content = $this->handleInitials($content);
|
||||
}
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
protected function handleAccountLogs($content)
|
||||
{
|
||||
// Translate Old Query System to New Query System
|
||||
|
||||
if (!empty($content['limit'])) {
|
||||
$content['queries'][] = 'Query.limit('.$content['limit'].')';
|
||||
}
|
||||
|
||||
if (!empty($content['offset'])) {
|
||||
$content['queries'][] = 'Query.offset('.$content['offset'].')';
|
||||
}
|
||||
|
||||
unset($content['limit']);
|
||||
unset($content['offset']);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
protected function handleInitials($content)
|
||||
{
|
||||
unset($content[' color']);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
protected function handleQueryTranslation($content) {
|
||||
$content['queries'] = [];
|
||||
|
||||
if (isset($content['limit'])) {
|
||||
$content['queries'][] = Query::limit($content['limit']);
|
||||
}
|
||||
|
||||
if (isset($content['offset'])) {
|
||||
$content['queries'][] = Query::offset($content['offset']);
|
||||
}
|
||||
|
||||
if (isset($content['cursor'])) {
|
||||
$direction = $content['cursorDirection'] ?? 'after';
|
||||
|
||||
if ($direction === 'after') {
|
||||
$content['queries'][] = Query::cursorAfter($content['cursor']);
|
||||
} else {
|
||||
$content['queries'][] = Query::cursorBefore($content['cursor']);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($content['orderAttributes'])) {
|
||||
foreach ($content['orderAttributes'] as $i=>$attribute) {
|
||||
if ($content['orderTypes'][$i] === 'ASC') {
|
||||
$content['queries'][] = Query::orderAsc($attribute);
|
||||
} else if ($content['orderTypes'][$i] === 'DESC') {
|
||||
$content['queries'][] = Query::orderDesc($attribute);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($content['limit']);
|
||||
unset($content['offset']);
|
||||
unset($content['cursor']);
|
||||
unset($content['orderAttributes']);
|
||||
unset($content['orderTypes']);
|
||||
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue