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

55 lines
1.2 KiB
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-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(`/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,
2019-10-17 05:34:26 -04:00
statement_descriptor: this.statement_descriptor,
2019-10-16 06:06:19 -04:00
metadata: this.metadata,
2019-10-15 06:50:30 -04:00
active: this.active
};
2019-10-14 18:40:49 -04:00
2019-11-18 19:01:55 -05:00
return ajax("/patrons/admin/products", {
method: "post",
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,
2019-10-15 23:15:01 -04:00
active: this.active
};
2019-10-24 23:00:59 -04:00
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) {
2019-11-18 19:01:55 -05:00
return ajax(`/patrons/admin/products/${id}`, {
method: "get"
}).then(product => AdminProduct.create(product));
2019-10-24 23:00:59 -04:00
}
2019-10-14 18:40:49 -04:00
});
export default AdminProduct;