From a640703f2da8815dc26ad1600a6f206be1624379 Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Wed, 1 Jun 2022 22:10:32 +0200 Subject: feat: Initial after clean slate --- apps/web-shared/src/lib/api/user.ts | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 apps/web-shared/src/lib/api/user.ts (limited to 'apps/web-shared/src/lib/api/user.ts') diff --git a/apps/web-shared/src/lib/api/user.ts b/apps/web-shared/src/lib/api/user.ts new file mode 100644 index 0000000..a3a149e --- /dev/null +++ b/apps/web-shared/src/lib/api/user.ts @@ -0,0 +1,47 @@ +import {api_base} from "$shared/lib/configuration"; +import {http_delete, http_get, http_post} from "./internal-fetch"; +import type {LoginPayload} from "$shared/lib/models/LoginPayload"; +import type {UpdateProfilePayload} from "$shared/lib/models/UpdateProfilePayload"; +import type {CreateAccountPayload} from "$shared/lib/models/CreateAccountPayload"; +import type {IInternalFetchResponse} from "$shared/lib/models/IInternalFetchResponse"; + +export async function login(payload: LoginPayload): Promise { + return http_post(api_base("_/account/login"), payload); +} + +export async function logout(): Promise { + return http_get(api_base("_/account/logout")); +} + +export async function create_forgot_password_request(username: string): Promise { + if (!username) throw new Error("Username is empty"); + return http_get(api_base("_/forgot-password-requests/create?username=" + username)); +} + +export async function check_forgot_password_request(public_id: string): Promise { + if (!public_id) throw new Error("Id is empty"); + return http_get(api_base("_/forgot-password-requests/is-valid?id=" + public_id)); +} + +export async function fulfill_forgot_password_request(public_id: string, newPassword: string): Promise { + if (!public_id) throw new Error("Id is empty"); + return http_post(api_base("_/forgot-password-requests/fulfill"), {id: public_id, newPassword}); +} + +export async function delete_account(): Promise { + return http_delete(api_base("_/account/delete")); +} + +export async function update_profile(payload: UpdateProfilePayload): Promise { + if (!payload.password && !payload.username) throw new Error("Password and Username is empty"); + return http_post(api_base("_/account/update"), payload); +} + +export async function create_account(payload: CreateAccountPayload): Promise { + if (!payload.password && !payload.username) throw new Error("Password and Username is empty"); + return http_post(api_base("_/account/create"), payload); +} + +export async function get_profile_for_active_check(): Promise { + return http_get(api_base("_/account"), 0, true); +} -- cgit v1.3