Skip to content

Commit

Permalink
fix: fixed issue in focus area team/project count
Browse files Browse the repository at this point in the history
  - while applying isRecent filter
  • Loading branch information
navneethkrish authored and madan-ideas2it committed Oct 15, 2024
1 parent 1a97482 commit d6164e4
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 64 deletions.
6 changes: 5 additions & 1 deletion apps/web-api/src/members/members.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions apps/web-api/src/members/members.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -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: {
Expand Down
25 changes: 5 additions & 20 deletions apps/web-api/src/pl-events/pl-event-guests.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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: {
Expand Down Expand Up @@ -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);
Expand Down
35 changes: 18 additions & 17 deletions apps/web-api/src/pl-events/pl-events.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -98,20 +113,6 @@ export class PLEventsService {
}
}
}
}:{
select: {
team: {
select:{
name: true,
logo: true
}
},
event: {
select: {
type: true
}
}
}
}
}
});
Expand Down
30 changes: 19 additions & 11 deletions apps/web-api/src/projects/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down Expand Up @@ -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 {};
}
Expand Down
34 changes: 21 additions & 13 deletions apps/web-api/src/teams/teams.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ export class TeamsService {
technologies,
membershipSources,
fundingStage,
officeHours
officeHours
} = queryParams;
const filter:any = [];
this.buildNameAndPLNFriendFilter(name, plnFriend, filter);
Expand All @@ -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
};
Expand Down Expand Up @@ -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 {};
}

}

0 comments on commit d6164e4

Please sign in to comment.