destroy plans

This commit is contained in:
Rimian Perkins 2019-10-16 11:22:58 +11:00
parent 1bedc1ba2f
commit e2f1f0f523
4 changed files with 26 additions and 9 deletions

View File

@ -8,8 +8,14 @@ module DiscoursePatrons
before_action :set_api_key before_action :set_api_key
def index def index
plans = ::Stripe::Plan.list begin
render_json_dump plans.data plans = ::Stripe::Plan.list
render_json_dump plans.data
rescue ::Stripe::InvalidRequestError => e
return render_json_error e.message
end
end end
def create def create
@ -31,8 +37,14 @@ module DiscoursePatrons
end end
def destroy def destroy
plan = ::Stripe::Plan.delete(params[:id]) begin
render_json_dump plan plan = ::Stripe::Plan.delete(params[:id])
render_json_dump plan
rescue ::Stripe::InvalidRequestError => e
return render_json_error e.message
end
end end
private private

View File

@ -6,7 +6,9 @@ const AdminPlan = Discourse.Model.extend({
amount: 0, amount: 0,
intervals: ["day", "week", "month", "year"], intervals: ["day", "week", "month", "year"],
destroy() {}, destroy() {
return ajax(`/patrons/admin/plans/${this.id}`, { method: "delete" });
},
save() { save() {
const data = { const data = {
@ -20,7 +22,7 @@ const AdminPlan = Discourse.Model.extend({
}); });
AdminPlan.reopenClass({ AdminPlan.reopenClass({
find() { findAll() {
return ajax("/patrons/admin/plans", { method: "get" }).then(result => return ajax("/patrons/admin/plans", { method: "get" }).then(result =>
result.map(plan => AdminPlan.create(plan)) result.map(plan => AdminPlan.create(plan))
); );

View File

@ -2,7 +2,7 @@ import AdminPlan from "discourse/plugins/discourse-patrons/discourse/models/admi
export default Discourse.Route.extend({ export default Discourse.Route.extend({
model() { model() {
return AdminPlan.find(); return AdminPlan.findAll();
}, },
actions: { actions: {
@ -13,9 +13,12 @@ export default Discourse.Route.extend({
I18n.t("yes_value"), I18n.t("yes_value"),
confirmed => { confirmed => {
if (confirmed) { if (confirmed) {
this.controllerFor("adminPluginsDiscoursePatronsPlansIndex") plan.destroy().then(() => {
this.controllerFor("adminPluginsDiscoursePatronsPlansIndex")
.get("model") .get("model")
.removeObject(plan); .removeObject(plan);
})
.catch(data => bootbox.alert(data.jqXHR.responseJSON.errors.join("\n")));
} }
} }
); );

View File

@ -68,7 +68,7 @@ en:
active: Active active: Active
product: product:
product_id: Product ID product_id: Product ID
group: Group group: User Group
active: Active active: Active
operations: operations:
destroy: destroy: