From c0345dec11a0940f25dbd278b530f7480082a989 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 19 Mar 2024 07:58:32 -0400 Subject: [PATCH] feat: add updateEmail --- src/account.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/account.ts b/src/account.ts index 1b6e2f3..48e7a8b 100644 --- a/src/account.ts +++ b/src/account.ts @@ -28,8 +28,9 @@ import { postApiAccountPasswordResetConfirm, postApiAuthLogout, getApiUploadLimit, + postApiAccountUpdateEmail, } from "./account/generated/index.js"; -import { AxiosResponse } from "axios"; +import { AxiosError, AxiosResponse } from "axios"; export class AccountApi { private apiUrl: string; @@ -111,7 +112,10 @@ export class AccountApi { public async verifyOtp(otpVerifyRequest: OTPVerifyRequest): Promise { let ret: AxiosResponse; try { - ret = await postApiAccountOtpVerify(otpVerifyRequest, this.buildOptions()); + ret = await postApiAccountOtpVerify( + otpVerifyRequest, + this.buildOptions(), + ); } catch (e) { return false; } @@ -226,6 +230,23 @@ export class AccountApi { return this.checkSuccessVal(ret) ? ret.data.limit : 0; } + public async updateEmail( + email: string, + password: string, + ): Promise { + let ret: AxiosResponse; + try { + ret = await postApiAccountUpdateEmail( + { email, password }, + this.buildOptions(), + ); + } catch (e) { + return new Error((e as AxiosError).response.data as string); + } + + return this.checkSuccessBool(ret); + } + private checkSuccessBool(ret: AxiosResponse): boolean { return ret.status === 200; }