Skip to content

Commit

Permalink
feat: [#44] new endpoint to change users passwords
Browse files Browse the repository at this point in the history
  • Loading branch information
josecelano committed Jun 3, 2024
1 parent 44c7c58 commit e762ab6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions src/modes/rest/resources/torrent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type UploadTorrentParams = {
category: string
description: string
tags: Array<number>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
file: any
}

Expand Down Expand Up @@ -102,6 +103,7 @@ export class TorrentResource implements IRestResource {
}

async deleteTorrent(infoHash: string): Promise<DeleteTorrentResponseData> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return await fetchDelete<any, DeleteTorrentResponse>(
`${this.client.apiBaseUrl}/torrent/${infoHash}`,
{},
Expand Down
23 changes: 23 additions & 0 deletions src/modes/rest/resources/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ type RegisterUserParams = {
confirm_password: string
}

type ChangePasswordParams = {
current_password: string
password: string
confirm_password: string
}

type Token = {
token: string
}
Expand Down Expand Up @@ -89,4 +95,21 @@ export class UserResource implements IRestResource {
return Promise.reject(err.response?.data?.error ?? err);
});
}

async changePassword(params: ChangePasswordParams, username: string): Promise<boolean> {
return await fetchPost<void>(
`${this.client.apiBaseUrl}/user/${username}/change-password`,
JSON.stringify(params),
{
"Authorization": `Bearer ${this.client.authToken}`,
"Content-Type": "application/json"
}
)
.then(() => {
return Promise.resolve(true);
})
.catch((err) => {
return Promise.reject(err.response?.data?.error ?? err);
});
}
}

0 comments on commit e762ab6

Please sign in to comment.