Skip to content

Commit a217286

Browse files
Kalash ShahKalash Shah
Kalash Shah
authored and
Kalash Shah
committed
📝 function documentations
1 parent 87a8ae5 commit a217286

File tree

7 files changed

+171
-13
lines changed

7 files changed

+171
-13
lines changed

src/app.controller.ts

-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@ import { GithubCallbackQuery } from './constants/profile.types';
1919
export class AppController {
2020
constructor(private readonly appService: AppService) {}
2121

22-
@Get()
23-
getHello(): string {
24-
return this.appService.getHello2();
25-
}
26-
2722
@Get('/error')
2823
@Render('error')
2924
error(@Query('message') message: string) {

src/app.service.ts

+14-8
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ import {
1010
GITHUB_SECRET_KEY,
1111
} from './constants/env';
1212
import { PrismaService } from 'prisma/prisma.service';
13+
import { CloudinaryService } from './cloudinary/cloudinary.service';
1314
import { GithubCallbackQuery } from './constants/profile.types';
1415
import * as jwt from 'jsonwebtoken';
1516
import { decode } from './constants/decode';
16-
import { CloudinaryService } from './cloudinary/cloudinary.service';
1717

1818
@Injectable()
1919
export class AppService {
@@ -22,13 +22,12 @@ export class AppService {
2222
private cloudinary: CloudinaryService,
2323
) {}
2424

25-
getHello(): string {
26-
return 'Hello from B-704';
27-
}
28-
getHello2(): string {
29-
return '8 CPI Boi - Akhilesh Manda';
30-
}
31-
25+
/**
26+
* It takes a query object as input, verifies the state and code, and then uses the code to get an
27+
* access token from Github
28+
* @param {GithubCallbackQuery} query - GithubCallbackQuery
29+
* @returns A string
30+
*/
3231
async githubCallback(query: GithubCallbackQuery): Promise<string> {
3332
const { code, state } = query;
3433
if (!code || !state) {
@@ -88,6 +87,13 @@ export class AppService {
8887
}
8988
}
9089

90+
/**
91+
* It uploads a profile picture to Cloudinary, deletes the old profile picture from Cloudinary, and
92+
* updates the user's profile picture in the database
93+
* @param file - Express.Multer.File - This is the file that was uploaded by the user.
94+
* @param {string} token - The token that was sent to the client when they logged in.
95+
* @returns The secure_url of the uploaded image
96+
*/
9197
async uploadProfilePicture(
9298
file: Express.Multer.File,
9399
token: string,

src/constants/notifications.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/**
2+
* Function to create a notification message for when a user starts following.
3+
* @param {string} name - The name of the user who started following.
4+
* @returns Returns a string containing the notification message.
5+
*/
16
export const followingNotification = (name: string) => {
27
return `${name} started following you, do you want to follow back?`;
38
};

src/constants/profile.data.ts

+53
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ const GET_CONTRIBUTION_GRAPH_QUERY = `query ($userName: String!) {
2727
}
2828
}`;
2929

30+
/**
31+
* It takes a Github token as an argument and returns the Github username associated with that token
32+
* @param {string} githubToken - The token that we got from the Github OAuth flow.
33+
* @returns The username of the user who is logged in.
34+
*/
3035
export const getGithubUsername = async (githubToken: string) => {
3136
try {
3237
const response = await axios.get(`https://api.github.com/user`, {
@@ -43,6 +48,13 @@ interface GithubCalendarData {
4348
weeks: [{ contributionDays: [{ contributionCount: number; date: Date }] }];
4449
}
4550

51+
/**
52+
* It takes a Github username and a Github token as arguments, and returns a promise that resolves to
53+
* the Github contribution graph data
54+
* @param {string} githubUsername - The username of the Github user whose contribution graph you want to fetch.
55+
* @param {string} githubToken - This is the token was generated from the users Github account.
56+
* @returns GithubCalendarData
57+
*/
4658
export const getGithubContributionGraph = async (
4759
githubUsername: string,
4860
githubToken: string,
@@ -71,6 +83,12 @@ query getUserProfile($username: String!) {
7183
}
7284
}`;
7385

86+
/**
87+
* It makes a POST request to the Leetcode GraphQL API with the username as a variable, and returns the submission calendar data
88+
* @param {string} leetcodeUsername - The username of the user whose contribution graph you want to
89+
* fetch.
90+
* @returns An array of objects containing the date and the number of submissions on that date.
91+
*/
7492
export const getLeetcodeContributionGraph = async (
7593
leetcodeUsername: string,
7694
) => {
@@ -139,6 +157,11 @@ interface CodeforcesSubmission {
139157
timeConsumedMillis: number;
140158
memoryConsumedBytes: number;
141159
}
160+
/**
161+
* It takes a Codeforces username as an argument and returns an array of submissions made by that user
162+
* @param {string} codeforcesUsername - The username of the user whose submissions you want to fetch.
163+
* @returns An array of CodeforcesSubmission objects
164+
*/
142165

143166
export const getCodeforcesContributionGraph = async (
144167
codeforcesUsername: string,
@@ -176,6 +199,13 @@ query($userName: String!) {
176199
}
177200
`;
178201

202+
/**
203+
* It takes a GitHub username and a GitHub token, and returns a list of pinned repositories for that
204+
* user
205+
* @param {string} username - The username of the user whose pinned repos you want to fetch.
206+
* @param {string} githubToken - This is the token that you get from the GitHub API.
207+
* @returns An array of Repository objects
208+
*/
179209
export const pinnedRepos = async (
180210
username: string,
181211
githubToken: string,
@@ -188,6 +218,11 @@ export const pinnedRepos = async (
188218
return response.data.data.user.pinnedItems.nodes;
189219
};
190220

221+
/**
222+
* It takes a Codeforces username as a parameter and returns an array of CFRating objects
223+
* @param {string} codeforcesUsername - The username of the user whose rating graph you want to fetch.
224+
* @returns CFRating[]
225+
*/
191226
export const getCFRatingGraph = async (
192227
codeforcesUsername: string,
193228
): Promise<CFRating[]> => {
@@ -205,6 +240,12 @@ export const getCFRatingGraph = async (
205240
throw new Error('Incorrect Codeforces username');
206241
}
207242
};
243+
/**
244+
* It takes a Codeforces username as input and returns an object containing an array of tags and an
245+
* array of ratings
246+
* @param {string} codeforcesUsername - The username of the user whose submissions you want to fetch.
247+
* @returns An object with two arrays, one for tags and one for ratings
248+
*/
208249

209250
export const getCFTagandProblemGraph = async (
210251
codeforcesUsername: string,
@@ -329,6 +370,13 @@ query userInfo($userName: String!) {
329370
}
330371
}`;
331372

373+
/**
374+
* It takes a GitHub username and a GitHub token, and returns an object containing the user's language
375+
* graph, statistics graph, and streak graph
376+
* @param {string} githubUsername - The username of the user you want to get the data for.
377+
* @param {string} githubToken - This is the token that you get from the github developer settings.
378+
* @returns GithubGraphsOutput
379+
*/
332380
export const getGithubGraphsTogether = async (
333381
githubUsername: string,
334382
githubToken: string,
@@ -519,6 +567,11 @@ query data($username: String!) {
519567
}
520568
`;
521569

570+
/**
571+
* It makes a POST request to the Leetcode GraphQL API, and returns the data in a more readable format
572+
* @param {string} leetcodeUsername - The username of the user you want to get the graphs for.
573+
* @returns LeetcodeGraphsOutput
574+
*/
522575
export const getLeetcodeGraphs = async (
523576
leetcodeUsername: string,
524577
): Promise<LeetcodeGraphsOutput> => {

src/dashboard/dashboard.service.ts

+56
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ import { HttpException, HttpStatus } from '@nestjs/common';
2626
export class DashboardService {
2727
constructor(private prisma: PrismaService) {}
2828

29+
/**
30+
* It takes a userId and a token, decodes the token, finds the user, creates a contribution graph
31+
* object, fills it with data from Codeforces, Github and Leetcode, and returns the contribution graph
32+
* object
33+
* @param {string} userId - The userId of the user whose contribution graph is to be fetched.
34+
* @param {string} token - The token that was generated when the user logged in.
35+
* @returns A contribution graph object
36+
*/
2937
async getContributionGraph(
3038
userId: string,
3139
token: string,
@@ -61,6 +69,13 @@ export class DashboardService {
6169
return contributionGraph;
6270
}
6371

72+
/**
73+
* It takes a userId and a token, decodes the token, finds the user, and then returns the pinned
74+
* repos from the user's github account
75+
* @param {string} userId - The userId of the user who's pinned repos we want to get
76+
* @param {string} token - The token that was generated when the user logged in.
77+
* @returns An array of pinned repos
78+
*/
6479
async getPinnedRepos(userId: string, token: string) {
6580
await decode(token, this.prisma);
6681
let user: User;
@@ -85,6 +100,13 @@ export class DashboardService {
85100
return [];
86101
}
87102

103+
/**
104+
* It takes in a userId and a token, verifies the token, and then fetches the Codeforces username
105+
* from the database and uses it to fetch the Codeforces graphs
106+
* @param {string} userId - The userId of the user whose graphs are to be fetched.
107+
* @param {string} token - The token that is generated when the user logs in.
108+
* @returns the CodeforcesGraphsOutput object.
109+
*/
88110
async codeforcesGraphs(
89111
userId: string,
90112
token: string,
@@ -119,6 +141,13 @@ export class DashboardService {
119141
return null;
120142
}
121143

144+
/**
145+
* It takes in a userId and a token, decodes the token, finds the user in the database, and then uses
146+
* the user's github token to get their github graphs
147+
* @param {string} userId - The userId of the user who's github token we want to use
148+
* @param {string} token - The token that was generated by the login mutation.
149+
* @returns GithubGraphsOutput | null
150+
*/
122151
async githubGraphs(
123152
userId: string,
124153
token: string,
@@ -145,6 +174,13 @@ export class DashboardService {
145174
}
146175
}
147176

177+
/**
178+
* It takes in a userId and a token, decodes the token, finds the user with the userId, and then
179+
* returns the leetcode graphs of the user if the user has a leetcode username
180+
* @param {string} userId - The userId of the user who's leetcode graphs we want to fetch
181+
* @param {string} token - The token that was generated when the user logged in.
182+
* @returns LeetcodeGraphsOutput
183+
*/
148184
async leetcodeGraphs(
149185
userId: string,
150186
token: string,
@@ -170,6 +206,12 @@ export class DashboardService {
170206
}
171207
}
172208

209+
/**
210+
* It takes a user object and a contribution graph object as parameters, and then it fills the
211+
* contribution graph object with the user's Codeforces data
212+
* @param {User} user - User - The user object that we are getting the contribution graph for.
213+
* @param {ContributionGraph} contributionGraph - This is the object that we will be returning to the user.
214+
*/
173215
async fillCodeforcesData(user: User, contributionGraph: ContributionGraph) {
174216
if (user.codeforcesUsername) {
175217
try {
@@ -202,6 +244,12 @@ export class DashboardService {
202244
}
203245
}
204246

247+
/**
248+
* It takes a user object and a contribution graph object, and if the user has a leetcode username,
249+
* it fetches the leetcode contribution graph and adds it to the contribution graph object
250+
* @param {User} user - User - The user object that we get from the database.
251+
* @param {ContributionGraph} contributionGraph - This is the object that we will be returning to the user.
252+
*/
205253
async fillLeetcodeData(user: User, contributionGraph: ContributionGraph) {
206254
if (user.leetcodeUsername) {
207255
try {
@@ -234,6 +282,14 @@ export class DashboardService {
234282
}
235283
}
236284

285+
/**
286+
* It takes a user and a contribution graph as input, and if the user has a github token, it fetches
287+
* the user's github contribution data and adds it to the contribution graph
288+
* @param {User} user - User - The user object that is passed in from the controller.
289+
* @param {ContributionGraph} contributionGraph - This is the object that we will be returning to the
290+
* user. It contains the total contributions, total github contributions, and an array of
291+
* contributions.
292+
*/
237293
async fillGithubData(user: User, contributionGraph: ContributionGraph) {
238294
if (user.githubToken) {
239295
try {

src/mail/mail.service.ts

+10
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import { HttpException, HttpStatus } from '@nestjs/common';
88
export class MailService {
99
constructor(private mailerService: MailerService) {}
1010

11+
/**
12+
* It sends an email to the user's email address with a 6-digit code
13+
* @param {User} user - User - The user object that we want to send the email to.
14+
* @param {string} code - The 6-digit code that will be sent to the user's email.
15+
*/
1116
async sendUserConfirmation(user: User, code: string) {
1217
try {
1318
await this.mailerService.sendMail({
@@ -27,6 +32,11 @@ export class MailService {
2732
}
2833
}
2934

35+
/**
36+
* It sends an email to the user's email address with a 6-digit code to reset their password
37+
* @param {User} user - User - The user object that we want to send the email to.
38+
* @param {string} code - The 6-digit code that will be sent to the user's email.
39+
*/
3040
async sendPasswordReset(user: User, code: string) {
3141
try {
3242
await this.mailerService.sendMail({

src/notification/notification.service.ts

+33
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ import { HttpException, HttpStatus } from '@nestjs/common';
99
export class NotificationService {
1010
constructor(private prisma: PrismaService) {}
1111

12+
/**
13+
* It deletes all previous notifications of the same type from the same user, then creates a new
14+
* notification
15+
* @param {string} toUser - The user who will receive the notification
16+
* @param {string} description - The description of the notification
17+
* @param {NotificationType} type - NotificationType
18+
* @param {string} [fromUser] - The user who sent the notification
19+
*/
1220
async sendNotification(
1321
toUser: string,
1422
description: string,
@@ -54,6 +62,14 @@ export class NotificationService {
5462
}
5563
}
5664

65+
/**
66+
* It takes a notificationId and a token as arguments, decodes the token, and then updates the
67+
* notification with the given notificationId to have a seenStatus of true and a seenAt date of the
68+
* current date
69+
* @param {string} notificationId - The id of the notification to be marked as seen
70+
* @param {string} token - The token that was sent to the user's email address.
71+
* @returns The notification that was updated.
72+
*/
5773
async seeNotification(notificationId: string, token: string) {
5874
await decode(token, this.prisma);
5975
try {
@@ -75,6 +91,14 @@ export class NotificationService {
7591
}
7692
}
7793

94+
/**
95+
* It takes an array of notification ids and a token as arguments, decodes the token, and then
96+
* updates the notifications with the given ids to have a seen status of true and a seenAt date of
97+
* the current date
98+
* @param {string[]} notificationIds - The ids of the notifications to be marked as seen
99+
* @param {string} token - The token of the user who is trying to mark the notifications as seen.
100+
* @returns The notifications that were updated
101+
*/
78102
async seeNotifications(notificationIds: string[], token: string) {
79103
await decode(token, this.prisma);
80104
try {
@@ -98,6 +122,12 @@ export class NotificationService {
98122
}
99123
}
100124

125+
/**
126+
* It fetches all the notifications of a user and returns the unseen notifications count and the
127+
* notifications themselves
128+
* @param {string} token - The token of the user who is requesting the notifications
129+
* @returns The notifications of the user.
130+
*/
101131
async notifications(token: string): Promise<NotificationOutput> {
102132
const user = await decode(token, this.prisma);
103133
this.deleteSeenPreviousNotifications();
@@ -154,6 +184,9 @@ export class NotificationService {
154184
}
155185
}
156186

187+
/**
188+
* It deletes all notifications that are older than 24 hours and have been seen by the user
189+
*/
157190
async deleteSeenPreviousNotifications() {
158191
try {
159192
await this.prisma.notification.deleteMany({

0 commit comments

Comments
 (0)