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