Skip to content

Commit

Permalink
fix: fixed issue in irl events filter
Browse files Browse the repository at this point in the history
  - fixed issue in search event guest by member or team name
  • Loading branch information
navneethkrish committed Oct 30, 2024
1 parent e579ede commit fc364aa
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
2 changes: 1 addition & 1 deletion apps/web-api/src/internals/pl-events.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class PLEventsInternalController {
builtQuery.where = {
AND: [
builtQuery.where,
this.eventService.buildSearchFilter(request.query),
this.eventService.buildMemberOrTeamFilter(request.query),
]
};
}
Expand Down
19 changes: 8 additions & 11 deletions apps/web-api/src/pl-events/pl-event-guests.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ export class PLEventGuestsService {
} else {
events = await this.eventLocationsService.getPastEventsByLocation(locationUid);
}
events = await this.filterEventsByAttendanceAndAdminStatus(filteredEvents, events, member);
if (events.length === 0)
return [];
events = await this.filterEventsByAttendanceAndAdminStatus(filteredEvents, events, member);
const result = await this.fetchAttendees({
eventUids: events?.map(event => event.uid),
...query,
Expand Down Expand Up @@ -344,18 +344,17 @@ export class PLEventGuestsService {
* @returns {Promise<PLEvent[]>} Filtered array of events based on the user’s attendance, login state, and admin status.
*/
async filterEventsByAttendanceAndAdminStatus(filteredEventsUid, events: PLEvent[], member): Promise<PLEvent[]> {
// Scenario 1: If the user is logged out, remove all invite-only events
const inviteOnlyEventsUid = events.filter(event => event.type === "INVITE_ONLY").map(event => event.uid);
if (filteredEventsUid?.length > 0 && !member) {
const publicFilteredUids = filteredEventsUid.filter(uid => !inviteOnlyEventsUid.includes(uid));
return events.filter(event => publicFilteredUids.includes(event.uid));
return events.filter(event => filteredEventsUid?.includes(event.uid))
.filter(event => event.type !== "INVITE_ONLY");
}
// If the user is logged out, remove all invite-only events
if (!member) {
return events.filter(event => event.type !== "INVITE_ONLY");
}
// If the user is an admin, return all events without filtering
if (this.memberService.checkIfAdminUser(member)) {
return events;
return filteredEventsUid?.length ? events.filter(event => filteredEventsUid.includes(event.uid)): events;
}
// Scenario 2: If the user is logged in and not an admin, get invite-only events they are attending
const userAttendedEvents = await this.prisma.pLEvent.findMany({
Expand All @@ -374,11 +373,9 @@ export class PLEventGuestsService {
// Create a Set of attended invite-only event UIDs for efficient lookup
const attendedEventUids = new Set(userAttendedEvents.map(event => event.uid));
// Filter events to keep non-invite-only events and attended invite-only events
if (filteredEventsUid.length > 0) {
return filteredEventsUid.filter(eventUid => {
const event:any = events.find(event => event.uid === eventUid);
return event?.type !== "INVITE_ONLY" || attendedEventUids.has(event?.uid);
});
if (filteredEventsUid?.length > 0) {
return events.filter(event => filteredEventsUid?.includes(event.uid))
.filter(event => event.type !== "INVITE_ONLY" || attendedEventUids.has(event?.uid));
}
return events.filter(event =>
event.type !== "INVITE_ONLY" || attendedEventUids.has(event.uid)
Expand Down
7 changes: 6 additions & 1 deletion apps/web-api/src/pl-events/pl-event-locations.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,12 @@ export class PLEventLocationsService {
logo: true,
banner: true,
resources: true,
additionalInfo: true
additionalInfo: true,
_count: {
select: {
eventGuests: true
}
}
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions apps/web-api/src/pl-events/pl-events.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,4 +243,36 @@ export class PLEventsService {
return {};
};

/**
* This method construct the dynamic query to search the given text in either
* by member name , by team name from query params
* This method builts a query to enable search by team name or member name.
* @param query name of the team or member which is to be fetched
* @returns Constructed query based on given text(name) input.
*/
buildMemberOrTeamFilter(query) {
const { searchBy, searchText } = query;
if (searchBy === "member") {
return {
member: {
name: {
contains : searchText,
mode: 'insensitive',
},
}
}
} else if (searchBy === "team") {
return {
team: {
name: {
contains: searchText,
mode: 'insensitive'
}
}
};
}
else {
return {};
}
};
}

0 comments on commit fc364aa

Please sign in to comment.