diff --git a/src/components/layout/Sidebar.vue b/src/components/layout/Sidebar.vue index 70398b7..2ab5cd1 100644 --- a/src/components/layout/Sidebar.vue +++ b/src/components/layout/Sidebar.vue @@ -48,6 +48,14 @@ const menuItems = ref([ label: 'Configuración', icon: 'pi pi-cog', to: '/configuracion' + }, + { + label: 'Usuarios y Roles', + icon: 'pi pi-users', + items: [ + { label: 'Usuarios', icon: 'pi pi-user', to: '/users' }, + { label: 'Roles', icon: 'pi pi-shield', to: '/users/roles' } + ] } ]); diff --git a/src/modules/users/components/RoleForm.vue b/src/modules/users/components/RoleForm.vue new file mode 100644 index 0000000..4f79518 --- /dev/null +++ b/src/modules/users/components/RoleForm.vue @@ -0,0 +1,113 @@ + + + + + diff --git a/src/modules/users/components/RoleIndex.vue b/src/modules/users/components/RoleIndex.vue new file mode 100644 index 0000000..dc23e36 --- /dev/null +++ b/src/modules/users/components/RoleIndex.vue @@ -0,0 +1,403 @@ + + + + + \ No newline at end of file diff --git a/src/modules/users/components/index.html b/src/modules/users/components/index.html new file mode 100644 index 0000000..b74e78a --- /dev/null +++ b/src/modules/users/components/index.html @@ -0,0 +1,214 @@ +
+ + + +
+ +
+
+

Permisos para Administrador General *

+

Hay cambios sin guardar

+
+
+ + +
+
+ +
+ +
+
+

Módulo de Ventas (POS)

+ +
+
+ +
+

Acceso al TPV

+ +
+
+

Crear Ventas

+ +
+
+

Aplicar Descuentos

+ +
+
+

Realizar Devoluciones

+ +
+
+

Anular Tickets

+ +
+
+
+ +
+
+

Módulo de Inventario

+ +
+
+
+

Ver Productos

+ +
+
+

Crear/Editar Productos

+ +
+
+

Ajustes de Stock

+ +
+
+

Gestionar Proveedores

+ +
+
+
+ +
+
+

Módulo de Reportes

+ +
+
+
+

Acceder a Reportes

+ +
+
+

Ver Dashboard

+ +
+
+

Exportar Datos

+ +
+
+
+
+
+
\ No newline at end of file diff --git a/src/modules/users/services/roleService.ts b/src/modules/users/services/roleService.ts new file mode 100644 index 0000000..f817db4 --- /dev/null +++ b/src/modules/users/services/roleService.ts @@ -0,0 +1,65 @@ +import api from "../../../services/api" +import type { + Role, + RolePagination, + RoleResponse, + CreateRoleData, + UpdateRoleData, + SingleRoleResponse, + ApiError +} from '../types/role' + +export const roleService = { + async getAllRoles(page = 1, perPage = 25) { + try { + console.log('🔍 Fetching roles from API...'); + const response = await api.get('/api/admin/roles', { + params: { + page, + per_page: perPage + } + }); + console.log('✅ Roles fetched successfully:', response.data); + return response; + } catch (error) { + console.error('❌ Error fetching roles:', error); + throw error; + } + }, + + async createRole(data: CreateRoleData) { + try { + console.log('🔍 Creating role...', data); + const response = await api.post('/api/admin/roles', data); + console.log('✅ Role created successfully:', response.data); + return response; + } catch (error) { + console.error('❌ Error creating role:', error); + throw error; + } + }, + + async updateRole(id: number, data: UpdateRoleData) { + try { + console.log('🔍 Updating role...', { id, data }); + const response = await api.put(`/api/admin/roles/${id}`, data); + console.log('✅ Role updated successfully:', response.data); + return response; + } catch (error) { + console.error('❌ Error updating role:', error); + throw error; + } + }, + + async deleteRole(id: number) { + try { + console.log('🔍 Deleting role...', { id }); + const response = await api.delete(`/api/admin/roles/${id}`); + console.log('✅ Role deleted successfully:', response.data); + return response; + } catch (error) { + console.error('❌ Error deleting role:', error); + throw error; + } + } +} \ No newline at end of file diff --git a/src/modules/users/types/role.d.ts b/src/modules/users/types/role.d.ts new file mode 100644 index 0000000..7e80591 --- /dev/null +++ b/src/modules/users/types/role.d.ts @@ -0,0 +1,59 @@ +// Base Role interface +export interface Role { + id: number; + name: string; + guard_name: string; + description: string; + created_at: string; + updated_at: string; +} + +// Pagination interfaces +export interface RolePagination { + current_page: number; + data: Role[]; + first_page_url: string; + from: number; + last_page: number; + last_page_url: string; + links: Array<{url: string | null; label: string; active: boolean}>; + next_page_url: string | null; + path: string; + per_page: number; + prev_page_url: string | null; + to: number; + total: number; +} + +// API Response interfaces +export interface RoleResponse { + status: string; + data: { + models: RolePagination; + }; +} + +export interface SingleRoleResponse { + status: string; + data: { + model: Role; + }; +} + +// Form data interfaces +export interface CreateRoleData { + description: string; +} + +export interface UpdateRoleData { + description: string; +} + +// Error handling interface +export interface ApiError { + status: string; + message: string; + errors: { + [key: string]: string[]; + }; +} \ No newline at end of file diff --git a/src/router/index.ts b/src/router/index.ts index 893da1f..ffc8beb 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -14,6 +14,9 @@ import ProductsIndex from '../modules/products/components/ProductsIndex.vue'; import ProductForm from '../modules/products/components/ProductForm.vue'; import StoresIndex from '../modules/stores/components/StoresIndex.vue'; +import RolesIndex from '../modules/users/components/RoleIndex.vue'; +import RoleForm from '../modules/users/components/RoleForm.vue'; + const routes: RouteRecordRaw[] = [ { path: '/login', @@ -151,6 +154,35 @@ const routes: RouteRecordRaw[] = [ title: 'Tiendas', requiresAuth: true }, + }, + { + path: 'users', + name: 'Usuarios', + + meta: { + title: 'Roles', + requiresAuth: true + }, + children: [ + { + path: 'roles', + name: 'Roles', + component: RolesIndex, + meta: { + title: 'Roles', + requiresAuth: true + } + }, + { + path: 'roles/permissions/:id', + name: 'RolePermissions', + component: RoleForm, + meta: { + title: 'Administrar Permisos', + requiresAuth: true + } + }, + ] } ] },