Skip to content

Conversation

@triantafillos
Copy link
Owner

This pull request adds a new /users/:id API endpoint to server.js for retrieving user information by ID, including proper error handling for invalid or missing users. It also updates the server startup logs to mention the new endpoint.

New API endpoint and logging:

  • Added a mock users database and a /users/:id GET endpoint that returns user data for a given ID, with validation for numeric IDs and 404 handling if the user is not found.
  • Updated the server startup message to include the /users/[id] endpoint.

@triantafillos triantafillos requested a review from Copilot November 7, 2025 22:28
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 adds a new REST API endpoint for retrieving users by ID, including proper error handling for invalid inputs and non-existent users.

Key changes:

  • Added a mock users database with three sample users
  • Implemented GET /users/:id endpoint with input validation and 404 handling
  • Added console log for the new endpoint on server startup
Comments suppressed due to low confidence (1)

server.js:1

  • The endpoint exposes user email addresses in the response. Consider whether this is intentional or if sensitive user data should be filtered from API responses to prevent data exposure.
const express = require('express');

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +47 to +51
// Validate that id is a number
if (isNaN(userId)) {
return res.status(400).json({
error: 'Invalid user ID',
message: 'User ID must be a number',
Copy link

Copilot AI Nov 7, 2025

Choose a reason for hiding this comment

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

The validation for isNaN(userId) does not handle negative numbers or zero, which may not be valid user IDs based on the current data model (IDs start at 1). Consider adding validation to reject non-positive integers: if (isNaN(userId) || userId <= 0) with an appropriate error message.

Suggested change
// Validate that id is a number
if (isNaN(userId)) {
return res.status(400).json({
error: 'Invalid user ID',
message: 'User ID must be a number',
// Validate that id is a positive integer
if (isNaN(userId) || userId <= 0) {
return res.status(400).json({
error: 'Invalid user ID',
message: 'User ID must be a positive integer',

Copilot uses AI. Check for mistakes.
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