diff --git a/apps/web-api/src/internals/pl-events.controller.ts b/apps/web-api/src/internals/pl-events.controller.ts index 1e539d4c6..dde7c1518 100644 --- a/apps/web-api/src/internals/pl-events.controller.ts +++ b/apps/web-api/src/internals/pl-events.controller.ts @@ -1,4 +1,4 @@ -import { Controller, UseGuards, Req } from '@nestjs/common'; +import { Controller, UseGuards, Req, Param } from '@nestjs/common'; import { ApiParam } from '@nestjs/swagger'; import { Request } from 'express'; import { Api, initNestServer, ApiDecorator } from '@ts-rest/nest'; @@ -20,11 +20,10 @@ export class PLEventsInternalController { private readonly eventGuestsService: PLEventGuestsService, ) {} - @Api(server.route.getPLEventGuestsBySlug) - @ApiParam({ name: 'slug', type: 'string' }) + @Api(server.route.getPLEventGuestsByLocation) @ApiOkResponseFromZod(ResponsePLEventGuestSchemaWithRelationsSchema) async fetchEventGuests( - @ApiDecorator() { params: { slug } }: RouteShape['getPLEventGuestsBySlug'], + @Param("uid") locationUid, @Req() request: Request ) { const queryableFields = prismaQueryableFieldsFromZod( @@ -32,6 +31,6 @@ export class PLEventsInternalController { ); const builder = new PrismaQueryBuilder(queryableFields); const builtQuery = builder.build(request.query); - return await this.eventGuestsService.getPlEventGuestsBySlug(slug, builtQuery); + return await this.eventGuestsService.getPLEventGuestsByLocation(locationUid, builtQuery); } } diff --git a/apps/web-api/src/pl-events/pl-event-guests.service.ts b/apps/web-api/src/pl-events/pl-event-guests.service.ts index 17bb40272..47db8b065 100644 --- a/apps/web-api/src/pl-events/pl-event-guests.service.ts +++ b/apps/web-api/src/pl-events/pl-event-guests.service.ts @@ -1,7 +1,7 @@ import { Injectable, NotFoundException, ConflictException, BadRequestException, Inject, CACHE_MANAGER } from '@nestjs/common'; import { LogService } from '../shared/log.service'; import { PrismaService } from '../shared/prisma.service'; -import { Prisma, Member } from '@prisma/client'; +import { Prisma, Member, PLEventGuest } from '@prisma/client'; import { MembersService } from '../members/members.service'; import { Cache } from 'cache-manager'; import { PLEventLocationsService } from './pl-event-locations.service'; @@ -236,23 +236,29 @@ export class PLEventGuestsService { await this.memberService.updateOfficeHoursIfChanged(member, guest.officeHours, tx); } } - + /** - * This method retrieves event guests by slug. - * @param slug The slug of the event - * @returns An array of event guests for the specified event - * - Throws an error if the event is not found. - */ - async getPlEventGuestsBySlug(slug: string, query:Prisma.PLEventGuestFindManyArgs) { + * Fetches all PLEventGuests for a given location, filtered by the upcoming events at that location. + * + * @param {string} locationUid - The UID of the location to get event guests for. + * @param {Prisma.PLEventGuestFindManyArgs} query - Optional query arguments, including orderBy. + * @returns {Promise} - A promise that resolves to an array of PLEventGuest records, including member and team details. + * @throws Will log an error and throw an appropriate HTTP exception if something goes wrong. + */ + async getPLEventGuestsByLocation( + locationUid: string, + query: Prisma.PLEventGuestFindManyArgs + ) { try { - const pLEventGuests = await this.prisma.pLEventGuest.findMany({ + const events = await this.eventLocationsService.getUpcomingEventsByLocation(locationUid); + return await this.prisma.pLEventGuest.findMany({ where: { - ...query.where, - event: { - slugURL: slug + eventUid: { + in: events.map(event => event.uid) } }, select: { + memberUid: true, isHost: true, isSpeaker: true, isFeatured: true, @@ -273,13 +279,13 @@ export class PLEventGuestsService { } } }, - orderBy: query.orderBy + orderBy: query.orderBy }); - return pLEventGuests; - } catch(err) { - return this.handleErrors(err, slug); - } - } + } + catch(err) { + this.handleErrors(err); + } + }; /** * This method checks whether all provided events are upcoming based on the list of upcoming events. diff --git a/libs/contracts/src/lib/contract-internals.ts b/libs/contracts/src/lib/contract-internals.ts index 3360da8b5..90e1d7c57 100644 --- a/libs/contracts/src/lib/contract-internals.ts +++ b/libs/contracts/src/lib/contract-internals.ts @@ -8,13 +8,13 @@ import { getAPIVersionAsPath } from '../utils/versioned-path'; const contract = initContract(); export const apiInternals = contract.router({ - getPLEventGuestsBySlug: { + getPLEventGuestsByLocation: { method: 'GET', - path: `${getAPIVersionAsPath('1')}/internals/irl/locations/:uid/events/:slug/guests`, + path: `${getAPIVersionAsPath('1')}/internals/irl/locations/:uid/events/guests`, query: PLEventGuestQueryParams, responses: { 200: ResponsePLEventGuestSchemaWithRelationsSchema, }, - summary: 'Get a pl event with guests by slug', + summary: 'Get a pl event with guests by location', }, }); \ No newline at end of file