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

55 lines
1.2 KiB
JavaScript
Raw Normal View History

import EmberObject from "@ember/object";
2024-01-16 17:51:44 +01:00
import { ajax } from "discourse/lib/ajax";
2019-10-15 09:40:49 +11:00
2024-11-29 15:42:50 +00:00
export default class AdminProduct extends EmberObject {
static findAll() {
return ajax("/s/admin/products", { method: "get" }).then((result) => {
if (result === null) {
return { unconfigured: true };
}
return result.map((product) => AdminProduct.create(product));
});
}
static find(id) {
return ajax(`/s/admin/products/${id}`, {
method: "get",
}).then((product) => AdminProduct.create(product));
}
isNew = false;
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" });
2024-11-29 15:42:50 +00: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,
2020-09-16 09:53:50 -05:00
active: this.active,
2019-10-15 21:50:30 +11:00
};
2019-10-15 09:40:49 +11:00
return ajax("/s/admin/products", {
2019-11-19 11:01:55 +11:00
method: "post",
2020-09-16 09:53:50 -05:00
data,
}).then((product) => AdminProduct.create(product));
2024-11-29 15:42:50 +00: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,
2020-09-16 09:53:50 -05:00
active: this.active,
2019-10-16 14:15:01 +11:00
};
return ajax(`/s/admin/products/${this.id}`, {
2019-10-25 14:00:59 +11:00
method: "patch",
2020-09-16 09:53:50 -05:00
data,
2019-10-25 14:00:59 +11:00
});
2024-11-29 15:42:50 +00:00
}
}