2019-12-17 00:31:58 -05:00
|
|
|
import EmberObject from "@ember/object";
|
2019-10-31 22:43:09 -04:00
|
|
|
import computed from "ember-addons/ember-computed-decorators";
|
|
|
|
import { ajax } from "discourse/lib/ajax";
|
2019-12-02 02:58:14 -05:00
|
|
|
import Plan from "discourse/plugins/discourse-subscriptions/discourse/models/plan";
|
2019-10-31 22:43:09 -04:00
|
|
|
|
2019-12-17 00:31:58 -05:00
|
|
|
const UserSubscription = EmberObject.extend({
|
2019-10-31 22:43:09 -04:00
|
|
|
@computed("status")
|
|
|
|
canceled(status) {
|
|
|
|
return status === "canceled";
|
2019-11-04 00:37:21 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
destroy() {
|
2019-12-02 18:29:44 -05:00
|
|
|
return ajax(`/s/user/subscriptions/${this.id}`, {
|
2019-11-06 04:59:35 -05:00
|
|
|
method: "delete"
|
|
|
|
}).then(result => UserSubscription.create(result));
|
2019-10-31 22:43:09 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
UserSubscription.reopenClass({
|
|
|
|
findAll() {
|
2019-12-02 18:29:44 -05:00
|
|
|
return ajax("/s/user/subscriptions", { method: "get" }).then(result =>
|
2019-10-31 22:43:09 -04:00
|
|
|
result.map(subscription => {
|
|
|
|
subscription.plan = Plan.create(subscription.plan);
|
|
|
|
return UserSubscription.create(subscription);
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default UserSubscription;
|