All checks were successful
Auto Tag Develop / tag (push) Successful in 7s
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [ ] Pas de régression - [ ] TU/TI/TF rédigée - [ ] TU/TI/TF OK - [ ] CHANGELOG modifié Reviewed-on: #40 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
72 lines
1.9 KiB
TypeScript
72 lines
1.9 KiB
TypeScript
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<UserData[] | { 'hydra:member': UserData[] }>('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<UserData[] | { 'hydra:member': UserData[] }>('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<UserData>(`users/${id}`, {}, {
|
|
toastErrorKey: 'errors.auth.user'
|
|
})
|
|
}
|
|
|
|
export async function createUser(payload: UserPayload = {}) {
|
|
const api = useApi()
|
|
return api.post<UserData>('users', payload, {
|
|
toastErrorKey: 'errors.auth.create',
|
|
toastSuccessKey : 'success.auth.create'
|
|
})
|
|
}
|
|
|
|
export async function updateUser(id : number, playload: UserPayload = {}){
|
|
const api = useApi()
|
|
return api.patch<UserData>(`users/${id}`, playload, {
|
|
toastErrorKey: 'errors.auth.update',
|
|
toastSuccessKey: 'success.auth.update'
|
|
})
|
|
}
|
|
export async function getCurrentUser() {
|
|
const api = useApi()
|
|
return api.get<UserData>('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<void>('logout', {}, {
|
|
toastErrorKey: 'errors.auth.logout',
|
|
toastSuccessKey: 'success.auth.logout'
|
|
})
|
|
}
|