Skip to content

Commit

Permalink
feat: [#49] new function to get the list of user profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mario-nt committed Jan 16, 2025
1 parent 67bb2a7 commit fca2b0c
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 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,10 @@ type NewUser = {
user_id: number
}

type GetUserProfilesResponse = {
data: Array<UserProfile>
}

export class UserResource implements IRestResource {
client: Rest;

Expand Down Expand Up @@ -112,4 +117,20 @@ export class UserResource implements IRestResource {
return Promise.reject(err.response?.data?.error ?? err);
});
}
async getUserProfiles(): Promise<Array<UserProfile>> {
return await fetchGet<GetUserProfilesResponse>(
`${this.client.apiBaseUrl}/users`,
{
"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 fca2b0c

Please sign in to comment.