Skip to content

Add template event retrieval and related data structures#21

Open
wesenbergg wants to merge 1 commit into
masterfrom
get-templates
Open

Add template event retrieval and related data structures#21
wesenbergg wants to merge 1 commit into
masterfrom
get-templates

Conversation

@wesenbergg

Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings March 5, 2026 21:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds endpoints and service-layer support to retrieve template events (and event details by ID) from the calendar_events table for use by the API.

Changes:

  • Introduces TemplateEventFull, a row parser, and getTemplateEvents() / getEventById() in calendarEventService.
  • Adds GET /api/events/templates and GET /api/events/:id routes (authorized) in the Express app.
  • Refactors/realigns some existing route handler indentation.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/services/calendarEventService.ts Adds template/event detail data structure, row parsing, and DB queries to fetch templates and event-by-id.
src/App.ts Adds API routes to expose template listing and event detail retrieval; adjusts handler formatting.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/App.ts
Comment on lines +84 to +88
starts: Date | null
registration_starts: Date | null
registration_ends: Date | null
cancellation_starts: Date | null
cancellation_ends: Date | null

Copilot AI Mar 5, 2026

Copy link

Choose a reason for hiding this comment

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

TemplateEventFull declares several datetime fields as Date | null, but the DB layer is configured to return MySQL DATETIME values as strings (see knexfile.ts typeCast). This makes the exported type misleading and can lead to runtime bugs for callers expecting Date methods. Either change these fields to string | null or explicitly convert them to Date in parseTemplateQueryResult (and ensure consistent timezone handling).

Suggested change
starts: Date | null
registration_starts: Date | null
registration_ends: Date | null
cancellation_starts: Date | null
cancellation_ends: Date | null
starts: string | null
registration_starts: string | null
registration_ends: string | null
cancellation_starts: string | null
cancellation_ends: string | null

Copilot uses AI. Check for mistakes.
Comment on lines +115 to +123
alcohol_meter: row.alcohol_meter ?? null,
price: row.price ?? null,
map: row.map ?? null,
max_participants: row.max_participants ?? null,
membership_required: row.membership_required ?? null,
outsiders_allowed: row.outsiders_allowed ?? null,
responsible: row.responsible ?? null,
show_responsible: row.show_responsible ?? null,
avec: row.avec ?? null,

Copilot AI Mar 5, 2026

Copy link

Choose a reason for hiding this comment

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

parseTemplateQueryResult currently passes through DB values for fields typed as booleans (membership_required, outsiders_allowed, show_responsible, avec). With MySQL/knex these are typically 0/1 numbers, not true/false, so the returned JSON and TS types will be inconsistent. Consider coercing these to booleans here (preserving null) or update the interface to match the actual runtime types.

Copilot uses AI. Check for mistakes.
Comment thread src/services/calendarEventService.ts
Comment thread src/App.ts
Comment on lines +69 to +75
app.get('/api/events/:id', authorizeRequest, async (req, res) => {
try {
const id = parseInt(req.params.id)
if (Number.isNaN(id)) return res.status(400).json({ error: 'Invalid ID' })
const event = await calendarEventService.getEventById(id)
if (!event) return res.status(404).json({ error: 'Not Found' })
return res.json(event)

Copilot AI Mar 5, 2026

Copy link

Choose a reason for hiding this comment

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

The new /api/events/:id handler returns the result of getEventById, which is typed as TemplateEventFull, but getEventById does not filter on template. As written, this is effectively a general “event details” endpoint, so the TemplateEventFull/parseTemplateQueryResult naming is misleading for API consumers and maintainers. Consider renaming the type/parser (or adding a template filter if this endpoint is intended to be template-only).

Copilot uses AI. Check for mistakes.
Comment thread src/App.ts
Comment on lines +72 to +74
if (Number.isNaN(id)) return res.status(400).json({ error: 'Invalid ID' })
const event = await calendarEventService.getEventById(id)
if (!event) return res.status(404).json({ error: 'Not Found' })

Copilot AI Mar 5, 2026

Copy link

Choose a reason for hiding this comment

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

The new /api/events/:id error payloads/messages ({ error: 'Invalid ID' }, { error: 'Not Found' }) are inconsistent with other endpoints in this file (mostly lowercase messages like internal server error, and more specific 404s like ID Not Found). To make client handling simpler, consider standardizing error message casing/content and status codes across routes (e.g., a consistent 400 message for invalid IDs and a consistent 404 message for missing resources).

Suggested change
if (Number.isNaN(id)) return res.status(400).json({ error: 'Invalid ID' })
const event = await calendarEventService.getEventById(id)
if (!event) return res.status(404).json({ error: 'Not Found' })
if (Number.isNaN(id)) return res.status(400).json({ error: 'invalid id' })
const event = await calendarEventService.getEventById(id)
if (!event) return res.status(404).json({ error: 'id not found' })

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants