magister.js
Version:
A JavaScript implementation of the Magister 6 API
55 lines (47 loc) • 1.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
/**
* @private
*/
class Privileges {
/**
* @param {Magister} magister
* @param {Object} raw
*/
constructor(magister, raw) {
/**
* @property _items
* @private
* @final
* @type {{ Naam: String, AccessType: String[] }[]}
*/
this._items = raw;
}
/**
* @param {string} thing
* @param {string} action
* @returns {boolean}
*/
can(thing, action) {
thing = thing.toLowerCase();
action = action.toLowerCase();
return this._items.some(x => x.Naam.toLowerCase() === thing && x.AccessType.some(a => a.toLowerCase() === action));
}
/**
* @param {string} thing
* @param {string} action
* @returns {Promise}
*/
needs(thing, action) {
if (this.can(thing, action)) {
return Promise.resolve();
} else {
return Promise.reject(new Error(`Account is not privileged to '${action}' '${thing}'`));
}
}
}
var _default = Privileges;
exports.default = _default;