UNPKG

@itslanguage/api

Version:
72 lines (62 loc) 2.09 kB
import "core-js/modules/es.array.iterator"; import "core-js/modules/es.regexp.to-string"; import "core-js/modules/es.string.split"; import "core-js/modules/web.dom-collections.iterator"; import "core-js/modules/web.url"; /** * The progress of a category (or actually, challenges in a category) can be requested by a user. * * @see {@link https://itslanguage.github.io/itslanguage-docs/api/progress/index.html} * * @module api/progress */ import { authorisedRequest } from '../communication'; /** * The URL for the category handler(s) to query for progress. * @type {string} */ var url = '/categories'; /** * Get progress by its category id. * The progress is returned for the current user if only the id is passed. If groups and or a role * is passed it will return progress for all users from that group. * * @param {string} id - The category id. * @param {Array|string} [groups=[]] - The id's or id of the groups to get * progress on. * @param {string} [role=''] - The id of the role that a user should be in. * * @returns {Promise} - The promise for the organisation. */ // eslint-disable-next-line import/prefer-default-export export function getById(id, groups, role) { if (groups === void 0) { groups = []; } if (role === void 0) { role = ''; } var filters = ''; var searchParams = new URLSearchParams(); var groupIds = []; if (typeof groups === 'string') { groupIds = groups.split(); // convert 'STRING' to ['STRING']; } else if (Array.isArray(groups)) { groupIds = groups; } if (groupIds.length > 0) { // If we have groups, add them to the searchParams! groupIds.forEach(group => { searchParams.append('group', group); }); } if (role !== '') { // Do we role with a role? Add it to the searchParams! searchParams.append('role', role); } if (groupIds.length > 0 || role) { // If we had groups or roles, construct a querystring based on searchParams. filters = "?" + searchParams.toString(); } return authorisedRequest('GET', url + "/" + id + "/progress" + filters); }