diff --git a/ui/src/stores/useAsistencias.js b/ui/src/stores/useAsistencias.js index d89883f..7d64062 100644 --- a/ui/src/stores/useAsistencias.js +++ b/ui/src/stores/useAsistencias.js @@ -48,8 +48,9 @@ export const useAsistenciasStore = defineStore('asistencias', { // If asistenciaData.entrada/salida are Date objects, convert them: // if (asistenciaData.entrada instanceof Date) asistenciaData.entrada = asistenciaData.entrada.toISOString(); // if (asistenciaData.salida instanceof Date) asistenciaData.salida = asistenciaData.salida.toISOString(); - await apiClient.post('/api/asistencias', asistenciaData); + const {data} = await apiClient.post('/api/asistencias', asistenciaData); await this.fetchAsistencias(); // Refresh the list + return data; } catch (error) { console.error('Error creating asistencia:', error); throw error; // Re-throw to allow form to handle it @@ -61,9 +62,10 @@ export const useAsistenciasStore = defineStore('asistencias', { // Similar date conversion logic as in createAsistencia if needed // if (asistenciaData.entrada instanceof Date) asistenciaData.entrada = asistenciaData.entrada.toISOString(); // if (asistenciaData.salida instanceof Date) asistenciaData.salida = asistenciaData.salida.toISOString(); - await apiClient.put(`/api/asistencias/${id}`, asistenciaData); + const {data} = await apiClient.put(`/api/asistencias/${id}`, asistenciaData); await this.fetchAsistencias(); // Refresh the list this.currentAsistencia = getDefaultCurrentAsistencia(); // Reset currentAsistencia + return data; } catch (error) { console.error(`Error updating asistencia with id ${id}:`, error); throw error; // Re-throw to allow form to handle it diff --git a/ui/src/stores/usePlanillas.js b/ui/src/stores/usePlanillas.js index 3025e0e..b415fad 100644 --- a/ui/src/stores/usePlanillas.js +++ b/ui/src/stores/usePlanillas.js @@ -1,81 +1,79 @@ -import { defineStore } from 'pinia'; -import apiClient from '../apiClient'; // Assuming apiClient is configured for API calls +import { defineStore } from 'pinia' +import apiClient from '../apiClient' + +// 🎛 helper para valores por defecto +const getDefaultCurrentPlanilla = () => ({ + id: null, + fecha_desde: null, + fecha_hasta: null, + titulo: '', + total: null, + estado: 'pagado', + fecha_anulado: null, + empleado_id: null, +}) export const usePlanillasStore = defineStore('planillas', { state: () => ({ planillas: [], - currentPlanilla: { - id: null, - fecha_desde: null, - fecha_hasta: null, - titulo: '', - total: null, - estado: 'pagado', // Default value from schema - fecha_anulado: null, - empleado_id: null, - // Empleado relation is not included here, will be handled by ID. - }, + currentPlanilla: getDefaultCurrentPlanilla(), }), + actions: { async fetchPlanillas() { try { - const response = await apiClient.get('/api/planillas'); - this.planillas = response.data; - } catch (error) { - console.error('Error fetching planillas:', error); - // Handle error (e.g., show a notification to the user) + const { data } = await apiClient.get('/api/planillas') + this.planillas = data + } catch (e) { + console.error('Error fetching planillas:', e) } }, async fetchPlanillaById(id) { try { - const response = await apiClient.get(`/api/planillas/${id}`); - this.currentPlanilla = response.data; - } catch (error) { - console.error(`Error fetching planilla with id ${id}:`, error); - // Handle error + const { data } = await apiClient.get(`/api/planillas/${id}`) + this.currentPlanilla = data + } catch (e) { + console.error(`Error fetching planilla ${id}:`, e) + this.currentPlanilla = getDefaultCurrentPlanilla() } }, async createPlanilla(planillaData) { try { - await apiClient.post('/api/planillas', planillaData); - await this.fetchPlanillas(); // Refresh the list - } catch (error) { - console.error('Error creating planilla:', error); - // Handle error + const { data } = await apiClient.post('/api/planillas', planillaData) + await this.fetchPlanillas() + return data + } catch (e) { + console.error('Error creating planilla:', e) + throw e } }, async updatePlanilla(id, planillaData) { try { - await apiClient.put(`/api/planillas/${id}`, planillaData); - await this.fetchPlanillas(); // Refresh the list - this.currentPlanilla = { // Reset currentPlanilla - id: null, - fecha_desde: null, - fecha_hasta: null, - titulo: '', - total: null, - estado: 'pagado', - fecha_anulado: null, - empleado_id: null, - }; - } catch (error) { - console.error(`Error updating planilla with id ${id}:`, error); - // Handle error + const { data } = await apiClient.put(`/api/planillas/${id}`, planillaData) + await this.fetchPlanillas() + this.clearCurrentPlanilla() + return data + } catch (e) { + console.error(`Error updating planilla ${id}:`, e) + throw e } }, async deletePlanilla(id) { try { - await apiClient.delete(`/api/planillas/${id}`); - await this.fetchPlanillas(); // Refresh the list - } catch (error) - { - console.error(`Error deleting planilla with id ${id}:`, error); - // Handle error + await apiClient.delete(`/api/planillas/${id}`) + await this.fetchPlanillas() + } catch (e) { + console.error(`Error deleting planilla ${id}:`, e) + throw e } }, + + clearCurrentPlanilla() { + this.currentPlanilla = getDefaultCurrentPlanilla() + }, }, -}); +}) diff --git a/ui/src/stores/useTareas.js b/ui/src/stores/useTareas.js index 145088e..0866087 100644 --- a/ui/src/stores/useTareas.js +++ b/ui/src/stores/useTareas.js @@ -43,8 +43,9 @@ export const useTareasStore = defineStore('tareas', { async createTarea(tareaData) { try { - await apiClient.post('/api/tareas', tareaData); + const { data } = await apiClient.post('/api/tareas', tareaData); await this.fetchTareas(); // Refresh the list + return data; // Return created tarea data if needed } catch (error) { console.error('Error creating tarea:', error); throw error; // Re-throw to allow form to handle it @@ -53,9 +54,10 @@ export const useTareasStore = defineStore('tareas', { async updateTarea(id, tareaData) { try { - await apiClient.put(`/api/tareas/${id}`, tareaData); + const { data } = await apiClient.put(`/api/tareas/${id}`, tareaData); await this.fetchTareas(); // Refresh the list this.currentTarea = getDefaultCurrentTarea(); // Reset currentTarea + return data; // Return updated tarea data if needed } catch (error) { console.error(`Error updating tarea with id ${id}:`, error); throw error; // Re-throw to allow form to handle it