Skip to content

Commit

Permalink
filter by slug
Browse files Browse the repository at this point in the history
  • Loading branch information
kaioken committed Dec 21, 2024
1 parent 53cbd55 commit bda6a79
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
24 changes: 17 additions & 7 deletions app/GraphQL/Social/Builders/Messages/MessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use GraphQL\Type\Definition\ResolveInfo;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
use InvalidArgumentException;
use Kanvas\Apps\Models\Apps;
use Kanvas\Social\Enums\AppEnum;
use Kanvas\Social\Enums\InteractionEnum;
Expand Down Expand Up @@ -43,6 +44,7 @@ public function getAll(
//Check in this condition if the message is an item and if then check if it has been bought by the current user via status=completed on Order
if (! $user->isAppOwner()) {
$messages = Message::fromCompany($user->getCurrentCompany());

return $messages;
}

Expand Down Expand Up @@ -78,13 +80,21 @@ public function getChannelMessages(
GraphQLContext $context,
ResolveInfo $resolveInfo
): Builder {
return Message::fromApp()->whereHas('channels', function ($query) use ($args) {
$query->where('channels.uuid', $args['channel_uuid']);
})
->when(! auth()->user()->isAdmin(), function ($query) {
$query->where('companies_id', auth()->user()->currentCompanyId());
})
->select('messages.*');
if (isset($args['channel_uuid']) && isset($args['channel_slug'])) {
throw new InvalidArgumentException('Provide only one of channel_uuid or channel_slug, not both.');
}

return Message::fromApp()
->whereHas('channels', function ($query) use ($args) {
if (isset($args['channel_uuid'])) {
$query->where('channels.uuid', $args['channel_uuid']);
} elseif (isset($args['channel_slug'])) {
$query->where('channels.slug', $args['channel_slug']);
}
})
->when(! auth()->user()->isAdmin(), function ($query) {
$query->where('companies_id', auth()->user()->currentCompanyId());
});
}

public function getGroupByDate(
Expand Down
3 changes: 2 additions & 1 deletion graphql/schemas/Social/message.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,8 @@ extend type Query @guard {
)

channelMessages(
channel_uuid: String!
channel_uuid: String
channel_slug: String
where: _
@whereConditions(
columns: [
Expand Down

0 comments on commit bda6a79

Please sign in to comment.