From e762ab600e4e664ff7cc05830cf99f7c5bd62005 Mon Sep 17 00:00:00 2001 From: Jose Celano Date: Mon, 3 Jun 2024 19:36:52 +0100 Subject: [PATCH] feat: [#44] new endpoint to change users passwords --- package-lock.json | 4 ++-- src/modes/rest/resources/torrent.ts | 2 ++ src/modes/rest/resources/user.ts | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index f272fa3..0371411 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "torrust-index-api-lib", - "version": "1.0.0-alpha.5", + "version": "1.0.0-alpha.6", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "torrust-index-api-lib", - "version": "1.0.0-alpha.5", + "version": "1.0.0-alpha.6", "license": "SEE LICENSE IN COPYRIGHT", "dependencies": { "torrust-index-types-lib": "^1.0.0-alpha.5" diff --git a/src/modes/rest/resources/torrent.ts b/src/modes/rest/resources/torrent.ts index 7bb1eb8..70b5854 100644 --- a/src/modes/rest/resources/torrent.ts +++ b/src/modes/rest/resources/torrent.ts @@ -51,6 +51,7 @@ type UploadTorrentParams = { category: string description: string tags: Array + // eslint-disable-next-line @typescript-eslint/no-explicit-any file: any } @@ -102,6 +103,7 @@ export class TorrentResource implements IRestResource { } async deleteTorrent(infoHash: string): Promise { + // eslint-disable-next-line @typescript-eslint/no-explicit-any return await fetchDelete( `${this.client.apiBaseUrl}/torrent/${infoHash}`, {}, diff --git a/src/modes/rest/resources/user.ts b/src/modes/rest/resources/user.ts index 0a9b740..cadfb1f 100644 --- a/src/modes/rest/resources/user.ts +++ b/src/modes/rest/resources/user.ts @@ -23,6 +23,12 @@ type RegisterUserParams = { confirm_password: string } +type ChangePasswordParams = { + current_password: string + password: string + confirm_password: string +} + type Token = { token: string } @@ -89,4 +95,21 @@ export class UserResource implements IRestResource { return Promise.reject(err.response?.data?.error ?? err); }); } + + async changePassword(params: ChangePasswordParams, username: string): Promise { + return await fetchPost( + `${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); + }); + } }