Files
CoHaiSe-CLOUD/frontend/src/services/accountService.ts
T
Gitea ActionsandEsiah f689ab4d57
CD — Deployment / deploy (push) Successful in 34s
refactor: restructure frontend and backend by domain services (#26)
Split the monolithic backend (lib/, routes/, access.ts, storage.ts, media.ts)
into a layered structure inspired by JeanXXIII-CRM:
- config/: appConfig, db
- middleware/: auth (session, roles, cookies)
- models/: shared types
- routes/: *Routes.ts (thin HTTP handlers)
- services/: *Service.ts (business logic, one per domain)
- utils/: errors, http, migrate, ratelimit, validators, service bootstrap

Frontend likewise: services/*Service.ts + apiClient, contexts/, types/, utils/format.
Route files now carry the "Routes" suffix; service files are named
authService.ts, ratelimit.ts, etc. and live in their own files, frontend and
backend separated.

Updated docs and READMEs to reflect the new layout. Typecheck and builds pass.

---------

Co-authored-by: xEsiah <[email protected]>
Reviewed-on: #26
Reviewed-by: Esiah <[email protected]>
Co-authored-by: Gitea Actions <-[email protected]>
2026-11-13 09:13:27 +00:00

25 lines
1.5 KiB
TypeScript

import type { SessionInfo, Theme, Language } from "../types/index.js";
import { BASE, del, get, patch, post, putBinary } from "./apiClient.js";
export const accountService = {
forgotPassword: (email: string) => post<{ ok: boolean }>("/account/forgot-password", { email }),
resetPassword: (token: string, password: string) =>
post<{ ok: boolean }>("/account/reset-password", { token, password }),
requestEmailChange: (password: string, new_email: string) =>
post<{ ok: boolean }>("/account/email-change", { password, new_email }),
confirmEmailChange: (token: string) =>
post<{ ok: boolean; email: string }>("/account/email-change/confirm", { token }),
updateProfile: (first_name: string, last_name: string) =>
patch<{ ok: boolean }>("/account/profile", { first_name, last_name }),
preferences: () => get<{ theme: Theme; language: Language }>("/account/preferences"),
updatePreferences: (theme: Theme, language: Language) =>
patch<{ theme: Theme; language: Language }>("/account/preferences", { theme, language }),
sessions: () => get<{ sessions: SessionInfo[] }>("/account/sessions"),
revokeSession: (id: string) => del<{ ok: boolean }>(`/account/sessions/${encodeURIComponent(id)}`),
revokeOtherSessions: () => del<{ ok: boolean }>("/account/sessions"),
avatarUrl: (userId: string) => `${BASE}/account/avatar/${encodeURIComponent(userId)}`,
uploadAvatar: (file: File) => putBinary<{ ok: boolean }>("/account/avatar", file, file.type),
deleteAvatar: () => del<{ ok: boolean }>("/account/avatar"),
};