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

View File

@ -6,7 +6,9 @@ const AdminPlan = Discourse.Model.extend({
amount: 0,
intervals: ["day", "week", "month", "year"],
destroy() {},
destroy() {
return ajax(`/patrons/admin/plans/${this.id}`, { method: "delete" });
},
save() {
const data = {
@ -20,7 +22,7 @@ const AdminPlan = Discourse.Model.extend({
});
AdminPlan.reopenClass({
find() {
findAll() {
return ajax("/patrons/admin/plans", { method: "get" }).then(result =>
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({
model() {
return AdminPlan.find();
return AdminPlan.findAll();
},
actions: {
@ -13,9 +13,12 @@ export default Discourse.Route.extend({
I18n.t("yes_value"),
confirmed => {
if (confirmed) {
this.controllerFor("adminPluginsDiscoursePatronsPlansIndex")
plan.destroy().then(() => {
this.controllerFor("adminPluginsDiscoursePatronsPlansIndex")
.get("model")
.removeObject(plan);
})
.catch(data => bootbox.alert(data.jqXHR.responseJSON.errors.join("\n")));
}
}
);

View File

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