55 lines
1.1 KiB
Plaintext
Raw Normal View History

2019-10-15 09:40:49 +11:00
import { ajax } from "discourse/lib/ajax";
const AdminProduct = Discourse.Model.extend({
2019-10-16 14:15:01 +11:00
isNew: false,
2019-10-17 12:07:06 +11:00
metadata: {},
2019-10-16 14:15:01 +11:00
2019-10-15 23:14:04 +11:00
destroy() {
return ajax(`/s/admin/products/${this.id}`, { method: "delete" });
2019-10-15 23:14:04 +11:00
},
2019-10-15 09:40:49 +11:00
save() {
2019-10-15 21:50:30 +11:00
const data = {
name: this.name,
2019-10-17 20:34:26 +11:00
statement_descriptor: this.statement_descriptor,
2019-10-16 21:06:19 +11:00
metadata: this.metadata,
2019-10-15 21:50:30 +11:00
active: this.active
};
2019-10-15 09:40:49 +11:00
return ajax("/s/admin/products", {
2019-11-19 11:01:55 +11:00
method: "post",
data
}).then(product => AdminProduct.create(product));
2019-10-16 14:15:01 +11:00
},
update() {
const data = {
name: this.name,
2019-10-17 20:34:26 +11:00
statement_descriptor: this.statement_descriptor,
2019-10-16 21:06:19 +11:00
metadata: this.metadata,
2019-10-16 14:15:01 +11:00
active: this.active
};
return ajax(`/s/admin/products/${this.id}`, {
2019-10-25 14:00:59 +11:00
method: "patch",
data
});
2019-10-15 09:40:49 +11:00
}
});
AdminProduct.reopenClass({
2019-10-15 23:14:04 +11:00
findAll() {
return ajax("/s/admin/products", { method: "get" }).then(result =>
2019-10-15 09:40:49 +11:00
result.map(product => AdminProduct.create(product))
);
2019-10-16 14:15:01 +11:00
},
find(id) {
return ajax(`/s/admin/products/${id}`, {
2019-11-19 11:01:55 +11:00
method: "get"
}).then(product => AdminProduct.create(product));
2019-10-25 14:00:59 +11:00
}
2019-10-15 09:40:49 +11:00
});
export default AdminProduct;