edit(update) working

This commit is contained in:
ATUL GUNJAL 2025-04-21 14:34:04 +05:30
parent 32830a9dd2
commit 7822f0938e

View File

@ -56,7 +56,7 @@
import { useRoute, useRouter } from 'vue-router'
import { useDirectus } from '../../app/composables/useDirectus'
const directus = useDirectus()
const { fetchCollection, updateItem } = useDirectus()
const route = useRoute()
const router = useRouter()
@ -66,11 +66,10 @@
const fetchClasses = async () => {
try {
const { data } = await directus.items('classes').readByQuery({
classes.value = await fetchCollection('classes', {
fields: ['id', 'name', 'section'],
sort: ['name']
})
classes.value = data
} catch (err) {
console.error('Error loading classes:', err)
}
@ -78,8 +77,11 @@
const fetchStudent = async () => {
try {
const student = await directus.items('students').readOne(studentId)
form.value = student
const studentData = await fetchCollection('students', {
filter: { id: { _eq: studentId } },
limit: 1
})
form.value = studentData[0] // Get first item from array
} catch (err) {
console.error('Error loading student:', err)
}
@ -92,7 +94,7 @@
const submitForm = async () => {
try {
await directus.items('students').updateOne(studentId, form.value)
await updateItem('students', studentId, form.value)
alert('Student updated successfully!')
router.push('/students')
} catch (err) {
@ -110,4 +112,3 @@
border-radius: 0.375rem;
}
</style>