feat: simplify presence parameter validation by removing Nullable wrapper

This commit is contained in:
ArnabChatterjee20k
2026-05-13 18:25:06 +05:30
parent 20162a69be
commit f818f16ebe
2 changed files with 10 additions and 12 deletions
@@ -24,7 +24,6 @@ use Utopia\Database\Validator\UID;
use Utopia\Platform\Action;
use Utopia\Validator\Boolean;
use Utopia\Validator\JSON;
use Utopia\Validator\Nullable;
use Utopia\Validator\Text;
class Update extends PlatformAction
@@ -93,15 +92,15 @@ class Update extends PlatformAction
),
])
->param('presenceId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Presence unique ID.', false, ['dbForProject'])
->param('userId', null, new Nullable(new UID()), 'User ID.', true)
->param('status', null, new Nullable(new Text(Database::LENGTH_KEY)), 'Presence status.', true)
->param('expiresAt', null, new Nullable(new DatetimeValidator(
->param('userId', null, new UID(), 'User ID.', true)
->param('status', null, new Text(Database::LENGTH_KEY), 'Presence status.', true)
->param('expiresAt', null, new DatetimeValidator(
new \DateTime(),
(new \DateTime())->modify('+30 days'),
requireDateInFuture: true
)), 'Presence expiry datetime.', true)
->param('metadata', null, new Nullable(new JSON()), 'Presence metadata object.', true)
->param('permissions', null, new Nullable(new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE, [Database::PERMISSION_READ, Database::PERMISSION_UPDATE, Database::PERMISSION_DELETE, Database::PERMISSION_WRITE])), 'An array of permissions strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).', true)
), 'Presence expiry datetime.', true)
->param('metadata', null, new JSON(), 'Presence metadata object.', true)
->param('permissions', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE, [Database::PERMISSION_READ, Database::PERMISSION_UPDATE, Database::PERMISSION_DELETE, Database::PERMISSION_WRITE]), 'An array of permissions strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).', true)
->param('purge', false, new Boolean(true), 'When true, purge cached responses used by list presences endpoint.', true)
->inject('response')
->inject('dbForProject')
@@ -24,7 +24,6 @@ use Utopia\Database\Validator\UID;
use Utopia\Platform\Action;
use Utopia\Platform\Scope\HTTP;
use Utopia\Validator\JSON;
use Utopia\Validator\Nullable;
use Utopia\Validator\Text;
class Upsert extends PlatformAction
@@ -93,14 +92,14 @@ class Upsert extends PlatformAction
),
])
->param('presenceId', '', fn (Database $dbForProject) => new UID($dbForProject->getAdapter()->getMaxUIDLength()), 'Presence unique ID.', false, ['dbForProject'])
->param('userId', null, new Nullable(new UID()), 'User ID.', true)
->param('userId', null, new UID(), 'User ID.', true)
->param('status', '', new Text(Database::LENGTH_KEY), 'Presence status.', false)
->param('permissions', null, new Nullable(new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE, [Database::PERMISSION_READ, Database::PERMISSION_UPDATE, Database::PERMISSION_DELETE, Database::PERMISSION_WRITE])), 'An array of permissions strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).', true)
->param('expiresAt', null, new Nullable(new DatetimeValidator(
->param('permissions', null, new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE, [Database::PERMISSION_READ, Database::PERMISSION_UPDATE, Database::PERMISSION_DELETE, Database::PERMISSION_WRITE]), 'An array of permissions strings. By default, only the current user is granted all permissions. [Learn more about permissions](https://appwrite.io/docs/permissions).', true)
->param('expiresAt', null, new DatetimeValidator(
new \DateTime(),
(new \DateTime())->modify('+30 days'),
requireDateInFuture: true
)), 'Presence expiry datetime.', true)
), 'Presence expiry datetime.', true)
->param('metadata', [], new JSON(), 'Presence metadata object.', true)
->inject('response')
->inject('request')