From bfe8847d72cd0893230f2e654242658214943e61 Mon Sep 17 00:00:00 2001 From: Markus Hatvan Date: Sat, 2 Oct 2021 09:24:32 +0200 Subject: chore: convert various files from JS to TS (#2010) --- src/api/UserApi.ts | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 src/api/UserApi.ts (limited to 'src/api/UserApi.ts') diff --git a/src/api/UserApi.ts b/src/api/UserApi.ts new file mode 100644 index 000000000..31c8acead --- /dev/null +++ b/src/api/UserApi.ts @@ -0,0 +1,58 @@ +import { BinaryLike } from 'crypto'; +import { hash } from '../helpers/password-helpers'; + +export default class UserApi { + server: any; + + local: any; + + constructor(server: any, local: any) { + this.server = server; + this.local = local; + } + + login(email: string, password: BinaryLike) { + return this.server.login(email, hash(password)); + } + + logout() { + return this; + } + + signup(data: { password: BinaryLike }) { + Object.assign(data, { + password: hash(data.password), + }); + return this.server.signup(data); + } + + password(email: string) { + return this.server.retrievePassword(email); + } + + invite(data: any) { + return this.server.inviteUser(data); + } + + getInfo() { + return this.server.userInfo(); + } + + updateInfo(data: { oldPassword: string; newPassword: string }) { + const userData = data; + if (userData.oldPassword && userData.newPassword) { + userData.oldPassword = hash(userData.oldPassword); + userData.newPassword = hash(userData.newPassword); + } + + return this.server.updateUserInfo(userData); + } + + getLegacyServices() { + return this.server.getLegacyServices(); + } + + delete() { + return this.server.deleteAccount(); + } +} -- cgit v1.2.3-54-g00ecf