Files
animethemes-server/app/GraphQL/Mutations/List/ExternalProfileMutator.php
T
2025-05-12 02:07:27 -03:00

43 lines
912 B
PHP

<?php
declare(strict_types=1);
namespace App\GraphQL\Mutations\List;
use App\Models\List\ExternalProfile;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Arr;
/**
* Class ExternalProfileMutator.
*/
class ExternalProfileMutator
{
final public const ROUTE_SLUG = 'id';
/**
* Start a new sync job.
*
* @param null $_
* @param array $args
* @return JsonResponse
*/
public function sync($_, array $args): JsonResponse
{
/** @var ExternalProfile $profile */
$profile = Arr::pull($args, self::ROUTE_SLUG);
if (!$profile->canBeSynced()) {
return new JsonResponse([
'error' => 'This external profile cannot be synced at the moment.'
], 403);
}
$profile->startSyncJob();
return new JsonResponse([
'message' => 'Job dispatched.'
], 201);
}
}