discourse-subscriptions/assets/javascripts/discourse/models/admin-plan.js.es6

67 lines
1.5 KiB
Plaintext
Raw Normal View History

2019-10-30 20:41:01 -04:00
import Plan from "discourse/plugins/discourse-patrons/discourse/models/plan";
2019-10-22 01:35:41 -04:00
import computed from "ember-addons/ember-computed-decorators";
2019-10-09 22:52:55 -04:00
import { ajax } from "discourse/lib/ajax";
2019-10-30 20:41:01 -04:00
const AdminPlan = Plan.extend({
2019-10-23 00:55:06 -04:00
isNew: false,
2019-10-14 18:40:49 -04:00
name: "",
interval: "month",
amount: 0,
intervals: ["day", "week", "month", "year"],
2019-10-22 20:50:54 -04:00
metadata: {},
2019-10-14 18:40:49 -04:00
2019-10-23 00:55:06 -04:00
@computed("trial_period_days")
parseTrialPeriodDays(trial_period_days) {
2019-10-24 23:00:59 -04:00
if (trial_period_days) {
2019-10-23 00:55:06 -04:00
return parseInt(0 + trial_period_days);
2019-10-24 23:00:59 -04:00
} else {
2019-10-23 00:55:06 -04:00
return 0;
}
},
2019-10-15 20:22:58 -04:00
destroy() {
return ajax(`/patrons/admin/plans/${this.id}`, { method: "delete" });
},
2019-10-14 18:40:49 -04:00
save() {
const data = {
2019-10-17 05:34:26 -04:00
nickname: this.nickname,
2019-10-14 18:40:49 -04:00
interval: this.interval,
amount: this.amount,
2019-10-23 00:55:06 -04:00
trial_period_days: this.parseTrialPeriodDays,
2019-10-22 20:50:54 -04:00
product: this.product,
metadata: this.metadata,
2019-10-23 19:02:31 -04:00
active: this.active
2019-10-14 18:40:49 -04:00
};
return ajax("/patrons/admin/plans", { method: "post", data });
2019-10-23 00:55:06 -04:00
},
update() {
const data = {
nickname: this.nickname,
trial_period_days: this.parseTrialPeriodDays,
metadata: this.metadata,
2019-10-23 19:02:31 -04:00
active: this.active
2019-10-23 00:55:06 -04:00
};
return ajax(`/patrons/admin/plans/${this.id}`, { method: "patch", data });
2019-10-14 18:40:49 -04:00
}
2019-10-09 22:52:55 -04:00
});
AdminPlan.reopenClass({
2019-10-21 00:28:45 -04:00
findAll(data) {
return ajax("/patrons/admin/plans", { method: "get", data }).then(result =>
2019-10-13 21:36:46 -04:00
result.map(plan => AdminPlan.create(plan))
2019-10-09 22:52:55 -04:00
);
2019-10-17 05:34:26 -04:00
},
find(id) {
return ajax(`/patrons/admin/plans/${id}`, { method: "get" }).then(plan =>
AdminPlan.create(plan)
);
2019-10-09 22:52:55 -04:00
}
});
export default AdminPlan;