|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Landofcoder |
| 5 | + * |
| 6 | + * NOTICE OF LICENSE |
| 7 | + * |
| 8 | + * This source file is subject to the Landofcoder.com license that is |
| 9 | + * available through the world-wide-web at this URL: |
| 10 | + * https://landofcoder.com/terms |
| 11 | + * |
| 12 | + * DISCLAIMER |
| 13 | + * |
| 14 | + * Do not edit or add to this file if you wish to upgrade this extension to newer |
| 15 | + * version in the future. |
| 16 | + * |
| 17 | + * @category Landofcoder |
| 18 | + * @package Lof_SellerMessageGraphQl |
| 19 | + * @copyright Copyright (c) 2021 Landofcoder (https://www.landofcoder.com/) |
| 20 | + * @license https://landofcoder.com/terms |
| 21 | + */ |
| 22 | + |
| 23 | +declare(strict_types=1); |
| 24 | + |
| 25 | +namespace Lof\MarketplaceGraphQl\Model\Resolver\Customer; |
| 26 | + |
| 27 | +use Magento\Framework\GraphQl\Config\Element\Field; |
| 28 | +use Magento\Framework\GraphQl\Query\ResolverInterface; |
| 29 | +use Magento\Framework\GraphQl\Schema\Type\ResolveInfo; |
| 30 | +use Magento\Framework\GraphQl\Exception\GraphQlInputException; |
| 31 | +use Magento\Framework\GraphQl\Exception\GraphQlAuthorizationException; |
| 32 | +use Lof\MarketPlace\Api\CustomerMessageRepositoryInterface; |
| 33 | + |
| 34 | +class DeleteMessage implements ResolverInterface |
| 35 | +{ |
| 36 | + /** |
| 37 | + * @var CustomerMessageRepositoryInterface |
| 38 | + */ |
| 39 | + private $customerMessageRepository; |
| 40 | + |
| 41 | + /** |
| 42 | + * @param CustomerMessageRepositoryInterface $customerMessageRepository |
| 43 | + */ |
| 44 | + public function __construct( |
| 45 | + CustomerMessageRepositoryInterface $customerMessageRepository |
| 46 | + ) { |
| 47 | + $this->customerMessageRepository = $customerMessageRepository; |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @inheritdoc |
| 52 | + */ |
| 53 | + public function resolve( |
| 54 | + Field $field, |
| 55 | + $context, |
| 56 | + ResolveInfo $info, |
| 57 | + array $value = null, |
| 58 | + array $args = null |
| 59 | + ) { |
| 60 | + if (!$context->getExtensionAttributes()->getIsCustomer()) { |
| 61 | + throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.')); |
| 62 | + } |
| 63 | + if (!($args['message_id']) || !isset($args['message_id'])) { |
| 64 | + throw new GraphQlInputException(__('"message_id" value should be specified')); |
| 65 | + } |
| 66 | + $data = $this->customerMessageRepository->deleteMessage($context->getUserId(), (int)$args['message_id']); |
| 67 | + |
| 68 | + return [ |
| 69 | + "code" => $data ? 0 : 1, |
| 70 | + "message" => $data ? "The message was delete successfully!" : "Error when delete the message." |
| 71 | + ]; |
| 72 | + } |
| 73 | +} |
0 commit comments