Skip to content

Add admin-only POST /adminEvent endpoint - #46

Merged
1 commit merged into
mainfrom
piersol-admin-publish-events
Nov 22, 2026
Merged

1 commit merged into
mainfrom
piersol-admin-publish-events

Conversation

@piersolh

@piersolh piersolh commented Nov 22, 2026 •

Copy link
Copy Markdown

ℹ️ Issue

Closes #36

📝 Description

Adds POST /api/adminEvent so admins can publish Luma-linked, organization-wide events. Published events are stored in admin_events, so the existing GET /api/adminEvent lists them as admin/staff events (not steward-run). Cognito auth (#32) is already merged, so this uses real auth rather than a placeholder.

Briefly list the changes made to the code:

  1. New @Roles() decorator and RolesGuard (aws/cognito/) that check the caller's Cognito group: no token → 401 (global guard), non-admin including stewards → 403. Skipped when AUTH_DISABLED=true.
  2. New CreateAdminEventDto with validation that names the failing field: UUID site_id, YYYY-MM-DD date, HH:MM[:SS] times, endTime after startTime, https Luma-only registrationLink, required place, optional flyerS3Key.
  3. EventsService.createAdminEvent returns 404 for an unknown site_id, otherwise inserts and returns the event. Site is added to the events module.
  4. AdminEventResponseDto gains place, endTime, flyerS3Key (additive, also returned by GET).
  5. Swagger decorators and events/README.md updated. Unit tests for the service, DTO, controller and guard.

✔️ Verification

  1. unit tests ofc
  2. postman

steward account - unauthorized

Screenshot 2026-11-22 at 1 03 03 PM

not logged in. - unauthorized

Screenshot 2026-11-22 at 1 01 30 PM

admin account - authorized

Screenshot 2026-11-22 at 1 03 52 PM

future work

  • guys getting the auth token is so jank rn without a frontend but I was able to do it. i created a work around so dm me if u need to verify my work

Adds a RolesGuard/@roles decorator (Cognito groups) for 403s, a validated
CreateAdminEventDto, service logic that 404s on unknown sites and inserts
into admin_events, extended response DTO, README docs and unit tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@piersolh
piersolh marked this pull request as ready for review November 22, 2026 20:06
@saumyapalk23 saumyapalk23 self-assigned this Nov 22, 2026

@mehanana mehanana left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Pretty good! just some minor changes to make :)

*
* @throws {NotFoundException} If `dto.site_id` does not match a site.
*/
async createAdminEvent(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

startTime/endTime accept HH:MM, but we save them unpadded. save() returns the object we passed in rather than what Postgres stored, so a POST with "14:00" responds with time: "14:00" while a later GET of the same row returns "14:00:00". Could we normalize to HH:MM:SS before saving? toSeconds in the DTO file already does this, so i think we can reuse this (might also need to rewrite some tests)

description: 'Calendar date (YYYY-MM-DD)',
example: '2026-10-25',
})
@Matches(/^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/, {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This regex accepts impossible dates like 2026-02-31. Postgres rejects those at insert time, so the client gets a 500 instead of a 400. @IsDateString({ strict: true }) should catch them. Also I would add 2026-02-31 to the "rejects a bad site_id, date and time" test :)

site_id!: string;

@ApiProperty({ description: 'Event title' })
@IsString({ message: 'name must be a string' })

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do the name, description, and place fields in the entity have a length limit (varchar(n))? If so, could we add @maxlength here to match, so long input fails validation with a 400 instead of failing at insert with a 500?

expect(Reflect.getMetadata(ROLES_KEY, handler)).toEqual([UserType.ADMIN]);
expect(Reflect.getMetadata(IS_PUBLIC_KEY, handler)).toBeUndefined();
expect(Reflect.getMetadata(GUARDS_METADATA, handler)).toContain(RolesGuard);
expect(Reflect.getMetadata('__httpCode__', handler)).toBe(201);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

'__httpCode__' is a Nest internal string. Nest exports it as HTTP_CODE_METADATA from @nestjs/common/constants, the same place GUARDS_METADATA comes from:

Suggested change
expect(Reflect.getMetadata('__httpCode__', handler)).toBe(201);
expect(Reflect.getMetadata(HTTP_CODE_METADATA, handler)).toBe(201);

@saumyapalk23 saumyapalk23 closed this pull request by merging all changes into main in d4301d5 Nov 22, 2026
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.

bffc-29 POST /adminEvent: Admins publish events (linked to Luma reg.)

3 participants