discourse/app/assets/javascripts/admin/addon/models/email-log.js
David Taylor 64557c4076
DEV: Update admin models to native class syntax (#20704)
This commit was generated using the ember-native-class-codemod along with a handful of manual updates
2023-03-17 10:18:42 +00:00

33 lines
799 B
JavaScript

import AdminUser from "admin/models/admin-user";
import EmberObject from "@ember/object";
import { ajax } from "discourse/lib/ajax";
import getURL from "discourse-common/lib/get-url";
export default class EmailLog extends EmberObject {
static create(attrs) {
attrs = attrs || {};
if (attrs.user) {
attrs.user = AdminUser.create(attrs.user);
}
if (attrs.post_url) {
attrs.post_url = getURL(attrs.post_url);
}
return super.create(attrs);
}
static findAll(filter, offset) {
filter = filter || {};
offset = offset || 0;
const status = filter.status || "sent";
delete filter.status;
return ajax(`/admin/email/${status}.json?offset=${offset}`, {
data: filter,
}).then((logs) => logs.map((log) => EmailLog.create(log)));
}
}