Modify the implementation of the changeUserName method in the api object

This commit is contained in:
pavel Hamawand 2024-03-21 01:58:57 +01:00
parent 9e2a3cca81
commit 3e11b87eee

View file

@ -497,12 +497,28 @@ export const api: API = {
}); });
} }
}, },
changeUserName: function (
// eslint-disable-next-line @typescript-eslint/no-unused-vars async changeUserName(
_data: StrNameChange, data: StrNameChange,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
token: string, token: string,
): Promise<APIResponse<void>> { ): Promise<APIResponse<void>> {
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" };
}
}, },
}; };