Skip to content

Commit

Permalink
fix: fixed issue event listing in irl
Browse files Browse the repository at this point in the history
  • Loading branch information
navneethkrish authored and madan-ideas2it committed Oct 30, 2024
1 parent a66f2af commit 2799a4a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
39 changes: 21 additions & 18 deletions apps/web-api/src/pl-events/pl-event-guests.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,10 +403,7 @@ export class PLEventGuestsService {
const { eventUids, isHost, isSpeaker, topics, sortBy, sortDirection='asc', search, limit=10, page=1, loggedInMemberUid } = queryParams;
// Build dynamic query conditions for filtering by eventUids, isHost, and isSpeaker
let { conditions, values } = this.buildConditions(eventUids, topics);

// Apply search functionality to filter results based on member, team, or project names
({ conditions, values } = this.applySearch(conditions, values, search));


// Apply sorting based on the sortBy parameter (default is sorting by memberName)
const orderBy = this.applySorting(sortBy, sortDirection, loggedInMemberUid);

Expand Down Expand Up @@ -492,14 +489,15 @@ export class PLEventGuestsService {
LEFT JOIN "Project" cp ON cp."createdBy" = m.uid
LEFT JOIN "Team" tm ON tm.uid = pg."teamUid"
LEFT JOIN "Image" tml ON tml.uid = tm."logoUid"
${conditions} -- Add the dynamically generated conditions for filtering
${this.applySearch(values, search)}
GROUP BY
pg."memberUid",
pg."teamUid",
pg."topics",
pg."reason",
m.name,
tm.name
${conditions} -- Add the dynamically generated conditions for filtering
${orderBy} -- Apply sorting logic
)
AS subquery
Expand Down Expand Up @@ -556,7 +554,7 @@ export class PLEventGuestsService {
const values:any = [];
// Add a condition to filter by event UIDs if provided
if (eventUids && eventUids.length > 0) {
conditions.push(`pg."eventUid" IN (${eventUids.map((_, i) => `$${i + 1}`).join(", ")})`);
conditions.push(`array_agg(e.uid) && ARRAY[${eventUids?.map((_, i) => `$${i + 1}`).join(", ")}]`);
values.push(...eventUids);
}
// Add a condition for topics if provided, using the overlap operator (&&)
Expand All @@ -565,7 +563,7 @@ export class PLEventGuestsService {
values.push(topics);
}
// Combine conditions into a single WHERE clause if any conditions are present
const conditionsString = conditions.length > 0 ? ` WHERE ${conditions.join(" AND ")} ` : '';
const conditionsString = conditions.length > 0 ? ` Having ${conditions.join(" AND ")} ` : '';
return { conditions: conditionsString, values };
}

Expand Down Expand Up @@ -600,19 +598,18 @@ export class PLEventGuestsService {
* @param {string} search - The search term to filter by member name, team name, or project names.
* @returns {Object} Updated conditions and values for the SQL query after applying search filters.
*/
applySearch(conditions:string, values, search:string) {
applySearch(values, search:string) {
// Add a condition to search by member name, team name, or project names (either contributed or created)
if (search) {
conditions += ` AND (
m."name" ILIKE $${values.length + 1} OR
tm."name" ILIKE $${values.length + 1} OR
pc_project."name" ILIKE $${values.length + 1} OR
cp."name" ILIKE $${values.length + 1}
)`;
// Append search term to the query values with wildcard matching
values.push(`%${search}%`);
return ` WHERE
m."name" ILIKE $${values.length } OR
tm."name" ILIKE $${values.length } OR
pc_project."name" ILIKE $${values.length } OR
cp."name" ILIKE $${values.length } `;
// Append search term to the query values with wildcard matching
}
return { conditions, values };
return ``;
}

/**
Expand Down Expand Up @@ -708,10 +705,16 @@ export class PLEventGuestsService {
async getPLEventGuestByUidAndLocation(
memberUid: string,
locationUid: string,
isUserLoggedIn: boolean
isUserLoggedIn: boolean,
type: string
) {
try {
const events = await this.eventLocationsService.getUpcomingEventsByLocation(locationUid);
let events;
if (type === "upcoming") {
events = await this.eventLocationsService.getUpcomingEventsByLocation(locationUid);
} else {
events = await this.eventLocationsService.getPastEventsByLocation(locationUid);
}
const result = await this.prisma.pLEventGuest.findMany({
where: {
memberUid,
Expand Down
3 changes: 2 additions & 1 deletion apps/web-api/src/pl-events/pl-events.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ export class PLEventsController {
@Param('uid') locationUid: string,
@Param('guestUid') guestUid: string
) {
const { type } = request.query;
const member: any = await this.memberService.findMemberByEmail(request["userEmail"]);
const memberUid = this.memberService.checkIfAdminUser(member) ? guestUid : member.uid;
return await this.eventGuestService.getPLEventGuestByUidAndLocation(memberUid, locationUid, request["isUserLoggedIn"]);
return await this.eventGuestService.getPLEventGuestByUidAndLocation(memberUid, locationUid, true, type);
}
}

0 comments on commit 2799a4a

Please sign in to comment.