Fase 2: Gestión de Usuarios (CRUD Completo) - Backend & Frontend
This commit is contained in:
37
frontend/admin-panel/src/services/userService.ts
Normal file
37
frontend/admin-panel/src/services/userService.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import api from './api';
|
||||
// @ts-ignore
|
||||
import type { User } from '../types/User';
|
||||
|
||||
interface CreateUserDto {
|
||||
username: string;
|
||||
password: string;
|
||||
role: string;
|
||||
email?: string;
|
||||
}
|
||||
|
||||
interface UpdateUserDto {
|
||||
username: string;
|
||||
password?: string;
|
||||
role: string;
|
||||
email?: string;
|
||||
}
|
||||
|
||||
export const userService = {
|
||||
getAll: async (): Promise<User[]> => {
|
||||
const response = await api.get<User[]>('/users');
|
||||
// @ts-ignore
|
||||
return response.data;
|
||||
},
|
||||
|
||||
create: async (user: CreateUserDto): Promise<void> => {
|
||||
await api.post('/users', user);
|
||||
},
|
||||
|
||||
update: async (id: number, user: UpdateUserDto): Promise<void> => {
|
||||
await api.put(`/users/${id}`, user);
|
||||
},
|
||||
|
||||
delete: async (id: number): Promise<void> => {
|
||||
await api.delete(`/users/${id}`);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user