diff --git a/apps/web-api/src/members/members.controller.ts b/apps/web-api/src/members/members.controller.ts index 47b9602fa..f28d5aa9f 100644 --- a/apps/web-api/src/members/members.controller.ts +++ b/apps/web-api/src/members/members.controller.ts @@ -65,7 +65,11 @@ export class MemberController { delete builtQuery.where?.name; } builtQuery.where = { - AND: [builtQuery.where, this.membersService.buildNameFilters(queryParams)], + AND: [ + builtQuery.where, + this.membersService.buildNameFilters(queryParams), + this.membersService.buildRecentMembersFilter(queryParams) + ], }; return await this.membersService.getRolesWithCount(builtQuery, queryParams); } diff --git a/apps/web-api/src/members/members.service.ts b/apps/web-api/src/members/members.service.ts index cfb855859..70a695e82 100644 --- a/apps/web-api/src/members/members.service.ts +++ b/apps/web-api/src/members/members.service.ts @@ -702,7 +702,7 @@ export class MembersService { } async updateTelegramIfChanged(member, telegram, tx?:Prisma.TransactionClient) { - if (telegram && telegram != '' && member.telegramHandler != telegram) { + if (member.telegramHandler != telegram) { member = await (tx || this.prisma).member.update({ where: { uid: member.uid }, data: { @@ -714,7 +714,7 @@ export class MembersService { } async updateOfficeHoursIfChanged(member, officeHours, tx?:Prisma.TransactionClient) { - if (officeHours && officeHours != '' && member.officeHours != officeHours) { + if (member.officeHours != officeHours) { member = await (tx || this.prisma).member.update({ where: { uid: member.uid }, data: { 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 ae77c2ae5..8ceb10da9 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 @@ -133,14 +133,12 @@ export class PLEventGuestsService { in: events.map(event => event.uid) } }, - select: isUserLoggedIn ? { + select: { uid: true, reason: true, - telegramId: true, memberUid: true, teamUid: true, topics: true, - officeHours: true, additionalInfo: true, isHost: true, isSpeaker: true, @@ -163,9 +161,9 @@ export class PLEventGuestsService { select: { name: true, image: true, - telegramHandler: true, + telegramHandler: isUserLoggedIn ? true : false, preferences: true, - officeHours: true, + officeHours: isUserLoggedIn ? true : false, teamMemberRoles: { select:{ team: { @@ -203,21 +201,8 @@ export class PLEventGuestsService { } }, createdAt: true, - }: - { - team: { - select:{ - name: true, - logo: true - } - }, - event: { - select: { - type: true - } - }, - memberUid: true, - createdAt: true, + telegramId: isUserLoggedIn ? true : false, + officeHours: isUserLoggedIn ? true : false } }); this.restrictTelegramBasedOnMemberPreference(result, isUserLoggedIn); diff --git a/apps/web-api/src/pl-events/pl-events.service.ts b/apps/web-api/src/pl-events/pl-events.service.ts index 3c309d01d..dbaaf3952 100644 --- a/apps/web-api/src/pl-events/pl-events.service.ts +++ b/apps/web-api/src/pl-events/pl-events.service.ts @@ -51,16 +51,31 @@ export class PLEventsService { include: { logo: true, banner: true, - eventGuests: isUserLoggedIn ? { - include: { + eventGuests: { + select: { + uid: true, + reason: true, + memberUid: true, + teamUid: true, + topics: true, + additionalInfo: true, + isHost: true, + isSpeaker: true, + createdAt: true, + telegramId: isUserLoggedIn ? true : false, + officeHours: isUserLoggedIn ? true : false, event: { include: { logo: true } }, member: { - include:{ + select:{ image: true, + name: true, + preferences: true, + telegramHandler: isUserLoggedIn ? true : false, + officeHours: isUserLoggedIn ? true : false, teamMemberRoles: { select:{ team: { @@ -98,20 +113,6 @@ export class PLEventsService { } } } - }:{ - select: { - team: { - select:{ - name: true, - logo: true - } - }, - event: { - select: { - type: true - } - } - } } } }); diff --git a/apps/web-api/src/projects/projects.service.ts b/apps/web-api/src/projects/projects.service.ts index 326d32cd7..ea189f53d 100644 --- a/apps/web-api/src/projects/projects.service.ts +++ b/apps/web-api/src/projects/projects.service.ts @@ -343,6 +343,7 @@ export class ProjectsService { this.buildNameFilter(name, filter); this.buildFundingFilter(lookingForFunding, filter); this.buildMaintainingTeamFilter(team, filter); + this.buildRecentProjectsFilter(query, filter); return { AND: filter }; @@ -376,22 +377,29 @@ export class ProjectsService { } /** - * This method constructs a dynamic filter query for retrieving recent projects - * created within a specified number of days, based on the 'is_recent' query parameter - * and an environment variable to configure the timeline. + * Constructs a dynamic filter query for retrieving recent projects based on the 'is_recent' query parameter. + * If 'is_recent' is set to 'true', it creates a 'createdAt' filter to retrieve records created within a + * specified number of days. The number of days is configured via an environment variable. + * + * If a filter array is passed, it pushes the 'createdAt' filter to the existing filters. * * @param queryParams - HTTP request query parameters object - * @returns Constructed query with a 'createdAt' filter if 'is_recent' is set to 'true', + * @param filter - Optional existing filter array to which the recent filter will be added if provided + * @returns The constructed query with a 'createdAt' filter if 'is_recent' is 'true', * or an empty object if 'is_recent' is not provided or set to 'false'. */ - buildRecentProjectsFilter(queryParams) { + buildRecentProjectsFilter(queryParams, filter?) { const { isRecent } = queryParams; - if (isRecent === 'true') { - return { - createdAt: { - gte: new Date(Date.now() - (parseInt(process.env.RECENT_RECORD_DURATION_IN_DAYS || '30') * 24 * 60 * 60 * 1000)) - } - }; + const recentFilter = { + createdAt: { + gte: new Date(Date.now() - (parseInt(process.env.RECENT_RECORD_DURATION_IN_DAYS || '30') * 24 * 60 * 60 * 1000)) + } + }; + if (isRecent === 'true' && !filter) { + return recentFilter; + } + if (isRecent === 'true' && filter) { + filter.push(recentFilter); } return {}; } diff --git a/apps/web-api/src/teams/teams.service.ts b/apps/web-api/src/teams/teams.service.ts index 29f43edf3..e1ef48d34 100644 --- a/apps/web-api/src/teams/teams.service.ts +++ b/apps/web-api/src/teams/teams.service.ts @@ -288,7 +288,7 @@ export class TeamsService { technologies, membershipSources, fundingStage, - officeHours + officeHours } = queryParams; const filter:any = []; this.buildNameAndPLNFriendFilter(name, plnFriend, filter); @@ -297,6 +297,7 @@ export class TeamsService { this.buildMembershipSourcesFilter(membershipSources, filter); this.buildFundingStageFilter(fundingStage, filter); this.buildOfficeHoursFilter(officeHours, filter); + this.buildRecentTeamsFilter(queryParams, filter); return { AND: filter }; @@ -397,25 +398,32 @@ export class TeamsService { } } + /** - * This method constructs a dynamic filter query for retrieving recent teams - * created within a specified number of days, based on the 'is_recent' query parameter - * and an environment variable to configure the timeline. + * Constructs a dynamic filter query for retrieving recent teams based on the 'is_recent' query parameter. + * If 'is_recent' is set to 'true', it creates a 'createdAt' filter to retrieve records created within a + * specified number of days. The number of days is configured via an environment variable. + * + * If a filter array is passed, it pushes the 'createdAt' filter to the existing filters. * * @param queryParams - HTTP request query parameters object - * @returns Constructed query with a 'createdAt' filter if 'is_recent' is set to 'true', + * @param filter - Optional existing filter array to which the recent filter will be added if provided + * @returns The constructed query with a 'createdAt' filter if 'is_recent' is 'true', * or an empty object if 'is_recent' is not provided or set to 'false'. */ - buildRecentTeamsFilter(queryParams) { + buildRecentTeamsFilter(queryParams, filter?) { const { isRecent } = queryParams; - if (isRecent === 'true') { - return { - createdAt: { - gte: new Date(Date.now() - (parseInt(process.env.RECENT_RECORD_DURATION_IN_DAYS || '30') * 24 * 60 * 60 * 1000)) - } - }; + const recentFilter = { + createdAt: { + gte: new Date(Date.now() - (parseInt(process.env.RECENT_RECORD_DURATION_IN_DAYS || '30') * 24 * 60 * 60 * 1000)) + } + }; + if (isRecent === 'true' && !filter) { + return recentFilter; + } + if (isRecent === 'true' && filter) { + filter.push(recentFilter); } return {}; } - }