UNPKG

apisearch

Version:
71 lines (70 loc) 1.62 kB
"use strict"; exports.__esModule = true; exports.User = void 0; var InvalidFormatError_1 = require("../Error/InvalidFormatError"); /** * User class */ var User = /** @class */ (function () { /** * Construct * * @param id string * @param attributes Array */ function User(id, attributes) { if (attributes === void 0) { attributes = {}; } this.id = id; this.attributes = attributes; } /** * Return the user id * * @return {string} */ User.prototype.getId = function () { return this.id; }; /** * Return array * * @returns {{}} */ User.prototype.getAttributes = function () { return this.attributes; }; /** * To array * * @returns {{id: string, attributes: {}}} */ User.prototype.toArray = function () { var array = { id: this.id }; if (Object.keys(this.attributes).length > 0) { array.attributes = this.attributes; } return array; }; /** * Create from array * * @param array * * @return User */ User.createFromArray = function (array) { if (array == null || typeof array.id == "undefined" || array.id == null) { throw InvalidFormatError_1.InvalidFormatError.userFormatNotValid(); } var attributes = typeof array.attributes === typeof {} ? array.attributes : {}; return new User(array.id, attributes); }; return User; }()); exports.User = User;