improve events endpoints

This commit is contained in:
SrGooglo 2025-04-01 21:51:39 +00:00
parent 43a1d7b4c0
commit 82b7bc579b
4 changed files with 45 additions and 13 deletions

View File

@ -0,0 +1,15 @@
export default {
name: "Event",
collection: "events",
schema: {
name: { type: String, required: true },
category: { type: String },
description: { type: String },
announcement: { type: Object, required: true },
location: { type: String },
startDate: { type: Date, required: true },
endDate: { type: Date, required: true },
featured: { type: Boolean, default: false },
pageConfig: { type: Object, default: {} },
},
}

View File

@ -1,13 +0,0 @@
export default {
name: "FeaturedEvent",
collection: "featuredEvents",
schema: {
name: { type: String, required: true },
category: { type: String },
description: { type: String },
dates: { type: Object },
location: { type: String },
announcement: { type: Object, required: true },
expired: { type: Boolean, default: false }
}
}

View File

@ -0,0 +1,20 @@
import { Event } from "@db_models"
import axios from "axios"
export default async (req) => {
let event = await Event.findById(req.params.event_id)
event = event.toObject()
// fetch page if exist
if (event.page && event.page.startsWith("https://")) {
try {
const response = await axios.get(event.page)
event.page = response.data
} catch (error) {
console.error(error)
}
}
return event
}

View File

@ -0,0 +1,10 @@
import { Event } from "@db_models"
export default async (req) => {
const events = await Event.find({
endDate: { $gte: new Date() },
featured: true,
})
return events
}