mirror of
https://github.com/AnimeThemes/animethemes-server.git
synced 2026-07-11 01:24:46 +02:00
43 lines
912 B
PHP
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);
|
|
}
|
|
}
|