44 lines
1.0 KiB
Plaintext
Raw Normal View History

2019-10-29 11:43:32 +11:00
import computed from "ember-addons/ember-computed-decorators";
2019-10-17 20:34:26 +11:00
import { ajax } from "discourse/lib/ajax";
2019-10-31 11:41:01 +11:00
import Plan from "discourse/plugins/discourse-patrons/discourse/models/plan";
2019-10-17 20:34:26 +11:00
const Subscription = Discourse.Model.extend({
2019-10-29 11:43:32 +11:00
@computed("created")
createdFormatted(created) {
return moment.unix(created).format();
},
2019-10-31 10:01:41 +11:00
@computed("status")
canceled(status) {
return status === 'canceled';
},
2019-10-17 20:34:26 +11:00
save() {
const data = {
customer: this.customer,
plan: this.plan
};
return ajax("/patrons/subscriptions", { method: "post", data });
2019-10-29 14:35:07 +11:00
},
destroy() {
2019-10-31 10:01:41 +11:00
return ajax(`/patrons/subscriptions/${this.id}`, { method: "delete" }).then(result =>
Subscription.create(result)
);
2019-10-29 14:35:07 +11:00
},
2019-10-17 20:34:26 +11:00
});
2019-10-29 11:43:32 +11:00
Subscription.reopenClass({
findAll() {
return ajax("/patrons/subscriptions", { method: "get" }).then(result =>
2019-10-31 11:41:01 +11:00
result.map(subscription => {
subscription.plan = Plan.create(subscription.plan);
return Subscription.create(subscription)
})
2019-10-29 11:43:32 +11:00
);
}
});
2019-10-17 20:34:26 +11:00
export default Subscription;