diff --git a/package-lock.json b/package-lock.json index 114c187..59a43ed 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "torrust-index-api-lib", - "version": "3.0.0", + "version": "3.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "torrust-index-api-lib", - "version": "3.0.0", + "version": "3.1.0", "license": "SEE LICENSE IN COPYRIGHT", "dependencies": { - "torrust-index-types-lib": "^3.0.0" + "torrust-index-types-lib": "^3.1.0" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^6.7.4", @@ -1663,10 +1663,9 @@ } }, "node_modules/torrust-index-types-lib": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/torrust-index-types-lib/-/torrust-index-types-lib-3.0.0.tgz", - "integrity": "sha512-Jfi3tOLP9btSXHlUivIMQhkpfYj2hzFS8bGliGCV6QC6eYvUkzQwNqwMfNtwRrhcqrJ0tyU9R74qGG2rIJ9n7Q==", - "license": "SEE LICENSE IN COPYRIGHT" + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/torrust-index-types-lib/-/torrust-index-types-lib-3.1.0.tgz", + "integrity": "sha512-88V7IUbwyLoD5ZvzVmVHSJEB/ZK6OhmdXegpWdt8uEVAofs4ipRoRuphdFObTX1X1YCTN7OExBw/QXzhCo+WUA==" }, "node_modules/ts-api-utils": { "version": "1.3.0", diff --git a/package.json b/package.json index 46ed2a7..40a1f53 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "torrust-index-api-lib", - "version": "3.0.0", + "version": "3.1.0", "description": "Contains API functions for the Torrust project.", "repository": { "type": "git", @@ -23,6 +23,6 @@ "typescript": "^5.2.2" }, "dependencies": { - "torrust-index-types-lib": "^3.0.0" + "torrust-index-types-lib": "^3.1.0" } } \ No newline at end of file diff --git a/src/modes/rest/resources/user.ts b/src/modes/rest/resources/user.ts index cadfb1f..9fa5373 100644 --- a/src/modes/rest/resources/user.ts +++ b/src/modes/rest/resources/user.ts @@ -1,7 +1,8 @@ import {Rest} from "../rest"; import {IRestResource} from "../restResource"; -import {fetchPost} from "../../../utils/fetch"; -import {TokenResponse} from "torrust-index-types-lib"; +import {fetchGet, fetchPost} from "../../../utils/fetch"; +import { TokenResponse, UserProfile } from "torrust-index-types-lib"; + type LoginUserParams = { login: string @@ -41,6 +42,20 @@ type NewUser = { user_id: number } +type GetUserProfilesParams = { + pageSize: number + page: number +} + +type GetUserProfilesResponseData = { + total: number + results: Array +} + +type GetUserProfilesResponse = { + data: GetUserProfilesResponseData +} + export class UserResource implements IRestResource { client: Rest; @@ -112,4 +127,20 @@ export class UserResource implements IRestResource { return Promise.reject(err.response?.data?.error ?? err); }); } + async getUserProfiles(params: GetUserProfilesParams): Promise { + return await fetchGet( + `${this.client.apiBaseUrl}/users?page_size=${params.pageSize}&page=${params.page - 1}`, + { + "Authorization": `Bearer ${this.client.authToken}`, + "Content-Type": "application/json" + } + ) + .then((res) => { + return Promise.resolve(res.data); + }) + .catch((err) => { + return Promise.reject(err.response?.data?.error ?? err); + }); + } } +