From a92d526125fb2dcec1d62e5eccee4cf24a8aec64 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 18 Jan 2024 01:50:09 +1300 Subject: [PATCH] Remove docs label, fix throw on no provider --- app/controllers/api/account.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/app/controllers/api/account.php b/app/controllers/api/account.php index 56a9073724..40ccbff1d9 100644 --- a/app/controllers/api/account.php +++ b/app/controllers/api/account.php @@ -1756,10 +1756,9 @@ App::post('/v1/account/targets/push') ->label('sdk.response.code', Response::STATUS_CODE_CREATED) ->label('sdk.response.type', Response::CONTENT_TYPE_JSON) ->label('sdk.response.model', Response::MODEL_TARGET) - ->label('docs', false) ->param('targetId', '', new CustomId(), 'Target ID. Choose a custom ID or generate a random ID with `ID.unique()`. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can\'t start with a special char. Max length is 36 chars.') - ->param('providerId', '', new UID(), 'Provider ID. Message will be sent to this target from the specified provider ID. If no provider ID is set the first setup provider will be used.') ->param('identifier', '', new Text(Database::LENGTH_KEY), 'The target identifier (token, email, phone etc.)') + ->param('providerId', '', new UID(), 'Provider ID. Message will be sent to this target from the specified provider ID. If no provider ID is set the first setup provider will be used.', true) ->inject('queueForEvents') ->inject('user') ->inject('request') @@ -1770,10 +1769,6 @@ App::post('/v1/account/targets/push') $provider = Authorization::skip(fn () => $dbForProject->getDocument('providers', $providerId)); - if ($provider->isEmpty()) { - throw new Exception(Exception::PROVIDER_NOT_FOUND); - } - if ($user->isEmpty()) { throw new Exception(Exception::USER_NOT_FOUND); } @@ -1796,8 +1791,8 @@ App::post('/v1/account/targets/push') Permission::read(Role::user($user->getId())), Permission::update(Role::user($user->getId())), ], - 'providerId' => $providerId ?? null, - 'providerInternalId' => $provider->getInternalId() ?? null, + 'providerId' => empty($providerId) ? $providerId : null, + 'providerInternalId' => empty($providerId) ? $provider->getInternalId() : null, 'providerType' => MESSAGE_TYPE_PUSH, 'userId' => $user->getId(), 'userInternalId' => $user->getInternalId(),