Skip to content

Commit

Permalink
Merge #50: New API endpoint for listing users
Browse files Browse the repository at this point in the history
83df258 feat: release 3.1.0 (Mario)
d2e6b72 feat: [#49] new types for pagination (Mario)
fca2b0c feat: [#49] new function to get the list of user profiles (Mario)

Pull request description:

  Resolves #49

ACKs for top commit:
  josecelano:
    ACK 83df258

Tree-SHA512: 475ff4f8fd0b1fa8d43be9ee1ab8e9d9871ca2469e94ec87e36437381c22bd03bbc30c14605b625725114ce353a939068ef5d006f7c928c480ba3348aa3df194
  • Loading branch information
josecelano committed Jan 22, 2025
2 parents 67bb2a7 + 83df258 commit 5019e24
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 11 deletions.
13 changes: 6 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -23,6 +23,6 @@
"typescript": "^5.2.2"
},
"dependencies": {
"torrust-index-types-lib": "^3.0.0"
"torrust-index-types-lib": "^3.1.0"
}
}
35 changes: 33 additions & 2 deletions src/modes/rest/resources/user.ts
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -41,6 +42,20 @@ type NewUser = {
user_id: number
}

type GetUserProfilesParams = {
pageSize: number
page: number
}

type GetUserProfilesResponseData = {
total: number
results: Array<UserProfile>
}

type GetUserProfilesResponse = {
data: GetUserProfilesResponseData
}

export class UserResource implements IRestResource {
client: Rest;

Expand Down Expand Up @@ -112,4 +127,20 @@ export class UserResource implements IRestResource {
return Promise.reject(err.response?.data?.error ?? err);
});
}
async getUserProfiles(params: GetUserProfilesParams): Promise<GetUserProfilesResponseData> {
return await fetchGet<GetUserProfilesResponse>(
`${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);
});
}
}

0 comments on commit 5019e24

Please sign in to comment.