Version 5.0.0 beta 1
This commit is contained in:
1 parent
25ddeb65d6
commit
15c7beabc5
6736 files changed
+627902
-497943
No files matched your search
@@ -10,30 +10,38 @@
|
||||
*/
|
||||
|
||||
namespace IPS\calendar\api\GraphQL\Mutations;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\SafeException;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
use IPS\calendar\api\GraphQL\Types\EventType;
|
||||
use IPS\calendar\Calendar;
|
||||
use IPS\calendar\Event;
|
||||
use IPS\Content\Api\GraphQL\ItemMutator;
|
||||
use IPS\Content\Item;
|
||||
use IPS\Member;
|
||||
use OutOfRangeException;
|
||||
use function defined;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
header( ( $_SERVER['SERVER_PROTOCOL'] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create Event mutation for GraphQL API
|
||||
*/
|
||||
class _CreateEvent extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
class CreateEvent extends ItemMutator
|
||||
{
|
||||
/**
|
||||
* Class
|
||||
*/
|
||||
protected $class = \IPS\calendar\Event::class;
|
||||
protected string $class = Event::class;
|
||||
|
||||
/*
|
||||
* @brief Query description
|
||||
*/
|
||||
public static $description = "Create a new calendar event";
|
||||
public static string $description = "Create a new calendar event";
|
||||
|
||||
/*
|
||||
* Mutation arguments
|
||||
@@ -48,7 +56,7 @@ class _CreateEvent extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
/**
|
||||
* Return the mutation return type
|
||||
*/
|
||||
public function type()
|
||||
public function type(): EventType
|
||||
{
|
||||
return \IPS\calendar\api\GraphQL\TypeRegistry::event();
|
||||
}
|
||||
@@ -56,42 +64,43 @@ class _CreateEvent extends \IPS\Content\Api\GraphQL\ItemMutator
|
||||
/**
|
||||
* Resolves this mutation
|
||||
*
|
||||
* @param mixed Value passed into this resolver
|
||||
* @param array Arguments
|
||||
* @param array Context values
|
||||
* @return \IPS\calendar\Event
|
||||
* @param mixed $val Value passed into this resolver
|
||||
* @param array $args Arguments
|
||||
* @param array $context Context values
|
||||
* @param array $info
|
||||
* @return Event
|
||||
*/
|
||||
public function resolve($val, $args, $context, $info)
|
||||
public function resolve( mixed $val, array $args, array $context, array $info): Item
|
||||
{
|
||||
/* Get calendar */
|
||||
try
|
||||
{
|
||||
$calendar = \IPS\calendar\Calendar::loadAndCheckPerms( $args['calendarID'] );
|
||||
$calendar = Calendar::loadAndCheckPerms( $args['calendarID'] );
|
||||
}
|
||||
catch ( \OutOfRangeException $e )
|
||||
catch ( OutOfRangeException $e )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_CALENDAR', '1L296/6_graphql', 400 );
|
||||
throw new SafeException( 'NO_CALENDAR', '1L296/6_graphql', 400 );
|
||||
}
|
||||
|
||||
/* Check permission */
|
||||
if ( !$calendar->can( 'add', \IPS\Member::loggedIn() ) )
|
||||
if ( !$calendar->can( 'add', Member::loggedIn() ) )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_PERMISSION', '1L296/7_graphql', 403 );
|
||||
throw new SafeException( 'NO_PERMISSION', '1L296/7_graphql', 403 );
|
||||
}
|
||||
|
||||
/* Check we have a title and a post */
|
||||
if ( !$args['title'] )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_TITLE', '1L296/8_graphql', 400 );
|
||||
throw new SafeException( 'NO_TITLE', '1L296/8_graphql', 400 );
|
||||
}
|
||||
if ( !$args['content'] )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'NO_POST', '1L296/9_grapqhl', 400 );
|
||||
throw new SafeException( 'NO_POST', '1L296/9_grapqhl', 400 );
|
||||
}
|
||||
|
||||
if ( !$args['start'] )
|
||||
{
|
||||
throw new \IPS\Api\GraphQL\SafeException( 'INVALID_START', '1L296/A_grapqhl', 400 );
|
||||
throw new SafeException( 'INVALID_START', '1L296/A_grapqhl', 400 );
|
||||
}
|
||||
|
||||
return $this->_create( $args, $calendar, $args['postKey'] ?? NULL );
|
||||
|
||||
Reference in new issue
Block a user