redmine-ts
Version:
Redmine REST API client written using TypeScript
865 lines (862 loc) • 32.8 kB
JavaScript
"use strict";
/**
* Redmine REST API client written in TypeScript
*
* MIT License 2021 Jakub Gawryl
*
*/
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Redmine = void 0;
var axios_1 = require("axios");
var Redmine = /** @class */ (function () {
/**
* Constructor
* @param host
* @param options
*/
function Redmine(baseUrl, options) {
if (!baseUrl) {
throw Error('Redmine host is not specified!');
}
this.baseURL = baseUrl;
this.options = options;
}
// ==================== PRIVATE METHODS ====================
/**
* Deeply iterate through given object and replace all found arrays into comma separated strings.
*
* @param obj
*/
Redmine._deepJoinArrays = function (obj) {
var newObj = {};
for (var k in obj) {
var v = obj[k];
newObj[k] = (typeof v === "object") ? (Array.isArray(v)) ? v.join(",") : Redmine._deepJoinArrays(v) : v;
}
return newObj;
};
/**
* Creates connection (if there's not any) and sends request to redmine API
* @param method HTTP methos (GET, POST, PUT, DELETE, etc)
* @param path Redmine API path (without initial "/" and format eg. "issues/1")
* @param params Parameters that are sent with request
*/
Redmine.prototype.request = function (method, path, params) {
if (params === void 0) { params = {}; }
// Create connection (if not present)
if (!this.conn) {
var connConfig = {
baseURL: this.baseURL,
maxBodyLength: this.options.maxUploadSize || 5242880,
headers: {
'Content-Type': 'application/json'
}
};
var _a = this.options, apiKey = _a.apiKey, username = _a.username, password = _a.password, impersonateUser = _a.impersonateUser;
// Set authentication
if (apiKey) {
connConfig.headers['X-Redmine-API-Key'] = apiKey;
}
else if (username && password) {
connConfig.auth = {
username: username,
password: password
};
}
// Set impersonate
if (impersonateUser) {
connConfig.headers['X-Redmine-Switch-User'] = impersonateUser;
}
this.conn = axios_1.default.create(connConfig);
}
var isUpload = path === 'uploads';
return this.conn[method.toLocaleLowerCase()]("/" + path + ".json", (method === "GET" || method === "get") ? Redmine._deepJoinArrays(params) : params, (isUpload) ? { headers: { 'Content-Type': 'application/octet-stream' } } : {})
.then(function (res) { return res.data; })
.catch(function (err) {
var _a;
// Check for axios connection error
if (err.errno) {
throw Error("Axios connection problem (" + err.config.baseURL + "): " + err.errno);
}
if (err.response) {
var message = err.response.status + " " + err.response.statusText + " (" + err.request.path + ")";
if (Array.isArray(err.response.data.errors) && err.response.data.errors.length > 0) {
message += "\n" + ((_a = err.response) === null || _a === void 0 ? void 0 : _a.data.errors.join(", "));
}
throw Error(message);
}
else {
throw err;
}
});
};
// ==================== PROJECTS ====================
/**
* Get list of projects
* http://www.redmine.org/projects/redmine/wiki/Rest_Projects#Listing-projects
*
* @param params
*/
Redmine.prototype.listProjects = function (params) {
return this.request('get', 'projects', { params: params });
};
/**
* Create project
* http://www.redmine.org/projects/redmine/wiki/Rest_Projects#Creating-a-project
*
* @param project
*/
Redmine.prototype.createProject = function (project) {
return this.request('post', 'projects', { project: project });
};
/**
* Get project
* http://www.redmine.org/projects/redmine/wiki/Rest_Projects#Showing-a-project
*
* @param projectId
* @param params
*/
Redmine.prototype.getProject = function (projectId, params) {
return this.request('get', "projects/" + projectId, { params: params });
};
/**
* Update project
* http://www.redmine.org/projects/redmine/wiki/Rest_Projects#Updating-a-project
*
* @param projectId
* @param project
*/
Redmine.prototype.updateProject = function (projectId, project) {
return this.request('put', "projects/" + projectId, { project: project });
};
/**
* Delete project
* https://www.redmine.org/projects/redmine/wiki/Rest_Projects#Deleting-a-project
*
* @param projectId
*/
Redmine.prototype.deleteProject = function (projectId) {
return this.request('delete', "projects/" + projectId);
};
// ==================== ISSUES ====================
/**
* Get list of issues
* http://www.redmine.org/projects/redmine/wiki/Rest_Issues#Listing-issues
*
* @param params
*/
Redmine.prototype.listIssues = function (params) {
return this.request('get', 'issues', { params: params });
};
/**
* Create issue
* http://www.redmine.org/projects/redmine/wiki/Rest_Issues#Creating-an-issue
*
* @param issue
*/
Redmine.prototype.createIssue = function (issue) {
return this.request('post', 'issues', { issue: issue });
};
/**
* Get issue
* http://www.redmine.org/projects/redmine/wiki/Rest_Issues#Showing-an-issue
*
* @param issueId
* @param params
*/
Redmine.prototype.getIssue = function (issueId, params) {
return this.request('get', "issues/" + issueId, { params: params });
};
/**
* Update issue
* http://www.redmine.org/projects/redmine/wiki/Rest_Issues#Updating-an-issue
*
* @param issueId
* @param issue
*/
Redmine.prototype.updateIssue = function (issueId, issue) {
return this.request('put', "issues/" + issueId, { issue: issue });
};
/**
* Delete issue
* http://www.redmine.org/projects/redmine/wiki/Rest_Issues#Deleting-an-issue
*
* @param issueId
*/
Redmine.prototype.deleteIssue = function (issueId) {
return this.request('delete', "issues/" + issueId);
};
/**
* Adds watcher to issue
* https://www.redmine.org/projects/redmine/wiki/Rest_Issues#Adding-a-watcher
*
* @param issueId
* @param watcherId
*/
Redmine.prototype.addWatcher = function (issueId, watcherId) {
return this.request('post', "issues/" + issueId + "/watchers", {
user_id: watcherId
});
};
/**
* Remove watcher from issue
* https://www.redmine.org/projects/redmine/wiki/Rest_Issues#Removing-a-watcher
*
* @param issueId
* @param watcherId
*/
Redmine.prototype.removeWatcher = function (issueId, watcherId) {
return this.request('delete', "issues/" + issueId + "/watchers/" + watcherId);
};
// ==================== MEMBERSHIPS ====================
/**
* Returns a paginated list of the project memberships.
* https://www.redmine.org/projects/redmine/wiki/Rest_Memberships#GET
*
* @param projectId can be either the project numerical id or the project identifier.
*/
Redmine.prototype.listProjectMembers = function (projectId, params) {
return this.request('get', "projects/" + projectId + "/memberships", { params: params });
};
/**
* Adds a project member.
* https://www.redmine.org/projects/redmine/wiki/Rest_Memberships#POST
*
* @param projectId can be either the project numerical id or the project identifier.
* @param membership
*/
Redmine.prototype.addProjectMember = function (projectId, membership) {
return this.request('post', "projects/" + projectId + "/memberships", { membership: membership });
};
/**
* Returns the membership of given id
* https://www.redmine.org/projects/redmine/wiki/Rest_Memberships#GET-2
*
* @param membershipId
*/
Redmine.prototype.getMembership = function (membershipId) {
return this.request('get', "memberships/" + membershipId);
};
/**
* Updates the membership of given id. Only the roles can be updated, the project and the user of a membership are read-only.
* https://www.redmine.org/projects/redmine/wiki/Rest_Memberships#PUT
*
* @param membershipId
* @param membership
*/
Redmine.prototype.updateMembership = function (membershipId, membership) {
return this.request('put', "memberships/" + membershipId, { membership: membership });
};
/**
* Deletes a memberships. Memberships inherited from a group membership can not be deleted. You must delete the group membership.
* https://www.redmine.org/projects/redmine/wiki/Rest_Memberships#DELETE
*
* @param membershipId
*/
Redmine.prototype.deleteMembership = function (membershipId) {
return this.request('delete', "memberships/" + membershipId);
};
// ==================== USERS ====================
/**
* Returns a list of users. This endpoint requires admin privileges.
* https://www.redmine.org/projects/redmine/wiki/Rest_Users#GET
*
* @param params
*/
Redmine.prototype.listUsers = function (params) {
return this.request('get', 'users', { params: params });
};
/**
* Creates a user. This endpoint requires admin privileges.
* https://www.redmine.org/projects/redmine/wiki/Rest_Users#POST
*
* @param user
* @param sendToUser
*/
Redmine.prototype.createUser = function (user, sendToUser) {
if (sendToUser === void 0) { sendToUser = false; }
return this.request('post', 'users', {
user: user,
send_information: sendToUser
});
};
/**
* Returns the user details. This endpoint can be used by admin or non admin but the returned fields will
* depend on the privileges of the requesting user. Details available in documentation:
* https://www.redmine.org/projects/redmine/wiki/Rest_Users#GET-2
*
* @param userId Id of the user or 'current' for retrieving the user whose credentials are used to access the API.
* @param params
*/
Redmine.prototype.getUser = function (userId, params) {
return this.request('get', "users/" + userId, { params: params });
};
/**
* Updates a user. This endpoint requires admin privileges.
* https://www.redmine.org/projects/redmine/wiki/Rest_Users#PUT
*
* @param userId
* @param user
*/
Redmine.prototype.updateUser = function (userId, user) {
return this.request('put', "users/" + userId, { user: user });
};
/**
* Deletes a user. This endpoint requires admin privileges.
* https://www.redmine.org/projects/redmine/wiki/Rest_Users#DELETE
*
* @param userId
*/
Redmine.prototype.deleteUser = function (userId) {
return this.request('delete', "users/" + userId);
};
// ==================== TIME ENTRIES ====================
/**
* Return time entries.
* https://www.redmine.org/projects/redmine/wiki/Rest_TimeEntries#Listing-time-entries
*
* @param params
*/
Redmine.prototype.listTimeEntries = function (params) {
return this.request('get', 'time_entries', { params: params });
};
/**
* Returns the time entry of given id.
* https://www.redmine.org/projects/redmine/wiki/Rest_TimeEntries#Showing-a-time-entry
*
* @param teId
*/
Redmine.prototype.getTimeEntry = function (teId) {
return this.request('get', "time_entries/" + teId);
};
/**
* Creates a time entry. It's apply to the issue or project but only one is required!
* (so only issue_id OR project_id can be passed here!)
* https://www.redmine.org/projects/redmine/wiki/Rest_TimeEntries#Creating-a-time-entry
*
* @param timeEntry
*/
Redmine.prototype.createTimeEntry = function (timeEntry) {
return this.request('post', 'time_entries', {
time_entry: timeEntry
});
};
/**
* Updates the time entry of given id.
* IMPORTANT NOTE: If time entry is transferred from one project to another (by changing project_id),
* the issue_id parameter must be set to null (or issue id which belongs to a new project)
* Otherwise, the method may return the error 'Issue is invalid'
* https://www.redmine.org/projects/redmine/wiki/Rest_TimeEntries#Updating-a-time-entry
*
* @param teId
* @param timeEntry
*/
Redmine.prototype.updateTimeEntry = function (teId, timeEntry) {
return this.request('put', "time_entries/" + teId, {
time_entry: timeEntry
});
};
/**
* Deletes the time entry of given id.
* https://www.redmine.org/projects/redmine/wiki/Rest_TimeEntries#Deleting-a-time-entry
*
* @param teId
*/
Redmine.prototype.deleteTimeEntry = function (teId) {
return this.request('delete', "time_entries/" + teId);
};
// ==================== NEWS ====================
/**
* Returns all news across all projects with pagination.
* https://www.redmine.org/projects/redmine/wiki/Rest_News#GET
*
* @param params
*/
Redmine.prototype.listAllNews = function (params) {
return this.request('get', 'news', { params: params });
};
/**
* Returns all news from project with given id or identifier with pagination.
* https://www.redmine.org/projects/redmine/wiki/Rest_News#GET-2
*
* @param projectId
* @param params
*/
Redmine.prototype.listProjectNews = function (projectId, params) {
return this.request('get', "projects/" + projectId + "/news", { params: params });
};
/**
* Get single news (Released in Redmine 4.1.0 but not yet documented)
* https://www.redmine.org/projects/redmine/repository/revisions/18441
*
* @param newsId
*/
Redmine.prototype.getNews = function (newsId, params) {
return this.request('get', "news/" + newsId, { params: params });
};
/**
* Create news (Released in Redmine 4.1.0 but not yet documented)
* https://www.redmine.org/projects/redmine/repository/revisions/18440
*
* @param news
*/
Redmine.prototype.createNews = function (projectId, news) {
return this.request('post', "projects/" + projectId + "/news", { news: news });
};
/**
* Update news (Released in Redmine 4.1.0 but not yet documented)
* https://www.redmine.org/projects/redmine/repository/revisions/18443
*
* @param newsId
* @param news
*/
Redmine.prototype.updateNews = function (newsId, news) {
return this.request('put', "news/" + newsId, { news: news });
};
/**
* Delete news (Released in Redmine 4.1.0 but not yet documented)
* https://www.redmine.org/projects/redmine/repository/revisions/18442
*
* @param newsId
*/
Redmine.prototype.deleteNews = function (newsId) {
return this.request('delete', "news/" + newsId);
};
// ==================== ISSUES RELATIONS ====================
/**
* Returns the relations for the issue of given id (not relation id!)
* https://www.redmine.org/projects/redmine/wiki/Rest_IssueRelations#GET
*
* @param issueId
*/
Redmine.prototype.listIssueRelations = function (issueId) {
return this.request('get', "issues/" + issueId + "/relations");
};
/**
* Creates a relation for the issue of given id (not relation id!)
* https://www.redmine.org/projects/redmine/wiki/Rest_IssueRelations#POST
*
* @param issueId
* @param relation
*/
Redmine.prototype.createIssueRelation = function (issueId, relation) {
return this.request('post', "issues/" + issueId + "/relations", { relation: relation });
};
/**
* Returns the relation of given id (not issue id!)
* https://www.redmine.org/projects/redmine/wiki/Rest_IssueRelations#GET-2
*
* @param relationId
*/
Redmine.prototype.getIssueRelation = function (relationId) {
return this.request('get', "relations/" + relationId);
};
/**
* Deletes the relation of given id (not issue id!)
* https://www.redmine.org/projects/redmine/wiki/Rest_IssueRelations#DELETE
*
* @param relationId
*/
Redmine.prototype.deleteIssueRelation = function (relationId) {
return this.request('delete', "relations/" + relationId);
};
// ==================== VERSIONS ====================
/**
* Returns the versions available for the project of given id or identifier.
* The response may include shared versions from other projects.
* https://www.redmine.org/projects/redmine/wiki/Rest_Versions#GET
*
* @param projectId
*/
Redmine.prototype.listProjectVersions = function (projectId) {
return this.request('get', "projects/" + projectId + "/versions");
};
/**
* Creates a version for the project of given id or identifier
* https://www.redmine.org/projects/redmine/wiki/Rest_Versions#POST
*
* @param projectId
* @param version
*/
Redmine.prototype.createProjectVersion = function (projectId, version) {
return this.request('post', "projects/" + projectId + "/versions", { version: version });
};
/**
* Returns the version of given id.
* https://www.redmine.org/projects/redmine/wiki/Rest_Versions#GET-2
*
* @param versionId
*/
Redmine.prototype.getProjectVersion = function (versionId) {
return this.request('get', "versions/" + versionId);
};
/**
* Updates the version of given id
* https://www.redmine.org/projects/redmine/wiki/Rest_Versions#PUT
*
* @param versionId
* @param version
*/
Redmine.prototype.updateProjectVersion = function (versionId, version) {
return this.request('put', "versions/" + versionId, { version: version });
};
/**
* Deletes the version of given id.
* https://www.redmine.org/projects/redmine/wiki/Rest_Versions#DELETE
*
* @param versionId
*/
Redmine.prototype.deleteProjectVersion = function (versionId) {
return this.request('delete', "versions/" + versionId);
};
// ==================== WIKI PAGES ====================
/**
* Returns the list of all pages in a project wiki.
* https://www.redmine.org/projects/redmine/wiki/Rest_WikiPages#Getting-the-pages-list-of-a-wiki
*
* @param projectId
*/
Redmine.prototype.listWikiPages = function (projectId) {
return this.request('get', "projects/" + projectId + "/wiki/index");
};
/**
* Returns the details of a wiki page.
* If version param is passed, returns the details of an old version of a wiki page.
* https://www.redmine.org/projects/redmine/wiki/Rest_WikiPages#Getting-a-wiki-page
*
* @param projectId
* @param pageTitle
* @param params
* @param version
*/
Redmine.prototype.getWikiPage = function (projectId, pageTitle, params, version) {
return this.request('get', "projects/" + projectId + "/wiki/" + pageTitle + (version ? "/" + version : ''), { params: params });
};
/**
* Creates or updates a wiki page.
*
* When creating or updating wiki pages, the text field must be provided.
* If you do not wish to change the text, you can keep it by first getting
* the wiki page, and provide the current text in the update.
*
* When updating an existing page, you can include a version attribute to
* make sure that the page is a specific version when you try to update it.
* (eg. you don't want to overwrite an update that would have been done after you retrieved the page).
* https://www.redmine.org/projects/redmine/wiki/Rest_WikiPages#Creating-or-updating-a-wiki-page
* @param projectId
* @param pageTitle
* @param wikiPages
*/
Redmine.prototype.createUpdateWikiPage = function (projectId, pageTitle, wikiPages) {
return this.request('put', "projects/" + projectId + "/wiki/" + pageTitle, {
wiki_page: wikiPages
});
};
/**
* Deletes a wiki page, its attachments and its history. If the deleted page is a
* parent page,its child pages are not deleted but changed as root pages.
* https://www.redmine.org/projects/redmine/wiki/Rest_WikiPages#Deleting-a-wiki-page
*
* @param projectId
* @param pageTitle
*/
Redmine.prototype.deleteWikiPage = function (projectId, pageTitle) {
return this.request('delete', "projects/" + projectId + "/wiki/" + pageTitle);
};
// ==================== QUERIES ====================
/**
* Returns the list of all custom queries visible by the user (public and private queries) for all projects.
* https://www.redmine.org/projects/redmine/wiki/Rest_Queries
*/
Redmine.prototype.listQueries = function () {
return this.request('get', 'queries');
};
// ==================== ATTACHMENTS ====================
/**
* Upload file to Redmine's server If the upload succeeds, you get
* a 201 response that contains a token for your uploaded file.
* https://www.redmine.org/projects/redmine/wiki/Rest_api#Attaching-files
*
* @param fileContent File content
*/
Redmine.prototype.uploadFile = function (fileContent) {
return this.request('post', 'uploads', fileContent);
};
/**
* Returns the description of the attachment of given id. The file can actually
* be downloaded at the URL given by the content_url attribute in the response.
* Then you can use this token to attach your uploaded file to a new or an
* existing issue or other resource (eg. news, wiki pages etc.)
* https://www.redmine.org/projects/redmine/wiki/Rest_Attachments#attachmentsidformat
*
* @param attachmentId
*/
Redmine.prototype.getAttachment = function (attachmentId) {
return this.request('get', "attachments/" + attachmentId);
};
/**
* Update attachment info (only filename and description can be changed)
*
* IMPORTANT NOTE: Changing filename may cause the image file to
* no longer appear on news pages, wikis, etc., when an image
* token ("!filename.png!") is used in the content.
*
* @param attachmentId
* @param attachment
*/
Redmine.prototype.updateAttachmentInfo = function (attachmentId, attachment) {
return this.request('put', "attachments/" + attachmentId, { attachment: attachment });
};
/**
* Delete an attachement
*
* IMPORTANT NOTE: Deleting attachement may cause the image file to
* no longer appear on news pages, wikis, etc., when an image
* token ("!filename.png!") is used in the content.
*
* https://www.redmine.org/projects/redmine/wiki/Rest_Attachments#DELETE
*
* @param attachmentId
*/
Redmine.prototype.deleteAttachment = function (attachmentId) {
return this.request('delete', "attachments/" + attachmentId);
};
// ==================== ISSUE STATUSES ====================
/**
* Returns the list of all issue statuses.
* https://www.redmine.org/projects/redmine/wiki/Rest_IssueStatuses
*/
Redmine.prototype.listIssueStatuses = function () {
return this.request('get', "issue_statuses");
};
// ==================== TRACKERS ====================
/**
* Returns the list of all trackers.
* https://www.redmine.org/projects/redmine/wiki/Rest_Trackers
*/
Redmine.prototype.listTrackers = function () {
return this.request('get', "trackers");
};
// ==================== ENUMERATIONS ====================
/**
* Returns the list of issue priorities.
* https://www.redmine.org/projects/redmine/wiki/Rest_Enumerations#enumerationsissue_prioritiesformat
*/
Redmine.prototype.listIssuePrioritiesEnum = function () {
return this.request('get', "enumerations/issue_priorities");
};
/**
* Returns the list of time entry activities.
* https://www.redmine.org/projects/redmine/wiki/Rest_Enumerations#enumerationstime_entry_activitiesformat
*/
Redmine.prototype.listTimeEntryActivitiesEnum = function () {
return this.request('get', "enumerations/time_entry_activities");
};
/**
* Returns the list of document categories.
* https://www.redmine.org/projects/redmine/wiki/Rest_Enumerations#enumerationsdocument_categoriesformat
*/
Redmine.prototype.listDocumentCategoriesEnum = function () {
return this.request('get', "enumerations/document_categories");
};
// ==================== ISSUE CATEGORIES ====================
/**
* Returns the issue categories available for the project of given id or identifier.
* @param projectId
*/
Redmine.prototype.listIssueCategories = function (projectId) {
return this.request('get', "projects/" + projectId + "/issue_categories");
};
/**
* Creates an issue category for the project of given id or identifier
* https://www.redmine.org/projects/redmine/wiki/Rest_IssueCategories#POST
*
* @param projectId
* @param issueCategory
*/
Redmine.prototype.createIssueCategory = function (projectId, issueCategory) {
return this.request('post', "projects/" + projectId + "/issue_categories", {
issue_category: issueCategory
});
};
/**
* Returns the issue category of given id
* https://www.redmine.org/projects/redmine/wiki/Rest_IssueCategories#GET-2
*
* @param issueCategoryId
*/
Redmine.prototype.getIssueCategory = function (issueCategoryId) {
return this.request('get', "issue_categories/" + issueCategoryId);
};
/**
* Updates the issue category of given id
* https://www.redmine.org/projects/redmine/wiki/Rest_IssueCategories#PUT
*
* @param issueCategoryId
* @param issueCategory
*/
Redmine.prototype.updateIssueCategory = function (issueCategoryId, issueCategory) {
return this.request('put', "issue_categories/" + issueCategoryId, {
issue_category: issueCategory
});
};
/**
* Deletes the issue category of given id
* https://www.redmine.org/projects/redmine/wiki/Rest_IssueCategories#DELETE
*
* @param issueCategoryId
*/
Redmine.prototype.deleteIssueCategory = function (issueCategoryId) {
return this.request('delete', "issue_categories/" + issueCategoryId);
};
// ==================== ROLES ====================
/**
* Returns the list of roles
* https://www.redmine.org/projects/redmine/wiki/Rest_Roles#rolesformat
*/
Redmine.prototype.listRoles = function () {
return this.request('get', "roles");
};
/**
* Returns the list of permissions for a given role
* https://www.redmine.org/projects/redmine/wiki/Rest_Roles#GET-2
*
* @param roleId
*/
Redmine.prototype.listRolePermissions = function (roleId) {
return this.request('get', "roles/" + roleId);
};
// ==================== GROUPS ====================
/**
* Returns the list of groups. This endpoint requires admin privileges
* https://www.redmine.org/projects/redmine/wiki/Rest_Groups#GET
*/
Redmine.prototype.listGroups = function () {
return this.request('get', 'groups');
};
/**
* Creates a group. This endpoint requires admin privileges
* https://www.redmine.org/projects/redmine/wiki/Rest_Groups#POST
*
* @param group
*/
Redmine.prototype.createGroup = function (group) {
return this.request('post', 'groups', { group: group });
};
/**
* Returns details of a group. This endpoint requires admin privileges
* https://www.redmine.org/projects/redmine/wiki/Rest_Groups#GET-2
*
* @param groupId
* @param params
*/
Redmine.prototype.getGroup = function (groupId, params) {
return this.request('get', "groups/" + groupId, { params: params });
};
/**
* Updates an existing group. This endpoint requires admin privileges
* https://www.redmine.org/projects/redmine/wiki/Rest_Groups#PUT
*
* @param groupId
* @param group
*/
Redmine.prototype.updateGroup = function (groupId, group) {
return this.request('put', "groups/" + groupId, { group: group });
};
/**
* Deletes an existing group. This endpoint requires admin privileges
* https://www.redmine.org/projects/redmine/wiki/Rest_Groups#DELETE
*
* @param groupId
*/
Redmine.prototype.deleteGroup = function (groupId) {
return this.request('delete', "groups/" + groupId);
};
/**
* Adds an existing user to a group. This endpoint requires admin privileges
* https://www.redmine.org/projects/redmine/wiki/Rest_Groups#POST-2
*
* @param userId
* @param groupId
*/
Redmine.prototype.addUserToGroup = function (userId, groupId) {
return this.request('post', "groups/" + groupId + "/users", {
user_id: userId
});
};
/**
* Removes a user from a group. This endpoint requires admin privileges
* https://www.redmine.org/projects/redmine/wiki/Rest_Groups#DELETE-2
*
* @param userId
* @param groupId
*/
Redmine.prototype.removeUserFromGroup = function (userId, groupId) {
return this.request('delete', "groups/" + groupId + "/users/" + userId);
};
// ==================== CUSTOM FIELDS ====================
/**
* Returns all the custom fields definitions
* https://www.redmine.org/projects/redmine/wiki/Rest_CustomFields#custom_fieldsformat
*/
Redmine.prototype.listCustomFields = function () {
return this.request('get', 'custom_fields');
};
// ==================== SEARCH ====================
/**
* Search in Redmine (Not documented yet - details in https://www.redmine.org/issues/6277)
* https://www.redmine.org/projects/redmine/wiki/Rest_Search
*
* @param q
* @param additionalParams
*/
Redmine.prototype.search = function (q, additionalParams) {
return this.request('get', 'search', {
params: __assign({ q: q }, additionalParams)
});
};
// ==================== FILES ====================
/**
* Returns the files available for the project of given id or identifier
* https://www.redmine.org/projects/redmine/wiki/Rest_Files#GET
*
* @param projectId
*/
Redmine.prototype.listProjectFiles = function (projectId) {
return this.request('get', "projects/" + projectId + "/files");
};
/**
* Upload a file for the project of given id or identifier
* https://www.redmine.org/projects/redmine/wiki/Rest_Files#POST
*
* @param projectId
* @param file
*/
Redmine.prototype.addProjectFile = function (projectId, file) {
return this.request('post', "projects/" + projectId + "/files", { file: file });
};
// ==================== MY ACCOUNT ====================
/**
* Returns the details of your account.
* https://www.redmine.org/projects/redmine/wiki/Rest_MyAccount#GET
*/
Redmine.prototype.getMyAccount = function () {
return this.request('get', 'my/account');
};
Redmine.prototype.updateMyAccount = function (user) {
return this.request('put', 'my/account', { user: user });
};
return Redmine;
}());
exports.Redmine = Redmine;