mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-03-02 07:39:26 +00:00
39 lines
951 B
JavaScript
39 lines
951 B
JavaScript
import computed from "ember-addons/ember-computed-decorators";
|
|
import { ajax } from "discourse/lib/ajax";
|
|
import Plan from "discourse/plugins/discourse-patrons/discourse/models/plan";
|
|
|
|
const Subscription = Discourse.Model.extend({
|
|
@computed("status")
|
|
canceled(status) {
|
|
return status === "canceled";
|
|
},
|
|
|
|
save() {
|
|
const data = {
|
|
customer: this.customer,
|
|
plan: this.plan
|
|
};
|
|
|
|
return ajax("/patrons/subscriptions", { method: "post", data });
|
|
},
|
|
|
|
destroy() {
|
|
return ajax(`/patrons/subscriptions/${this.id}`, { method: "delete" }).then(
|
|
result => Subscription.create(result)
|
|
);
|
|
}
|
|
});
|
|
|
|
Subscription.reopenClass({
|
|
findAll() {
|
|
return ajax("/patrons/subscriptions", { method: "get" }).then(result =>
|
|
result.map(subscription => {
|
|
subscription.plan = Plan.create(subscription.plan);
|
|
return Subscription.create(subscription);
|
|
})
|
|
);
|
|
}
|
|
});
|
|
|
|
export default Subscription;
|