From 3e11b87eee3bf7c0ac8468e6a303790dc3956e64 Mon Sep 17 00:00:00 2001 From: pavel Hamawand Date: Thu, 21 Mar 2024 01:58:57 +0100 Subject: [PATCH] Modify the implementation of the changeUserName method in the api object --- frontend/src/API/API.ts | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index a39ce9b..70e36c9 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -497,12 +497,28 @@ export const api: API = { }); } }, - changeUserName: function ( - // eslint-disable-next-line @typescript-eslint/no-unused-vars - _data: StrNameChange, - // eslint-disable-next-line @typescript-eslint/no-unused-vars + + async changeUserName( + data: StrNameChange, token: string, ): Promise> { - throw new Error("Function not implemented."); + try { + const response = await fetch("/api/changeUserName", { + method: "PUT", + headers: { + "Content-Type": "application/json", + Authorization: "Bearer " + token, + }, + body: JSON.stringify(data), + }); + + if (!response.ok) { + return { success: false, message: "Failed to change username" }; + } else { + return { success: true }; + } + } catch (e) { + return { success: false, message: "Failed to change username" }; + } }, };