Jules was unable to complete the task in time. Please review the work done so far and provide feedback for Jules to continue.

This commit is contained in:
google-labs-jules[bot]
2025-05-30 06:41:49 +00:00
parent 2c43538db3
commit fe014b677b
15 changed files with 2563 additions and 24 deletions

View File

@@ -1,5 +1,80 @@
import { defineStore } from 'pinia'
import { defineStore } from 'pinia';
import apiClient from '../apiClient'; // Assuming apiClient is configured
export const useTareas = defineStore('tareas', {
state: () => ({ tareas: [] }),
})
// Helper function to get default values for currentTarea
const getDefaultCurrentTarea = () => ({
id: null,
empleado_id: null,
planilla_id: null, // Optional
titulo: '',
precio: null, // Optional
estado: 'pendiente', // Default from schema
observacion: '', // Optional
fecha: null, // Should be a date
tipo: '', // Default from schema
// fecha_anulado is not typically part of creation/edit form directly
});
export const useTareasStore = defineStore('tareas', {
state: () => ({
tareas: [],
currentTarea: getDefaultCurrentTarea(),
}),
actions: {
async fetchTareas() {
try {
const response = await apiClient.get('/api/tareas');
this.tareas = response.data;
} catch (error) {
console.error('Error fetching tareas:', error);
// Consider more sophisticated error handling (e.g., user notifications)
}
},
async fetchTareaById(id) {
try {
const response = await apiClient.get(`/api/tareas/${id}`);
this.currentTarea = response.data;
} catch (error) {
console.error(`Error fetching tarea with id ${id}:`, error);
this.currentTarea = getDefaultCurrentTarea(); // Reset on error
}
},
async createTarea(tareaData) {
try {
await apiClient.post('/api/tareas', tareaData);
await this.fetchTareas(); // Refresh the list
} catch (error) {
console.error('Error creating tarea:', error);
throw error; // Re-throw to allow form to handle it
}
},
async updateTarea(id, tareaData) {
try {
await apiClient.put(`/api/tareas/${id}`, tareaData);
await this.fetchTareas(); // Refresh the list
this.currentTarea = getDefaultCurrentTarea(); // Reset currentTarea
} catch (error) {
console.error(`Error updating tarea with id ${id}:`, error);
throw error; // Re-throw to allow form to handle it
}
},
async deleteTarea(id) {
try {
await apiClient.delete(`/api/tareas/${id}`);
await this.fetchTareas(); // Refresh the list
} catch (error) {
console.error(`Error deleting tarea with id ${id}:`, error);
throw error; // Re-throw to allow handling in component
}
},
// Action to clear currentTarea, useful when navigating away from a form
clearCurrentTarea() {
this.currentTarea = getDefaultCurrentTarea();
}
},
});