feat: add updateEmail

This commit is contained in:
Derrick Hammer 2024-03-19 07:58:32 -04:00
parent 5b04f7ecaf
commit c0345dec11
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 23 additions and 2 deletions

View File

@ -28,8 +28,9 @@ import {
postApiAccountPasswordResetConfirm, postApiAccountPasswordResetConfirm,
postApiAuthLogout, postApiAuthLogout,
getApiUploadLimit, getApiUploadLimit,
postApiAccountUpdateEmail,
} from "./account/generated/index.js"; } from "./account/generated/index.js";
import { AxiosResponse } from "axios"; import { AxiosError, AxiosResponse } from "axios";
export class AccountApi { export class AccountApi {
private apiUrl: string; private apiUrl: string;
@ -111,7 +112,10 @@ export class AccountApi {
public async verifyOtp(otpVerifyRequest: OTPVerifyRequest): Promise<boolean> { public async verifyOtp(otpVerifyRequest: OTPVerifyRequest): Promise<boolean> {
let ret: AxiosResponse<void>; let ret: AxiosResponse<void>;
try { try {
ret = await postApiAccountOtpVerify(otpVerifyRequest, this.buildOptions()); ret = await postApiAccountOtpVerify(
otpVerifyRequest,
this.buildOptions(),
);
} catch (e) { } catch (e) {
return false; return false;
} }
@ -226,6 +230,23 @@ export class AccountApi {
return this.checkSuccessVal<UploadLimitResponse>(ret) ? ret.data.limit : 0; return this.checkSuccessVal<UploadLimitResponse>(ret) ? ret.data.limit : 0;
} }
public async updateEmail(
email: string,
password: string,
): Promise<boolean | Error> {
let ret: AxiosResponse<void>;
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<void>): boolean { private checkSuccessBool(ret: AxiosResponse<void>): boolean {
return ret.status === 200; return ret.status === 200;
} }