[#321] Gestion des rôles dans l'application (#2)
All checks were successful
Auto Tag Develop / tag (push) Successful in 6s
All checks were successful
Auto Tag Develop / tag (push) Successful in 6s
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | #321 | Gestion des rôles dans l'application | ## Description de la PR [#321] Gestion des rôles dans l'application ## Modification du .env ## Check list - [x] Pas de régression - [ ] TU/TI/TF rédigée - [x] TU/TI/TF OK - [ ] CHANGELOG modifié Reviewed-on: #2 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
This commit was merged in pull request #2.
This commit is contained in:
57
frontend/services/users.ts
Normal file
57
frontend/services/users.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import type { User } from './dto/user'
|
||||
import { extractItems } from '~/utils/api'
|
||||
|
||||
export const listUsers = async () => {
|
||||
const api = useApi()
|
||||
const data = await api.get<User[] | { 'hydra:member'?: User[] }>(
|
||||
'/users',
|
||||
{},
|
||||
{ toast: false }
|
||||
)
|
||||
return extractItems<User>(data)
|
||||
}
|
||||
|
||||
export const createUser = async (payload: {
|
||||
username: string
|
||||
plainPassword: string
|
||||
roles: string[]
|
||||
employeeId?: number | null
|
||||
}) => {
|
||||
const api = useApi()
|
||||
return api.post<User>(
|
||||
'/users',
|
||||
{
|
||||
username: payload.username,
|
||||
plainPassword: payload.plainPassword,
|
||||
roles: payload.roles,
|
||||
employee: payload.employeeId ? `/api/employees/${payload.employeeId}` : null
|
||||
},
|
||||
{
|
||||
toastSuccessKey: 'success.user.create',
|
||||
toastErrorKey: 'errors.user.create'
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export const updateUser = async (id: number, payload: {
|
||||
username: string
|
||||
plainPassword?: string
|
||||
roles: string[]
|
||||
employeeId?: number | null
|
||||
}) => {
|
||||
const api = useApi()
|
||||
const body: Record<string, unknown> = {
|
||||
username: payload.username,
|
||||
roles: payload.roles,
|
||||
employee: payload.employeeId ? `/api/employees/${payload.employeeId}` : null
|
||||
}
|
||||
|
||||
if (payload.plainPassword) {
|
||||
body.plainPassword = payload.plainPassword
|
||||
}
|
||||
|
||||
return api.patch<User>(`/users/${id}`, body, {
|
||||
toastSuccessKey: 'success.user.update',
|
||||
toastErrorKey: 'errors.user.update'
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user