From 48054f14218e7d231fdc62876ac90ba299c03035 Mon Sep 17 00:00:00 2001 From: euglazer Date: Wed, 20 Apr 2016 12:12:56 -0700 Subject: [PATCH] create separate route for adding a customer to a group --- app/controllers/groups_controller.rb | 12 +++++++++++- config/routes.rb | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index b8f3ae8e1..a4ea778d5 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -11,7 +11,6 @@ def index def create group = Group.create(group_params) group.add_admin(current_user) - group.add_customer(current_user.email) render json: [group] end @@ -32,6 +31,17 @@ def update render json: [group] end + api :POST, '/groups/:id/add_customer', 'Add a credit card that pays for the group' + def add_customer + group = Group.find(params[:id]) + if current_user.is_admin_for(group) + group.add_customer(current_user.email) + render json: [group] + else + render nothing: true, status: 403 + end + end + api :POST, '/groups/:id/add_card', 'Add a credit card that pays for the group' def add_card group = Group.find(params[:id]) diff --git a/config/routes.rb b/config/routes.rb index d19495594..0af02796f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -27,6 +27,7 @@ resources :groups, only: [:index, :show, :create, :update] do member do + post :add_customer post :add_card post :extend_trial end