Add series management and ticketing features: Introduce series event functionality in event creation, enhance event display with series information, and implement ticketing options for public events. Update layouts and improve form handling for better user experience.
This commit is contained in:
parent
c3a29fa47c
commit
a88aa62198
24 changed files with 2897 additions and 44 deletions
60
server/api/admin/series.get.js
Normal file
60
server/api/admin/series.get.js
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
import Series from '../../models/series.js'
|
||||
import Event from '../../models/event.js'
|
||||
import { connectDB } from '../../utils/mongoose.js'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
await connectDB()
|
||||
|
||||
// Fetch all series
|
||||
const series = await Series.find({ isActive: true })
|
||||
.sort({ createdAt: -1 })
|
||||
.lean()
|
||||
|
||||
// For each series, get event count and statistics
|
||||
const seriesWithStats = await Promise.all(
|
||||
series.map(async (s) => {
|
||||
const events = await Event.find({
|
||||
'series.id': s.id,
|
||||
'series.isSeriesEvent': true
|
||||
}).select('_id startDate endDate registrations').lean()
|
||||
|
||||
const now = new Date()
|
||||
const eventCount = events.length
|
||||
const completedEvents = events.filter(e => e.endDate < now).length
|
||||
const upcomingEvents = events.filter(e => e.startDate > now).length
|
||||
|
||||
const firstEventDate = events.length > 0 ?
|
||||
Math.min(...events.map(e => new Date(e.startDate))) : null
|
||||
const lastEventDate = events.length > 0 ?
|
||||
Math.max(...events.map(e => new Date(e.endDate))) : null
|
||||
|
||||
let status = 'upcoming'
|
||||
if (lastEventDate && lastEventDate < now) {
|
||||
status = 'completed'
|
||||
} else if (firstEventDate && firstEventDate <= now && lastEventDate && lastEventDate >= now) {
|
||||
status = 'active'
|
||||
}
|
||||
|
||||
return {
|
||||
...s,
|
||||
eventCount,
|
||||
completedEvents,
|
||||
upcomingEvents,
|
||||
startDate: firstEventDate,
|
||||
endDate: lastEventDate,
|
||||
status,
|
||||
totalRegistrations: events.reduce((sum, e) => sum + (e.registrations?.length || 0), 0)
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
return seriesWithStats
|
||||
} catch (error) {
|
||||
console.error('Error fetching series:', error)
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Failed to fetch series'
|
||||
})
|
||||
}
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue