60 lines
1.3 KiB
Plaintext
Raw Normal View History

2019-10-22 16:35:41 +11:00
import computed from "ember-addons/ember-computed-decorators";
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-22 16:35:41 +11:00
@computed("created")
createdFormatted(created) {
return moment.unix(created).format();
},
2019-10-15 23:14:04 +11:00
destroy() {
return ajax(`/patrons/admin/products/${this.id}`, { method: "delete" });
},
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
2019-10-25 14:00:59 +11:00
return ajax("/patrons/admin/products", { method: "post", data }).then(
product => AdminProduct.create(product)
2019-10-23 15:55:06 +11:00
);
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
};
2019-10-25 14:00:59 +11:00
return ajax(`/patrons/admin/products/${this.id}`, {
method: "patch",
data
});
2019-10-15 09:40:49 +11:00
}
});
AdminProduct.reopenClass({
2019-10-15 23:14:04 +11:00
findAll() {
2019-10-15 09:40:49 +11:00
return ajax("/patrons/admin/products", { method: "get" }).then(result =>
result.map(product => AdminProduct.create(product))
);
2019-10-16 14:15:01 +11:00
},
find(id) {
2019-10-25 14:00:59 +11:00
return ajax(`/patrons/admin/products/${id}`, { method: "get" }).then(
product => AdminProduct.create(product)
2019-10-16 14:15:01 +11:00
);
2019-10-25 14:00:59 +11:00
}
2019-10-15 09:40:49 +11:00
});
export default AdminProduct;