Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 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] 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 All @@ -10,4 +14,8 @@ export const NEO4J_PLATFORM_INFO = {
platform: 'DiscoursePlatform',
member: 'DiscourseMember',
},
[PlatformNames.Telegram]: {
platform: 'TelegramPlatform',
member: 'TelegramMember',
},
Comment on lines +17 to +20
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Include Telegram in SUPPORTED_NEO4J_PLATFORMS
You’ve added Telegram to NEO4J_PLATFORM_INFO, but SUPPORTED_NEO4J_PLATFORMS remains [Discord, Discourse]. If you intend to fully support Telegram, add it to SUPPORTED_NEO4J_PLATFORMS as well.

};
2 changes: 2 additions & 0 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import categoryController from './category.controller';
import moduleController from './module.controller';
import discourseController from './discourse.controller';
import nftController from './nft.controller';
import telegramController from './telegram.controller';

export {
authController,
Expand All @@ -24,4 +25,5 @@ export {
moduleController,
discourseController,
nftController,
telegramController,
};
140 changes: 140 additions & 0 deletions src/controllers/telegram.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
import { Response } from 'express';
import moment from 'moment-timezone';

import { DatabaseManager } from '@togethercrew.dev/db';

import { activityCompostionsTypes } from '../config/memberBreakDownTables';
import { IAuthAndPlatform } from '../interfaces/Request.interface';
import { telegramService } from '../services';
import { SupportedNeo4jPlatforms } from '../types/neo4j.type';
import { catchAsync, charts, date, pick } from '../utils';

const heatmapChart = catchAsync(async function (req: IAuthAndPlatform, res: Response) {
const platformConnection = await DatabaseManager.getInstance().getPlatformDb(req.platform?.id);
let heatmaps = await telegramService.heatmapService.getHeatmapChart(platformConnection, req.body);
const timeZoneOffset = parseInt(moment().tz(req.body.timeZone).format('Z'));

if (timeZoneOffset !== 0) {
heatmaps = date.shiftHeatmapsHours(heatmaps, timeZoneOffset);
}
heatmaps = charts.fillHeatmapChart(heatmaps);
res.send(heatmaps);
});

const lineGraph = catchAsync(async function (req: IAuthAndPlatform, res: Response) {
const platformConnection = await DatabaseManager.getInstance().getPlatformDb(req.platform?.id);
let lineGraph = await telegramService.heatmapService.lineGraph(
platformConnection,
req.body.startDate,
req.body.endDate,
);
lineGraph = charts.fillHeatmapLineGraph(lineGraph, req.body.startDate, req.body.endDate);
res.send(lineGraph);
});

const membersInteractionsNetworkGraph = catchAsync(async function (req: IAuthAndPlatform, res: Response) {
const networkGraphData = await telegramService.memberActivityService.getMembersInteractionsNetworkGraph(
req.platform.id,
req.platform?.name as SupportedNeo4jPlatforms,
);
res.send(networkGraphData);
});

const activeMembersCompositionTable = catchAsync(async function (req: IAuthAndPlatform, res: Response) {
const filter = pick({ ...req.query, ...req.body }, ['activityComposition', 'ngu']);
const options = pick(req.query, ['sortBy', 'limit', 'page']);
const platformConnection = await DatabaseManager.getInstance().getPlatformDb(req.platform?.id);
const activityCompostionFields =
telegramService.memberActivityService.getActivityCompositionOfActiveMembersComposition();
const memberActivity = await telegramService.memberActivityService.getLastDocumentForTablesUsage(
platformConnection,
activityCompostionFields,
);
const members = await telegramService.membersService.queryMembersForTables(
platformConnection,
filter,
options,
memberActivity,
activityCompostionsTypes.activeMembersComposition,
);
if (members) {
members.results.forEach((member) => {
member.ngu = telegramService.membersService.getNgu(member);
member.activityComposition = telegramService.memberActivityService.getActivityComposition(
member,
memberActivity,
filter.activityComposition,
);
});
}
res.send(members);
});

const activeMembersOnboardingTable = catchAsync(async function (req: IAuthAndPlatform, res: Response) {
const filter = pick({ ...req.query, ...req.body }, ['activityComposition', 'ngu']);
const options = pick(req.query, ['sortBy', 'limit', 'page']);
const platformConnection = await DatabaseManager.getInstance().getPlatformDb(req.platform?.id);
const activityCompostionFields =
telegramService.memberActivityService.getActivityCompositionOfActiveMembersOnboarding();
const memberActivity = await telegramService.memberActivityService.getLastDocumentForTablesUsage(
platformConnection,
activityCompostionFields,
);
const members = await telegramService.membersService.queryMembersForTables(
platformConnection,
filter,
options,
memberActivity,
activityCompostionsTypes.activeMembersOnboarding,
);
if (members) {
members.results.forEach((member) => {
member.ngu = telegramService.membersService.getNgu(member);
member.activityComposition = telegramService.memberActivityService.getActivityComposition(
member,
memberActivity,
filter.activityComposition,
);
});
}
res.send(members);
});

const disengagedMembersCompositionTable = catchAsync(async function (req: IAuthAndPlatform, res: Response) {
const filter = pick({ ...req.query, ...req.body }, ['activityComposition', 'ngu']);
const options = pick(req.query, ['sortBy', 'limit', 'page']);
const platformConnection = await DatabaseManager.getInstance().getPlatformDb(req.platform?.id);
const activityCompostionFields =
telegramService.memberActivityService.getActivityCompositionOfDisengagedComposition();
const memberActivity = await telegramService.memberActivityService.getLastDocumentForTablesUsage(
platformConnection,
activityCompostionFields,
);
const members = await telegramService.membersService.queryMembersForTables(
platformConnection,
filter,
options,
memberActivity,
activityCompostionsTypes.disengagedMembersCompostion,
);
if (members) {
members.results.forEach((member) => {
member.ngu = telegramService.membersService.getNgu(member);
member.activityComposition = telegramService.memberActivityService.getActivityComposition(
member,
memberActivity,
filter.activityComposition,
);
});
}
res.send(members);
});

export default {
heatmapChart,
lineGraph,
membersInteractionsNetworkGraph,
activeMembersCompositionTable,
activeMembersOnboardingTable,
disengagedMembersCompositionTable,
};
2 changes: 1 addition & 1 deletion src/docs/discourse.doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ paths:
[
'all_new_disengaged',
'all_disengaged_were_newly_active',
'all_disengaged_were_consistenly_active',
'all_disengaged_were_consistently_active',
'all_disengaged_were_vital',
'others',
]
Expand Down
18 changes: 9 additions & 9 deletions src/docs/memberActivity.doc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ paths:
post:
tags:
- [Member-Activity]
summary: Get data for inactive members line graph - discord only
summary: Get data for inactive members line graph - Discord, Discourse and Telegram
security:
- bearerAuth: []
parameters:
Expand Down Expand Up @@ -229,7 +229,7 @@ paths:
post:
tags:
- [Member-Activity]
summary: Get data for active members interactions graph - discord only
summary: Get data for active members interactions graph - Discord, Discourse and Telegram
security:
- bearerAuth: []
parameters:
Expand Down Expand Up @@ -333,7 +333,7 @@ paths:
get:
tags:
- [Member-Activity]
summary: Get data for fragmentation score - discord only
summary: Get data for fragmentation score - Discord, Discourse and Telegram
security:
- bearerAuth: []
parameters:
Expand Down Expand Up @@ -382,7 +382,7 @@ paths:
get:
tags:
- [Member-Activity]
summary: Get data for decentralisation score - discord only
summary: Get data for decentralisation score - Discord, Discourse and Telegram
security:
- bearerAuth: []
parameters:
Expand Down Expand Up @@ -431,7 +431,7 @@ paths:
post:
tags:
- [Member-Activity]
summary: Get data for active members onboarding line graph - discord only
summary: Get data for active members onboarding line graph - Discord, Discourse and Telegram
security:
- bearerAuth: []
parameters:
Expand Down Expand Up @@ -510,7 +510,7 @@ paths:
post:
tags:
- [Member-Activity]
summary: Get data for active members composition table - discord only
summary: Get data for active members composition table - Discord, Discourse and Telegram
security:
- bearerAuth: []
description: for now sortBy just can apply for ngu and joinedAt(DaoMemberSince in UI)
Expand Down Expand Up @@ -655,7 +655,7 @@ paths:
post:
tags:
- [Member-Activity]
summary: Get data for active members onboarding table - discord only
summary: Get data for active members onboarding table - Discord, Discourse and Telegram
security:
- bearerAuth: []
description: for now sortBy just can apply for ngu and joinedAt(DaoMemberSince in UI)
Expand Down Expand Up @@ -800,7 +800,7 @@ paths:
post:
tags:
- [Member-Activity]
summary: Get data for disengaged members composition table - discord only
summary: Get data for disengaged members composition table - Discord, Discourse and Telegram
security:
- bearerAuth: []
description: for now sortBy just can apply for ngu and joinedAt(DaoMemberSince in UI)
Expand All @@ -821,7 +821,7 @@ paths:
[
'all_new_disengaged',
'all_disengaged_were_newly_active',
'all_disengaged_were_consistenly_active',
'all_disengaged_were_consistently_active',
'all_disengaged_were_vital',
'others',
]
Expand Down
Loading
Loading