add: asign driver to vehicle
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { defineStore } from "pinia";
|
||||
import { ref } from "vue";
|
||||
import { getVehicles } from "../services/vehicles";
|
||||
import { getVehicles, updateVehicle } from "../services/vehicles";
|
||||
export const useVehiclesStore = defineStore('vehicles', () => {
|
||||
|
||||
const vehicles = ref([]);
|
||||
@@ -23,8 +23,28 @@ export const useVehiclesStore = defineStore('vehicles', () => {
|
||||
}
|
||||
}
|
||||
|
||||
const updateVehicleCompany = async(id, formData, localData = {}) => {
|
||||
const data = await updateVehicle(id, formData);
|
||||
if(data) {
|
||||
console.log({data});
|
||||
const index = vehicles.value.findIndex((vehicle) => vehicle._id === id);
|
||||
vehicles.value[index] = {
|
||||
...vehicles.value[index],
|
||||
...data,
|
||||
...localData
|
||||
};
|
||||
|
||||
console.log(vehicles.value[index]);
|
||||
return 'success';
|
||||
} else {
|
||||
return 'Algo salio mal, intente más tarde';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
vehicles,
|
||||
fetchVehicles,
|
||||
vehicles
|
||||
updateVehicleCompany
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user