Repository navigation
Add admin-only POST /adminEvent endpoint - #46
1 commit merged into
Conversation
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>
mehanana
left a comment
There was a problem hiding this comment.
Pretty good! just some minor changes to make :)
| * | ||
| * @throws {NotFoundException} If `dto.site_id` does not match a site. | ||
| */ | ||
| async createAdminEvent( |
There was a problem hiding this comment.
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])$/, { |
There was a problem hiding this comment.
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' }) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
'__httpCode__' is a Nest internal string. Nest exports it as HTTP_CODE_METADATA from @nestjs/common/constants, the same place GUARDS_METADATA comes from:
| expect(Reflect.getMetadata('__httpCode__', handler)).toBe(201); | |
| expect(Reflect.getMetadata(HTTP_CODE_METADATA, handler)).toBe(201); |
ℹ️ Issue
Closes #36
📝 Description
Adds
POST /api/adminEventso admins can publish Luma-linked, organization-wide events. Published events are stored inadmin_events, so the existingGET /api/adminEventlists 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:
@Roles()decorator andRolesGuard(aws/cognito/) that check the caller's Cognito group: no token → 401 (global guard), non-admin including stewards → 403. Skipped whenAUTH_DISABLED=true.CreateAdminEventDtowith validation that names the failing field: UUIDsite_id,YYYY-MM-DDdate,HH:MM[:SS]times,endTimeafterstartTime, https Luma-onlyregistrationLink, requiredplace, optionalflyerS3Key.EventsService.createAdminEventreturns 404 for an unknownsite_id, otherwise inserts and returns the event.Siteis added to the events module.AdminEventResponseDtogainsplace,endTime,flyerS3Key(additive, also returned by GET).events/README.mdupdated. Unit tests for the service, DTO, controller and guard.✔️ Verification
steward account - unauthorized
not logged in. - unauthorized
admin account - authorized
future work