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.

@ja-der ja-der force-pushed the jason/events-endpoints branch from 3251133 to 0e23067 Compare January 7, 2026 18:28
@ja-der ja-der requested a review from danielp1218 January 7, 2026 18:33
Copy link
Contributor

@danielp1218 danielp1218 left a comment

Choose a reason for hiding this comment

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

good stuff, LGTM!

seasonCode: string,
eventName: string,
startTime: string,
endTime: string,
Copy link
Contributor

@danielp1218 danielp1218 Jan 7, 2026

Choose a reason for hiding this comment

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

nit: personally would make the startTime and endTime accept Date objects instead (if we ever want to reuse this function elsewhere, it should be clear these represent dates)

Copy link
Author

Choose a reason for hiding this comment

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

updated!

@ja-der ja-der force-pushed the jason/events-endpoints branch from 0e23067 to c310fb3 Compare January 12, 2026 17:02
type CheckInReturn = Awaited<ReturnType<(typeof svc)["checkInUser"]>>;
import app from "@/server";

vi.mock("@/config/env", () => ({
Copy link

Choose a reason for hiding this comment

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

@danielp1218 we should move this into some setup script for vitest
https://vitest.dev/config/#globalsetup

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh yeah ill do that, that'll be really useful

Comment on lines +28 to +40
let consoleErrorSpy: ReturnType<typeof vi.spyOn>;

beforeAll(() => {
consoleErrorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
});

afterAll(() => {
consoleErrorSpy.mockRestore();
});

afterEach(() => {
vi.restoreAllMocks();
});
Copy link

Choose a reason for hiding this comment

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

kinda sus, why we are hiding error logs?

Comment on lines +42 to +63
vi.mock("@/db", () => ({
db: {
select: vi.fn(),
insert: vi.fn(),
},
}));

vi.mock("@/db/schema", () => ({
seasonResponse: {
seasonCode: "seasonCode",
seasonId: "seasonId",
eventName: "testEvent",
startTime: "1:00",
endTime: "2:00",
},
}));

vi.mock("drizzle-orm", () => ({
eq: vi.fn((field, value) => ({ field, value, type: "eq" })),
and: vi.fn((...conditions) => ({ conditions, type: "and" })),
sql: vi.fn((strings, ...values) => ({ strings, values, type: "sql" })),
}));
Copy link

@fpunny fpunny Jan 13, 2026

Choose a reason for hiding this comment

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

why are we mocking the DB and also initializing it?

Comment on lines +44 to +51
if (!response) {
throw new ApiError(404, {
code: "NO_EVENTS_FOUND",
message: "No events found",
suggestion: "Verify the seasonCode is correct.",
});
}
return c.json(response);
Copy link

Choose a reason for hiding this comment

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

nit: we should just return empty - we dont want a variant between empty/non-existent because it allows for people to "mine" for our season codes
https://owasp.org/www-community/Improper_Error_Handling

checkInAuthor,
checkInNotes: checkInNotes || null,
})
.onConflictDoUpdate({
Copy link

Choose a reason for hiding this comment

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

Do we want to allow rechecking in a user? would there realistically be a reason why we would recheckin?

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.

4 participants