mirror of
https://github.com/discourse/discourse-subscriptions.git
synced 2025-03-02 07:39:26 +00:00
The code in the plugin needed a dramatic cleanup. This refactor collapses the Plan/Product/Subscription controllers on the backend into one new controller: `SubscribeController`. This reduces N+1 calls to the back end during the subscription process and simplifies use of the code. I've also removed a bunch of dead code and refactored some logic into methods for easier readability. No feature/functionality changes in this commit; only refactoring. However, refactoring will allow for implementation of better anonymous user handling, so this is largely a foundation to enable making that change.
28 lines
567 B
JavaScript
28 lines
567 B
JavaScript
import discourseComputed from "discourse-common/utils/decorators";
|
|
import { ajax } from "discourse/lib/ajax";
|
|
import EmberObject from "@ember/object";
|
|
|
|
const Subscription = EmberObject.extend({
|
|
@discourseComputed("status")
|
|
canceled(status) {
|
|
return status === "canceled";
|
|
},
|
|
|
|
save() {
|
|
const data = {
|
|
source: this.source,
|
|
plan: this.plan,
|
|
};
|
|
|
|
return ajax("/s/create", { method: "post", data });
|
|
},
|
|
});
|
|
|
|
Subscription.reopenClass({
|
|
show(id) {
|
|
return ajax(`/s/${id}`, { method: "get" });
|
|
},
|
|
});
|
|
|
|
export default Subscription;
|