Skip to content

Commit

Permalink
feat: fetch event guests based on location
Browse files Browse the repository at this point in the history
  • Loading branch information
navneethkrish authored and madan-ideas2it committed Oct 23, 2024
1 parent cda4f01 commit fc8ecc4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 26 deletions.
9 changes: 4 additions & 5 deletions apps/web-api/src/internals/pl-events.controller.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -20,18 +20,17 @@ 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(
ResponsePLEventGuestSchemaWithRelationsSchema
);
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);
}
}
42 changes: 24 additions & 18 deletions apps/web-api/src/pl-events/pl-event-guests.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<PLEventGuest[]>} - 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,
Expand All @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions libs/contracts/src/lib/contract-internals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
});

0 comments on commit fc8ecc4

Please sign in to comment.