2019-10-31 22:43:09 -04:00
|
|
|
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 UserSubscription = Discourse.Model.extend({
|
|
|
|
@computed("status")
|
|
|
|
canceled(status) {
|
|
|
|
return status === "canceled";
|
2019-11-04 00:37:21 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy() {
|
2019-11-06 04:59:35 -05:00
|
|
|
return ajax(`/patrons/user/subscriptions/${this.id}`, {
|
|
|
|
method: "delete"
|
|
|
|
}).then(result => UserSubscription.create(result));
|
2019-10-31 22:43:09 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
UserSubscription.reopenClass({
|
|
|
|
findAll() {
|
|
|
|
return ajax("/patrons/user/subscriptions", { method: "get" }).then(result =>
|
|
|
|
result.map(subscription => {
|
|
|
|
subscription.plan = Plan.create(subscription.plan);
|
|
|
|
return UserSubscription.create(subscription);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default UserSubscription;
|