Skip to content

Commit

Permalink
Fixed schema, type coercions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitrijs Voronovs committed Oct 1, 2019
1 parent 9621510 commit 33f30cf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
10 changes: 8 additions & 2 deletions src/Model/Customer/CheckCustomerAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ public function __construct(
* @throws GraphQlNoSuchEntityException
* @throws GraphQlAuthenticationException
*/
public function execute(?int $customerId, ?int $customerType): void
public function execute(?int $customerId, ?int $customerType): bool
{
if ($this->isCustomerGuest($customerId, $customerType)) {
throw new GraphQlAuthorizationException(__('The current customer isn\'t authorized.'));
return false;
}

try {
Expand All @@ -81,16 +82,21 @@ public function execute(?int $customerId, ?int $customerType): void
__('Customer with id "%customer_id" does not exist.', ['customer_id' => $customerId]),
$e
);
return false;
}

if ($this->authentication->isLocked($customerId)) {
throw new GraphQlAuthenticationException(__('The account is locked.'));
return false;
}

$confirmationStatus = $this->accountManagement->getConfirmationStatus($customerId);
if ($confirmationStatus === AccountManagementInterface::ACCOUNT_CONFIRMATION_REQUIRED) {
throw new GraphQlAuthenticationException(__("This account isn't confirmed. Verify and try again."));
return false;
}

return true;
}

/**
Expand All @@ -105,6 +111,6 @@ private function isCustomerGuest(?int $customerId, ?int $customerType): bool
if ($customerId === null || $customerType === null) {
return true;
}
return (int)$customerId === 0 || (int)$customerType === UserContextInterface::USER_TYPE_GUEST;
return $customerId == 0 || $customerType == UserContextInterface::USER_TYPE_GUEST;
}
}
10 changes: 3 additions & 7 deletions src/Model/Resolver/ExpandedOrderResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ExpandedOrderResolver implements ResolverInterface
/**
* @var OrderRepository
*/
protected $orderRepository;
private $orderRepository;

/**
* @param CollectionFactoryInterface $collectionFactory
Expand All @@ -69,10 +69,6 @@ public function resolve(
array $value = null,
array $args = null
) {
if (!isset($args['id'])) {
throw new GraphQlInputException(__('Please specify valid order ID.'));
}

$itemsData = [];
$trackNumbers = [];

Expand All @@ -86,8 +82,8 @@ public function resolve(
throw new GraphQlNoSuchEntityException(__('Customer ID is invalid.'));
}

foreach ($order->getAllVisibleItems() as $_item) {
$itemsData[] = $_item;
foreach ($order->getAllVisibleItems() as $item) {
$itemsData[] = $item;
}

$tracksCollection = $order->getTracksCollection();
Expand Down
2 changes: 1 addition & 1 deletion src/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type Mutation {
type Query {
getCartForCustomer(guestCartId: String): QuoteData @resolver(class: "\\ScandiPWA\\QuoteGraphQl\\Model\\Resolver\\GetCartForCustomer")
getOrderList: OrderList @resolver(class: "\\ScandiPWA\\QuoteGraphQl\\Model\\Resolver\\OrderListResolver") @doc(description: "The Sales Order query returns information about a Sales order")
getOrderById(id: Int): Order @resolver(class: "\\ScandiPWA\\QuoteGraphQl\\Model\\Resolver\\ExpandedOrderResolver") @doc(description: "The Sales Order query returns information about a Sales order")
getOrderById(id: Int!): Order @resolver(class: "\\ScandiPWA\\QuoteGraphQl\\Model\\Resolver\\ExpandedOrderResolver") @doc(description: "The Sales Order query returns information about a Sales order")
}

input CartItemInput {
Expand Down

0 comments on commit 33f30cf

Please sign in to comment.