import { ajax } from "discourse/lib/ajax"; import RestModel from "discourse/models/rest"; import computed from "ember-addons/ember-computed-decorators"; import Category from "discourse/models/category"; export const PENDING = 0; export const APPROVED = 1; export const REJECTED = 2; export const IGNORED = 3; export const DELETED = 4; export default RestModel.extend({ @computed("type") humanType(type) { return I18n.t(`review.types.${type.underscore()}.title`, { defaultValue: "" }); }, update(updates) { // If no changes, do nothing if (Object.keys(updates).length === 0) { return Ember.RSVP.resolve(); } let adapter = this.store.adapterFor("reviewable"); return ajax( `/review/${this.id}?version=${this.version}`, adapter.getPayload("PUT", { reviewable: updates }) ).then(updated => { updated.payload = Object.assign( {}, this.payload || {}, updated.payload || {} ); if (updated.category_id) { updated.category = Category.findById(updated.category_id); delete updated.category_id; } this.setProperties(updated); }); } });