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:
@@ -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();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user