@magicbell/core
Version:
Official MagicBell API wrapper
36 lines • 1.07 kB
JavaScript
import { __decorate } from "tslib";
import camelize from '../../lib/decorators/camelize.js';
import unwrap from '../../lib/decorators/unwrap.js';
import NotificationPreferencesRepository from './NotificationPreferencesRepository.js';
/**
* A representation of notification preferences.
*
* @example
* const preferences = new NotificationPreferences()
* await preferences.fetch()
*/
export default class NotificationPreferences {
categories;
repo;
constructor(attrs) {
this.set(attrs);
this.repo = new NotificationPreferencesRepository();
}
async fetch() {
const json = await this.repo.get();
this.set(json);
}
async save(data) {
const payload = { notification_preferences: data };
const json = await this.repo.update(payload);
this.set(json);
}
set(json = {}) {
Object.assign(this, json);
}
}
__decorate([
unwrap('notification_preferences'),
camelize()
], NotificationPreferences.prototype, "set", null);
//# sourceMappingURL=NotificationPreferences.js.map