backend returns if user is already subscribed
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user