Skip to content

Instantly share code, notes, and snippets.

@rodrigooler
Created March 22, 2018 17:40
Show Gist options
  • Save rodrigooler/1425a73d531d456fb7bac3b463ea95f2 to your computer and use it in GitHub Desktop.
Save rodrigooler/1425a73d531d456fb7bac3b463ea95f2 to your computer and use it in GitHub Desktop.
def find_coupons(
_parent,
%{
city: city,
company_category_id: company_category_id,
coupon_category_id: coupon_category_id
},
_resolution
) do
{:ok,
%{
coupons:
Repo.all(
from(
coupon in Coupon,
join: company in Company,
join: address in Address,
where:
coupon.active == true and address.city == type(^city, :string) and
company.company_category_id == type(^company_category_id, :string) and
coupon.coupon_category == type(^coupon_category_id, :string)
)
)
}}
end
def find_coupons(_parent, %{city: city, company_category_id: company_category_id}, _resolution) do
{:ok,
%{
coupons:
Repo.all(
from(
coupon in Coupon,
join: company in Company,
join: address in Address,
where:
coupon.active == true and address.city == type(^city, :string) and
company.company_category_id == type(^company_category_id, :string)
)
)
}}
end
def find_coupons(_parent, %{city: city}, _resolution) do
{:ok,
%{
coupons:
Repo.all(
from(
coupon in Coupon,
join: company in Company,
join: address in Address,
where: coupon.active == true and address.city == type(^city, :string)
)
)
}}
end
def find_coupons(_parent, %{}, _resolution) do
{:ok, %{coupons: []}}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment