discourse-subscriptions/assets/javascripts/discourse/models/admin-product.js

59 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-10-14 18:40:49 -04:00
import { ajax } from "discourse/lib/ajax";
import EmberObject from "@ember/object";
2019-10-14 18:40:49 -04:00
const AdminProduct = EmberObject.extend({
2019-10-15 23:15:01 -04:00
isNew: false,
2019-10-16 21:07:06 -04:00
metadata: {},
2019-10-15 23:15:01 -04:00
2019-10-15 08:14:04 -04:00
destroy() {
return ajax(`/s/admin/products/${this.id}`, { method: "delete" });
2019-10-15 08:14:04 -04:00
},
2019-10-14 18:40:49 -04:00
save() {
2019-10-15 06:50:30 -04:00
const data = {
name: this.name,
2019-10-17 05:34:26 -04:00
statement_descriptor: this.statement_descriptor,
2019-10-16 06:06:19 -04:00
metadata: this.metadata,
2020-09-16 10:53:50 -04:00
active: this.active,
2019-10-15 06:50:30 -04:00
};
2019-10-14 18:40:49 -04:00
return ajax("/s/admin/products", {
2019-11-18 19:01:55 -05:00
method: "post",
2020-09-16 10:53:50 -04:00
data,
}).then((product) => AdminProduct.create(product));
2019-10-15 23:15:01 -04:00
},
update() {
const data = {
name: this.name,
2019-10-17 05:34:26 -04:00
statement_descriptor: this.statement_descriptor,
2019-10-16 06:06:19 -04:00
metadata: this.metadata,
2020-09-16 10:53:50 -04:00
active: this.active,
2019-10-15 23:15:01 -04:00
};
return ajax(`/s/admin/products/${this.id}`, {
2019-10-24 23:00:59 -04:00
method: "patch",
2020-09-16 10:53:50 -04:00
data,
2019-10-24 23:00:59 -04:00
});
2020-09-16 10:53:50 -04:00
},
2019-10-14 18:40:49 -04:00
});
AdminProduct.reopenClass({
2019-10-15 08:14:04 -04:00
findAll() {
2020-09-16 10:53:50 -04:00
return ajax("/s/admin/products", { method: "get" }).then((result) => {
if (result === null) {
return { unconfigured: true };
}
2020-09-16 10:53:50 -04:00
return result.map((product) => AdminProduct.create(product));
});
2019-10-15 23:15:01 -04:00
},
find(id) {
return ajax(`/s/admin/products/${id}`, {
2020-09-16 10:53:50 -04:00
method: "get",
}).then((product) => AdminProduct.create(product));
},
2019-10-14 18:40:49 -04:00
});
export default AdminProduct;