Fix subscriber api. Closes #2112
This commit is contained in:
@@ -44,17 +44,17 @@ class SubscribeSubscriberCommandHandler
|
|||||||
|
|
||||||
// Decide what to subscribe the subscriber to.
|
// Decide what to subscribe the subscriber to.
|
||||||
if ($subscriptions = $command->subscriptions) {
|
if ($subscriptions = $command->subscriptions) {
|
||||||
$subscriptions = Component::whereIn('id', $subscriptions);
|
$components = Component::whereIn('id', $subscriptions)->get();
|
||||||
} else {
|
} else {
|
||||||
$subscriptions = Component::all();
|
$components = Component::all();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($subscriptions as $component) {
|
$components->map(function ($component) use ($subscriber) {
|
||||||
Subscription::create([
|
Subscription::create([
|
||||||
'subscriber_id' => $subscriber->id,
|
'subscriber_id' => $subscriber->id,
|
||||||
'component_id' => $component->id,
|
'component_id' => $component->id,
|
||||||
]);
|
]);
|
||||||
}
|
});
|
||||||
|
|
||||||
if ($command->verified) {
|
if ($command->verified) {
|
||||||
dispatch(new VerifySubscriberCommand($subscriber));
|
dispatch(new VerifySubscriberCommand($subscriber));
|
||||||
@@ -62,6 +62,8 @@ class SubscribeSubscriberCommandHandler
|
|||||||
event(new SubscriberHasSubscribedEvent($subscriber));
|
event(new SubscriberHasSubscribedEvent($subscriber));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$subscriber->load('subscriptions');
|
||||||
|
|
||||||
return $subscriber;
|
return $subscriber;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ class SubscriberTest extends AbstractApiTestCase
|
|||||||
$this->assertResponseOk();
|
$this->assertResponseOk();
|
||||||
$this->seeHeader('Content-Type', 'application/json');
|
$this->seeHeader('Content-Type', 'application/json');
|
||||||
$this->seeJson(['email' => 'support@alt-three.com']);
|
$this->seeJson(['email' => 'support@alt-three.com']);
|
||||||
|
$this->seeJsonStructure(['data' => ['subscriptions' => []]]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testDeleteSubscriber()
|
public function testDeleteSubscriber()
|
||||||
|
|||||||
Reference in New Issue
Block a user