@apihawk/billia-sdk
Version:
The ApiHawk Billia SDK
64 lines (63 loc) • 2.66 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const billia_sdk_service_base_1 = require("../lib/billia-sdk-service-base");
const query_builder_1 = require("./common/query-builder");
const to_rest_resource_1 = require("./common/to-rest-resource");
class BilliaSDKCustomerNotification extends billia_sdk_service_base_1.BilliaSDKServiceBase {
constructor(api) {
super(api);
}
/**
* Get customer notifications.
*
* @param query
* @param session user session
*/
getNotifications(query = {}, session) {
return __awaiter(this, void 0, void 0, function* () {
const filter = {
page_size: -1,
where: []
};
const q = query_builder_1.default.parse(query);
const customerNotification = yield this.api.call({
url: `/customer/notification`,
method: 'GET',
query: q,
session
});
const restResource = to_rest_resource_1.toRestResource(customerNotification, 'customer_notification');
const unseenNotifications = restResource.items.filter((item) => item.status === 'unseen');
restResource.items = unseenNotifications.concat(restResource.items.filter((item) => item.status !== 'unseen'));
return restResource;
});
}
/**
* Change notification status
* @param {IApihawkSession} session
* @param {number | string} notificationId
* @param {string} status
* @returns {Promise<any>}
*/
changeNotificationStatus(session, notificationId, status) {
return __awaiter(this, void 0, void 0, function* () {
return this.api.call({
url: `/customer/notification/${notificationId}`,
method: 'PATCH',
session,
body: {
status
}
});
});
}
}
exports.BilliaSDKCustomerNotification = BilliaSDKCustomerNotification;