feat : add User CRUD with admin management
Add User API operations (GET, POST, PATCH, DELETE) with password hashing processor, frontend service, drawer and admin tab. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,12 @@
|
||||
export type UserData = {
|
||||
id: number
|
||||
username: string
|
||||
roles: string[]
|
||||
id: number
|
||||
'@id'?: string
|
||||
username: string
|
||||
roles: string[]
|
||||
}
|
||||
|
||||
export type UserWrite = {
|
||||
username: string
|
||||
password?: string
|
||||
roles: string[]
|
||||
}
|
||||
|
||||
32
frontend/services/users.ts
Normal file
32
frontend/services/users.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { UserData, UserWrite } from './dto/user-data'
|
||||
import type { HydraCollection } from '~/utils/api'
|
||||
import { extractHydraMembers } from '~/utils/api'
|
||||
|
||||
export function useUserService() {
|
||||
const api = useApi()
|
||||
|
||||
async function getAll(): Promise<UserData[]> {
|
||||
const data = await api.get<HydraCollection<UserData>>('/users')
|
||||
return extractHydraMembers(data)
|
||||
}
|
||||
|
||||
async function create(payload: UserWrite): Promise<UserData> {
|
||||
return api.post<UserData>('/users', payload as Record<string, unknown>, {
|
||||
toastSuccessKey: 'users.created',
|
||||
})
|
||||
}
|
||||
|
||||
async function update(id: number, payload: Partial<UserWrite>): Promise<UserData> {
|
||||
return api.patch<UserData>(`/users/${id}`, payload as Record<string, unknown>, {
|
||||
toastSuccessKey: 'users.updated',
|
||||
})
|
||||
}
|
||||
|
||||
async function remove(id: number): Promise<void> {
|
||||
await api.delete(`/users/${id}`, {}, {
|
||||
toastSuccessKey: 'users.deleted',
|
||||
})
|
||||
}
|
||||
|
||||
return { getAll, create, update, remove }
|
||||
}
|
||||
Reference in New Issue
Block a user