Created
March 22, 2018 17:40
-
-
Save rodrigooler/1425a73d531d456fb7bac3b463ea95f2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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