Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions app/pages/events/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,20 @@ async function saveChanges() {

// Update local event data
event.value = { ...editForm.value }

//update map center if location changed
if (editForm.value.location.address !== event.value.location.address) {
center.value = [editForm.value.location.longitude, editForm.value.location.latitude]
}

isEditMode.value = false

console.log('✅ Event updated successfully')
} catch (error) {
if(error.status === 500){
alert('Failed to geocode the provided location. Please check the address and try again.')
return
}
console.error('❌ Error updating event:', error)
alert('Error updating event. Please try again.')
}
Expand Down
22 changes: 10 additions & 12 deletions server/api/events/[id]/index.patch.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { error } from 'node:console'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this import, I think its unused

import prisma from '~~/server/utils/prisma'

// Geocode location using Nominatim
Expand Down Expand Up @@ -39,7 +40,6 @@ async function geocodeLocation( location: string) {
}



export default defineEventHandler(async (event) => {
const id = getRouterParam(event, 'id')
const body = await readBody(event)
Expand All @@ -51,17 +51,20 @@ export default defineEventHandler(async (event) => {
//check if location has already been fetched
const locationData = await prisma.location.findUnique({
where: {
address: body.location || null
address: body.location.address || null
},
select: {
latitude: true,
longitude: true,
address: true
}
}) || await geocodeLocation(body.location)
}) || await geocodeLocation(body.location.address)

console.log('📍 Location data from DB:', locationData)
if (!locationData) {
throw createError({ statusCode: 500, message: 'Failed to retrieve or create location data' })
}

console.log('📍 Location data from DB:', locationData)

if (!locationData) {
throw createError({
Expand All @@ -84,21 +87,16 @@ export default defineEventHandler(async (event) => {
const updatedEvent = await prisma.event.update({
where: { id },
data: {
title: body.title,
shortDesc: body.shortDesc,
description: body.description,
...body,
location: {
connectOrCreate: {
where: {
address: body.location || null
address: body.location.address
},
create: locationData!
}
},
startTime: new Date(body.startTime),
endTime: new Date(body.endTime),
allowVolunteers: body.allowVolunteers,
allowAttendees: body.allowAttendees,

},
include: {
eventAssets: true
Expand Down
1 change: 0 additions & 1 deletion server/api/events/index.post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export default defineEventHandler(async (event) => {
})
}


try {
// Create the event in the database
const newEvent = await prisma.event.create({
Expand Down