backend returns if user is already subscribed

This commit is contained in:
Rimian Perkins
2019-11-28 17:43:03 +11:00
parent c7dcc18923
commit 0fddb5e3b9
6 changed files with 93 additions and 38 deletions
+9 -1
View File
@@ -38,8 +38,16 @@ module DiscoursePatrons
{
id: product[:id],
name: product[:name],
description: product[:metadata][:description]
description: product[:metadata][:description],
subscribed: current_user_products.include?(product[:id])
}
end
def current_user_products
::DiscoursePatrons::Customer
.select(:product_id)
.where(user_id: current_user.id)
.map { |c| c.product_id }.compact
end
end
end
+5 -3
View File
@@ -40,9 +40,11 @@ module DiscoursePatrons
group.add(current_user)
end
unless DiscoursePatrons::Customer.exists?(user_id: current_user.id)
DiscoursePatrons::Customer.create(user_id: current_user.id, customer_id: params[:customer])
end
DiscoursePatrons::Customer.create(
user_id: current_user.id,
customer_id: params[:customer],
product_id: plan[:product]
)
render_json_dump @subscription