Skip to content

Instantly share code, notes, and snippets.

@ijunaid8989
Created November 21, 2024 06:28
Show Gist options
  • Save ijunaid8989/a31d83856bbfdef6d878d30085580ff2 to your computer and use it in GitHub Desktop.
Save ijunaid8989/a31d83856bbfdef6d878d30085580ff2 to your computer and use it in GitHub Desktop.
def list_plan_types_paginated(
search,
order_by \\ "id",
direction \\ "desc",
limit \\ 50,
cursor_after \\ nil,
cursor_before \\ nil,
opts \\ []
) do
from(p in PlanType, as: :plan_type)
|> join(:left, [p], cp in assoc(p, :core_provider))
|> join(:left, [p], cpt in assoc(p, :core_product_type))
|> select_merge([p, cp, cpt], %{
core_provider: cp,
core_product_type: cpt
})
|> group_by([p, cp, cpt], [p.id, cp.id, cpt.id])
|> Query.search(search, order_by, direction)
|> Repo.soft_deleted(opts)
|> Repo.paginate(
after: cursor_after,
before: cursor_before,
include_total_count: true,
cursor_fields: [
{String.to_existing_atom(order_by), String.to_existing_atom(direction)}
],
limit: limit
)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment