From d98aeab0c87a944f4f6e086e01ab0eb44bda7d53 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Wed, 20 Jun 2018 23:40:59 -0400 Subject: [PATCH] put profile --- src/abstractions/api.service.ts | 4 ++-- src/models/request/updateProfileRequest.ts | 10 +++++++++ src/services/api.service.ts | 25 ++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 src/models/request/updateProfileRequest.ts diff --git a/src/abstractions/api.service.ts b/src/abstractions/api.service.ts index cffb70f279..9f650c1a56 100644 --- a/src/abstractions/api.service.ts +++ b/src/abstractions/api.service.ts @@ -12,6 +12,7 @@ import { PasswordHintRequest } from '../models/request/passwordHintRequest'; import { RegisterRequest } from '../models/request/registerRequest'; import { TokenRequest } from '../models/request/tokenRequest'; import { TwoFactorEmailRequest } from '../models/request/twoFactorEmailRequest'; +import { UpdateProfileRequest } from '../models/request/updateProfileRequest'; import { CipherResponse } from '../models/response/cipherResponse'; import { FolderResponse } from '../models/response/folderResponse'; @@ -20,8 +21,6 @@ import { IdentityTwoFactorResponse } from '../models/response/identityTwoFactorR import { ProfileResponse } from '../models/response/profileResponse'; import { SyncResponse } from '../models/response/syncResponse'; -import { AttachmentView } from '../models/view/attachmentView'; - export abstract class ApiService { urlsSet: boolean; apiBaseUrl: string; @@ -32,6 +31,7 @@ export abstract class ApiService { refreshIdentityToken: () => Promise; postTwoFactorEmail: (request: TwoFactorEmailRequest) => Promise; getProfile: () => Promise; + putProfile: (request: UpdateProfileRequest) => Promise; getAccountRevisionDate: () => Promise; postPasswordHint: (request: PasswordHintRequest) => Promise; postRegister: (request: RegisterRequest) => Promise; diff --git a/src/models/request/updateProfileRequest.ts b/src/models/request/updateProfileRequest.ts new file mode 100644 index 0000000000..e029f3f783 --- /dev/null +++ b/src/models/request/updateProfileRequest.ts @@ -0,0 +1,10 @@ +export class UpdateProfileRequest { + name: string; + masterPasswordHint: string; + culture = 'en-US'; // deprecated + + constructor(name: string, masterPasswordHint: string) { + this.name = name; + this.masterPasswordHint = masterPasswordHint ? masterPasswordHint : null; + } +} diff --git a/src/services/api.service.ts b/src/services/api.service.ts index 0e7fe20833..747904ec11 100644 --- a/src/services/api.service.ts +++ b/src/services/api.service.ts @@ -18,6 +18,7 @@ import { PasswordHintRequest } from '../models/request/passwordHintRequest'; import { RegisterRequest } from '../models/request/registerRequest'; import { TokenRequest } from '../models/request/tokenRequest'; import { TwoFactorEmailRequest } from '../models/request/twoFactorEmailRequest'; +import { UpdateProfileRequest } from '../models/request/updateProfileRequest'; import { CipherResponse } from '../models/response/cipherResponse'; import { ErrorResponse } from '../models/response/errorResponse'; @@ -172,6 +173,30 @@ export class ApiService implements ApiServiceAbstraction { } } + async putProfile(request: UpdateProfileRequest): Promise { + const authHeader = await this.handleTokenState(); + const response = await fetch(new Request(this.apiBaseUrl + '/accounts/profile', { + body: JSON.stringify(request), + cache: 'no-cache', + credentials: this.getCredentials(), + headers: new Headers({ + 'Accept': 'application/json', + 'Content-Type': 'application/json; charset=utf-8', + 'Authorization': authHeader, + 'Device-Type': this.deviceType, + }), + method: 'PUT', + })); + + if (response.status === 200) { + const responseJson = await response.json(); + return new ProfileResponse(responseJson); + } else { + const error = await this.handleError(response, false); + return Promise.reject(error); + } + } + async getAccountRevisionDate(): Promise { const authHeader = await this.handleTokenState(); const response = await fetch(new Request(this.apiBaseUrl + '/accounts/revision-date', {