refactor(series): extract loadPublicSeries helper
This commit is contained in:
parent
bd4561fea7
commit
5f93d4c2e3
6 changed files with 68 additions and 56 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import Event from "../../models/event.js";
|
||||
import Series from "../../models/series.js";
|
||||
import { loadPublicSeries } from "../../utils/loadSeries.js";
|
||||
import { connectDB } from "../../utils/mongoose.js";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
|
|
@ -15,16 +15,14 @@ export default defineEventHandler(async (event) => {
|
|||
});
|
||||
}
|
||||
|
||||
// Try to fetch the Series model first for full ticketing info
|
||||
// Build query conditions based on whether id looks like ObjectId or string
|
||||
const isObjectId = /^[0-9a-fA-F]{24}$/.test(id);
|
||||
const seriesQuery = isObjectId
|
||||
? { $or: [{ _id: id }, { id: id }, { slug: id }] }
|
||||
: { $or: [{ id: id }, { slug: id }] };
|
||||
|
||||
const seriesModel = await Series.findOne(seriesQuery)
|
||||
.select("-registrations") // Don't expose registration details
|
||||
.lean();
|
||||
// Try to fetch the Series model first for full ticketing info.
|
||||
// Legacy series may exist only as event metadata (no Series doc), so we
|
||||
// fall through to the events-based path below when no Series doc matches.
|
||||
const seriesModel = await loadPublicSeries(event, id, {
|
||||
select: "-registrations", // Don't expose registration details
|
||||
lean: true,
|
||||
allowMissing: true,
|
||||
});
|
||||
|
||||
// Fetch all events in this series
|
||||
const events = await Event.find({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue