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

64 lines
1.5 KiB
Plaintext
Raw Normal View History

2019-12-02 02:58:14 -05:00
import Plan from "discourse/plugins/discourse-subscriptions/discourse/models/plan";
import discourseComputed from "discourse-common/utils/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",
unit_amount: 0,
2019-10-14 18:40:49 -04:00
intervals: ["day", "week", "month", "year"],
2019-10-22 20:50:54 -04:00
metadata: {},
2019-10-14 18:40:49 -04:00
@discourseComputed("trial_period_days")
parseTrialPeriodDays(trialDays) {
if (trialDays) {
return parseInt(0 + trialDays, 10);
2019-10-24 23:00:59 -04:00
} else {
2019-10-23 00:55:06 -04:00
return 0;
}
},
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.unit_amount,
2019-11-30 01:44:16 -05:00
currency: this.currency,
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("/s/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(`/s/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("/s/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(`/s/admin/plans/${id}`, { method: "get" }).then(plan =>
2019-10-17 05:34:26 -04:00
AdminPlan.create(plan)
);
2019-10-09 22:52:55 -04:00
}
});
export default AdminPlan;