import { useApi } from '~/composables/useApi' import type { UserData } from '~/services/dto/user-data' import type {UserPayload} from "~/services/dto/user-data"; export async function getUsers() { const api = useApi() const data = await api.get('users', {}, { toastErrorKey: 'errors.auth.users' }) if (Array.isArray(data)) { return data } return data['hydra:member'] ?? [] } export async function getAdminUsers() { const api = useApi() const data = await api.get('admin/users', {}, { toastErrorKey: 'errors.auth.users' }) if (Array.isArray(data)) { return data } return data['hydra:member'] ?? [] } export async function getUser(id: number) { const api = useApi() return api.get(`users/${id}`, {}, { toastErrorKey: 'errors.auth.user' }) } export async function createUser(payload: UserPayload = {}) { const api = useApi() return api.post('users', payload, { toastErrorKey: 'errors.auth.create', toastSuccessKey : 'success.auth.create' }) } export async function updateUser(id : number, playload: UserPayload = {}){ const api = useApi() return api.patch(`users/${id}`, playload, { toastErrorKey: 'errors.auth.update', toastSuccessKey: 'success.auth.update' }) } export async function getCurrentUser() { const api = useApi() return api.get('me', {}, { toast: false }) } export async function login(username: string, password: string) { const api = useApi() return api.post<{ token: string }>('login_check', { username, password }, { toastErrorKey: 'errors.auth.login', toastSuccessKey: 'success.auth.login' }) } export async function logout() { const api = useApi() return api.post('logout', {}, { toastErrorKey: 'errors.auth.logout', toastSuccessKey: 'success.auth.logout' }) }