Skip to content

Conversation

@ahmed-elgaml11
Copy link

Apply authentication middleware and server-side validation, and implement a course, topic, and track endpoints with course-completion feature

ahmed elgaml added 3 commits August 16, 2025 05:25
…ctions for courses and topics and tracks with server-side validation and aplly authntication middleware
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements a course completion feature with authentication middleware and server-side validation. It introduces comprehensive API endpoints for managing tracks, courses, topics, and user completion tracking.

  • Authentication middleware integration for protected endpoints
  • Course completion tracking system with user-specific progress calculation
  • RESTful API structure with validation schemas for tracks, courses, and topics

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
apps/api/src/services/tracks.ts Service layer for track data retrieval operations
apps/api/src/services/topics.ts Topic services including completion/incompletion functionality
apps/api/src/services/courses.ts Course services with progress tracking and topic completion queries
apps/api/src/schemas/tracks.ts Zod validation schemas for track endpoint parameters
apps/api/src/schemas/topics.ts Zod validation schemas for topic endpoint parameters
apps/api/src/schemas/courses.ts Zod validation schemas for course endpoint parameters
apps/api/src/routes/tracks.ts Track endpoints with progress calculation logic
apps/api/src/routes/topics.ts Topic CRUD operations and completion endpoints
apps/api/src/routes/index.ts Main router configuration and endpoint registration
apps/api/src/routes/courses.ts Course endpoints with filtering and progress tracking
apps/api/src/app.ts Application setup with API route integration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@@ -0,0 +1,60 @@
import exprees from "express";
const router = exprees.Router();
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

The import statement has a typo. 'exprees' should be 'express'.

Suggested change
const router = exprees.Router();
import express from "express";
const router = express.Router();

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,40 @@
import exprees from "express";
const router = exprees.Router();
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

The import statement has a typo. 'exprees' should be 'express'.

Suggested change
const router = exprees.Router();
import express from "express";
const router = express.Router();

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,70 @@
import exprees from "express";
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

The import statement has a typo. 'exprees' should be 'express'.

Copilot uses AI. Check for mistakes.
});
};
export const inCompleteTopic = async (userId: string, topicId: string) => {
prisma.userCompletion.delete({
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

Missing 'return' or 'await' statement. The delete operation is not being returned or awaited, which could cause issues with error handling and response timing.

Suggested change
prisma.userCompletion.delete({
return await prisma.userCompletion.delete({

Copilot uses AI. Check for mistakes.
});
};

export const getToltalTopics = async (courseId: string) => {
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

Function name has a typo. 'getToltalTopics' should be 'getTotalTopics'.

Suggested change
export const getToltalTopics = async (courseId: string) => {
export const getTotalTopics = async (courseId: string) => {

Copilot uses AI. Check for mistakes.
});
};

export const getToltalTopics = async (courseId: string) => {
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

Function name has a typo. 'getToltalTopics' should be 'getTotalTopics'.

Suggested change
export const getToltalTopics = async (courseId: string) => {
export const getTotalTopics = async (courseId: string) => {

Copilot uses AI. Check for mistakes.
},
});
};

Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

Duplicate function 'getToltalTopics' exists in both courses.ts and topics.ts services. Consider consolidating this logic to avoid code duplication.

Suggested change

Copilot uses AI. Check for mistakes.
res.status(200).json({
course,
totalTopics,
persentage,
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

Variable name has a typo. 'persentage' should be 'percentage'.

Suggested change
persentage,
const percentage = (completedTopics.length / totalTopics.length) * 100;
res.status(200).json({
course,
totalTopics,
percentage,

Copilot uses AI. Check for mistakes.

let filterdTopics;
if (completed === "true") {
filterdTopics = completedTopics;
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

Variable name has a typo. 'filterdTopics' should be 'filteredTopics'.

Suggested change
filterdTopics = completedTopics;
let filteredTopics;
if (completed === "true") {
filteredTopics = completedTopics;

Copilot uses AI. Check for mistakes.
req.user!.id,
req.params.courseId,
);
const persentage = (completedTopics.length / totalTopics.length) * 100;
Copy link

Copilot AI Aug 19, 2025

Choose a reason for hiding this comment

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

Division by zero error possible. If totalTopics.length is 0, this will result in NaN. Add a check to handle the case when there are no topics.

Suggested change
const persentage = (completedTopics.length / totalTopics.length) * 100;
const persentage =
totalTopics.length === 0
? 0
: (completedTopics.length / totalTopics.length) * 100;

Copilot uses AI. Check for mistakes.
@saifsweelam saifsweelam changed the base branch from main to dev August 19, 2025 20:00
@saifsweelam saifsweelam merged commit 180417a into IEEEManCSC:dev Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants