@knora/api
Version:
JavaScript library that handles API requests to Knora
96 lines • 5.25 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var operators_1 = require("rxjs/operators");
var api_response_data_1 = require("../../../models/api-response-data");
var endpoint_1 = require("../../endpoint");
var group_response_1 = require("../../../models/admin/group-response");
var groups_response_1 = require("../../../models/admin/groups-response");
var members_response_1 = require("../../../models/admin/members-response");
/**
* An endpoint for working with Knora groups.
*/
var GroupsEndpoint = /** @class */ (function (_super) {
__extends(GroupsEndpoint, _super);
function GroupsEndpoint() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Returns a list of all groups.
*/
GroupsEndpoint.prototype.getGroups = function () {
var _this = this;
return this.httpGet("").pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, groups_response_1.GroupsResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); }));
};
/**
* Creates a group.
*
* @param group The group to be created.
*/
GroupsEndpoint.prototype.createGroup = function (group) {
var _this = this;
return this.httpPost("", this.jsonConvert.serializeObject(group)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, group_response_1.GroupResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); }));
};
/**
* Gets a group by IRI.
*
* @param iri The IRI of the group.
*/
GroupsEndpoint.prototype.getGroupByIri = function (iri) {
var _this = this;
return this.httpGet("/" + encodeURIComponent(iri)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, group_response_1.GroupResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); }));
};
/**
* Updates a group.
*
* @param iri The IRI of the group to be updated.
* @param groupInfo The group information to be updated.
*/
GroupsEndpoint.prototype.updateGroup = function (iri, groupInfo) {
var _this = this;
return this.httpPut("/" + encodeURIComponent(iri), this.jsonConvert.serializeObject(groupInfo)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, group_response_1.GroupResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); }));
};
/**
* Updates the status of a group.
*
* @param iri The IRI of the group to be updated.
* @param status The new status of the group.
*/
GroupsEndpoint.prototype.updateGroupStatus = function (iri, status) {
var _this = this;
return this.httpPut("/" + encodeURIComponent(iri) + "/status", { status: status }).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, group_response_1.GroupResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); }));
};
/**
* Deletes a group. This method does not actually delete a group, but sets the status to false.
*
* @param iri The IRI of the group.
*/
GroupsEndpoint.prototype.deleteGroup = function (iri) {
var _this = this;
return this.httpDelete("/" + encodeURIComponent(iri)).pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, group_response_1.GroupResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); }));
};
/**
* Gets the members of a group.
*
* @param iri The IRI of the group.
*/
GroupsEndpoint.prototype.getGroupMembers = function (iri) {
var _this = this;
return this.httpGet("/" + encodeURIComponent(iri) + "/members").pipe(operators_1.map(function (ajaxResponse) { return api_response_data_1.ApiResponseData.fromAjaxResponse(ajaxResponse, members_response_1.MembersResponse, _this.jsonConvert); }), operators_1.catchError(function (error) { return _this.handleError(error); }));
};
return GroupsEndpoint;
}(endpoint_1.Endpoint));
exports.GroupsEndpoint = GroupsEndpoint;
//# sourceMappingURL=groups-endpoint.js.map