discourse-subscriptions/assets/javascripts/discourse/models/admin-plan.js.es6

40 lines
848 B
Plaintext
Raw Normal View History

2019-10-09 22:52:55 -04:00
import { ajax } from "discourse/lib/ajax";
const AdminPlan = Discourse.Model.extend({
2019-10-14 18:40:49 -04:00
name: "",
interval: "month",
amount: 0,
intervals: ["day", "week", "month", "year"],
2019-10-15 20:22:58 -04:00
destroy() {
return ajax(`/patrons/admin/plans/${this.id}`, { method: "delete" });
},
2019-10-14 18:40:49 -04:00
save() {
const data = {
2019-10-17 05:34:26 -04:00
nickname: this.nickname,
2019-10-14 18:40:49 -04:00
interval: this.interval,
amount: this.amount,
2019-10-17 05:34:26 -04:00
product_id: this.product_id
2019-10-14 18:40:49 -04:00
};
return ajax("/patrons/admin/plans", { method: "post", data });
}
2019-10-09 22:52:55 -04:00
});
AdminPlan.reopenClass({
2019-10-15 20:22:58 -04:00
findAll() {
2019-10-09 22:52:55 -04:00
return ajax("/patrons/admin/plans", { method: "get" }).then(result =>
2019-10-13 21:36:46 -04:00
result.map(plan => AdminPlan.create(plan))
2019-10-09 22:52:55 -04:00
);
2019-10-17 05:34:26 -04:00
},
find(id) {
return ajax(`/patrons/admin/plans/${id}`, { method: "get" }).then(plan =>
AdminPlan.create(plan)
);
2019-10-09 22:52:55 -04:00
}
});
export default AdminPlan;