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

72 lines
1.6 KiB
JavaScript
Raw Normal View History

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