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

46 lines
980 B
Plaintext
Raw Normal View History

2019-10-14 18:40:49 -04:00
import { ajax } from "discourse/lib/ajax";
const AdminProduct = Discourse.Model.extend({
2019-10-15 23:15:01 -04:00
isNew: false,
2019-10-15 08:14:04 -04:00
destroy() {
return ajax(`/patrons/admin/products/${this.id}`, { method: "delete" });
},
2019-10-14 18:40:49 -04:00
save() {
2019-10-15 06:50:30 -04:00
const data = {
name: this.name,
groupName: this.groupName,
active: this.active
};
2019-10-14 18:40:49 -04:00
return ajax("/patrons/admin/products", { method: "post", data });
2019-10-15 23:15:01 -04:00
},
update() {
const data = {
name: this.name,
groupName: this.groupName,
active: this.active
};
return ajax(`/patrons/admin/products/${this.id}`, { method: "patch", data });
2019-10-14 18:40:49 -04:00
}
});
AdminProduct.reopenClass({
2019-10-15 08:14:04 -04:00
findAll() {
2019-10-14 18:40:49 -04:00
return ajax("/patrons/admin/products", { method: "get" }).then(result =>
result.map(product => AdminProduct.create(product))
);
2019-10-15 23:15:01 -04:00
},
find(id) {
return ajax(`/patrons/admin/products/${id}`, { method: "get" }).then(product =>
AdminProduct.create(product)
);
},
2019-10-14 18:40:49 -04:00
});
export default AdminProduct;