@magicbell/core
Version:
Official MagicBell API wrapper
51 lines • 1.59 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const ajax_js_1 = require("../../lib/ajax.js");
const RemoteRepository_js_1 = tslib_1.__importDefault(require("../../repository/RemoteRepository.js"));
/**
* Class to interact with the notification API endpoints.
*
* @example
* const repo = new NotificationRepository();
* const notifications = repo.findBy({ unseen: true });
*/
class NotificationRepository extends RemoteRepository_js_1.default {
constructor(remotePathOrUrl = '/notifications') {
super(remotePathOrUrl);
}
/**
* Mark a notification as read in the API server.
*/
markAsRead(id) {
const url = `${this.remotePathOrUrl}/${id}/read`;
return (0, ajax_js_1.postAPI)(url)
.then(() => true)
.catch(() => false);
}
/**
* Mark a notification as unread in the API server.
*/
markAsUnread(id) {
const url = `${this.remotePathOrUrl}/${id}/unread`;
return (0, ajax_js_1.postAPI)(url)
.then(() => true)
.catch(() => false);
}
/**
* Mark all notifications as seen.
*/
markAllAsSeen() {
const url = `${this.remotePathOrUrl}/seen`;
return (0, ajax_js_1.postAPI)(url);
}
/**
* Mark all notifications as read.
*/
markAllAsRead() {
const url = `${this.remotePathOrUrl}/read`;
return (0, ajax_js_1.postAPI)(url);
}
}
exports.default = NotificationRepository;
//# sourceMappingURL=NotificationRepository.js.map