Skip to content

Commit

Permalink
format: format the code
Browse files Browse the repository at this point in the history
  • Loading branch information
Behzad-rabiei committed Dec 26, 2024
1 parent 9662107 commit 2825d62
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 28 deletions.
6 changes: 5 additions & 1 deletion src/constants/neo4j.constant.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { PlatformNames } from '@togethercrew.dev/db';

export const SUPPORTED_NEO4J_PLATFORMS = [PlatformNames.Discord, PlatformNames.Discourse, PlatformNames.Telegram] as const;
export const SUPPORTED_NEO4J_PLATFORMS = [
PlatformNames.Discord,
PlatformNames.Discourse,
PlatformNames.Telegram,
] as const;
export const NEO4J_PLATFORM_INFO = {
[PlatformNames.Discord]: {
platform: 'DiscordPlatform',
Expand Down
4 changes: 1 addition & 3 deletions src/services/telegram/heatmap.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ const logger = parentLogger.child({ module: 'DiscourseHeatmapService' });
* @returns {Array<Array<number>>}
*/
async function getHeatmapChart(platformConnection: Connection, body: any) {
const { startDate, endDate} = body;
const { startDate, endDate } = body;
try {
let matchStage: any = {
$and: [{ date: { $gte: new Date(startDate) } }, { date: { $lte: new Date(endDate) } }],
};


const heatmaps = await platformConnection.models.HeatMap.aggregate([
// Stage1 : convert date from string to date type and extract needed data
{
Expand Down Expand Up @@ -91,7 +90,6 @@ async function lineGraph(platformConnection: Connection, startDate: Date, endDat
chat_messages: 1,
replier: 1,
reacter: 1,

},
},

Expand Down
4 changes: 2 additions & 2 deletions src/services/telegram/memberActivity.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import NodeStats from '../../utils/enums/nodeStats.enum';

const logger = parentLogger.child({ module: 'DiscourseMemberActivityService' });

function getNgu(user:any): string {
function getNgu(user: any): string {
const { first_name, last_name, username } = user.options;
const combinedName = [first_name, last_name].filter(Boolean).join(" ");
const combinedName = [first_name, last_name].filter(Boolean).join(' ');
return combinedName || username;
}

Expand Down
28 changes: 6 additions & 22 deletions src/services/telegram/members.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ type Options = {
page?: string;
};


function getNgu(user: any): string {
const { firstName, lastName, username } = user;
const combinedName = [firstName, lastName].filter(Boolean).join(" ");
const combinedName = [firstName, lastName].filter(Boolean).join(' ');
return combinedName || username;
}
/**
Expand Down Expand Up @@ -72,10 +71,7 @@ async function queryMembersForTables(
// If 'others' was already handled, we combine conditions
if (matchStage.id) {
matchStage = {
$or: [
{ id: { $in: specificActivityIds } },
matchStage,
],
$or: [{ id: { $in: specificActivityIds } }, matchStage],
};
} else {
matchStage.id = { $in: specificActivityIds };
Expand All @@ -94,10 +90,7 @@ async function queryMembersForTables(
// If matchStage is already non-empty, combine with $and
if (Object.keys(matchStage).length > 0) {
matchStage = {
$and: [
matchStage,
{ $or: orNgu },
],
$and: [matchStage, { $or: orNgu }],
};
} else {
// Otherwise, just set the or
Expand All @@ -110,29 +103,20 @@ async function queryMembersForTables(
const date = new Date(memberActivityDocument.date);
date.setHours(23, 59, 59, 999);

const orJoinedAt = [
{ joined_at: null },
{ joined_at: { $lte: date } },
];
const orJoinedAt = [{ joined_at: null }, { joined_at: { $lte: date } }];

// Merge it with existing matchStage via $and
if (Object.keys(matchStage).length > 0) {
matchStage = {
$and: [
matchStage,
{ $or: orJoinedAt },
],
$and: [matchStage, { $or: orJoinedAt }],
};
} else {
matchStage.$or = orJoinedAt;
}
}

// Count total documents
const totalResults = await platformConnection.db
.collection('rawmembers')
.countDocuments(matchStage);

const totalResults = await platformConnection.db.collection('rawmembers').countDocuments(matchStage);

// Get the paginated results
const results = await platformConnection.db
Expand Down

0 comments on commit 2825d62

Please sign in to comment.