Skip to content

Conversation

@ja-der
Copy link

@ja-der ja-der commented Dec 15, 2025

implemented events endpoints: list, create, and check-in

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements three new event-related endpoints for managing events and user check-ins: listing events by season, creating new events, and checking users into events. The implementation includes service layer functions, route handlers with validation, and comprehensive test coverage.

Key Changes:

  • Added service layer functions (fetchEvents, createEvent, checkInUser) with database operations and error handling
  • Implemented three REST endpoints with Zod validation for event management and user check-ins
  • Added comprehensive unit tests for all service layer functions covering success and error scenarios

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/resources/events/events.test.ts Comprehensive unit tests for all three service functions with mocked database operations
src/resources/events/events.service.ts Service layer implementation for fetching, creating events and checking in users
src/resources/events/events.routes.ts HTTP route handlers with validation schemas for event endpoints
src/api.ts Registration of the new events routes with the API

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


export const createEvent = async (
seasonCode: string,
eventName: string,
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The parameter order doesn't match the test expectations. Tests call createEvent(seasonCode, eventId, eventName, startTime, endTime) with 5 parameters including an eventId, but the function signature only accepts 4 parameters and is missing eventId. This mismatch will cause the tests to fail at runtime.

Copilot uses AI. Check for mistakes.
async (c) => {
const seasonCode = c.req.param("seasonCode");
const eventId = c.req.param("eventId");
const body = await c.req.json();
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The request body is being parsed twice - once by the validator middleware on line 64 and again manually here. Use c.req.valid('json') instead to access the already-validated body, consistent with the pattern used in the create event endpoint (line 40).

Suggested change
const body = await c.req.json();
const body = c.req.valid("json");

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

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

i agree with mr. copilot

Comment on lines 13 to +15
export default api;

api.route("/", eventsRoute);
Copy link

Copilot AI Dec 15, 2025

Choose a reason for hiding this comment

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

The events route is registered after the export statement. Move this line before the export (after line 10) to maintain consistency with other route registrations and ensure proper initialization order.

Suggested change
export default api;
api.route("/", eventsRoute);
api.route("/", eventsRoute);
export default api;

Copilot uses AI. Check for mistakes.
: c.json({ message: "No events found" }, 404);
} catch (error) {
const message =
error instanceof Error ? error.message : "Failed to fetch events";
Copy link
Contributor

Choose a reason for hiding this comment

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

I changed the error handling to a different structure in my PR (#1). A better structure would be to throw an ApiError directly from the service function and not catch it (will be caught by Hono's error handling fn). Also, pls change all error responses to ApiError, we want to have consistent error handling. You can see how I did it in the formResponses route.

const eventsRoute = new Hono();

// list all events
eventsRoute.get("/seasons/:seasonCode/events", async (c) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

we should get some doc specifications on this :) (and all the other routes here). Check https://hono.dev/examples/hono-openapi.

we can work on this after this gets merged in though.

return result;
} catch (error: unknown) {
const dbError = handleDbError(error);
throw new Error(dbError.message);
Copy link
Contributor

Choose a reason for hiding this comment

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

outdated, check #1 for better way of doing this

async (c) => {
const seasonCode = c.req.param("seasonCode");
const eventId = c.req.param("eventId");
const body = await c.req.json();
Copy link
Contributor

Choose a reason for hiding this comment

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

i agree with mr. copilot

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.

3 participants