UNPKG

@magicbell/react-headless

Version:

Hooks to build a notification inbox

55 lines 1.89 kB
"use strict"; 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); } archive(id) { const url = `${this.remotePathOrUrl}/${id}/archive`; return (0, ajax_js_1.postAPI)(url) .then(() => true) .catch(() => false); } unarchive(id) { const url = `${this.remotePathOrUrl}/${id}/unarchive`; return (0, ajax_js_1.postAPI)(url) .then(() => true) .catch(() => false); } markAsRead(id) { const url = `${this.remotePathOrUrl}/${id}/read`; return (0, ajax_js_1.postAPI)(url) .then(() => true) .catch(() => false); } markAsUnread(id) { const url = `${this.remotePathOrUrl}/${id}/unread`; return (0, ajax_js_1.postAPI)(url) .then(() => true) .catch(() => false); } markAllAsSeen(params) { const url = `${this.remotePathOrUrl}/seen`; return (0, ajax_js_1.postAPI)(url, undefined, params) .then(() => true) .catch(() => false); } markAllAsRead(params) { const url = `${this.remotePathOrUrl}/read`; return (0, ajax_js_1.postAPI)(url, undefined, params) .then(() => true) .catch(() => false); } } exports.default = NotificationRepository; //# sourceMappingURL=NotificationRepository.js.map