/full-stack-assignment

1. backend

Primary LanguageJavaScript

This code snippet is a basic Node.js server using the Express framework to handle HTTP requests. Here's a breakdown of its key features:

  1. Server Setup: The server is set up to listen on port 3001 the app.listen method.

  2. Signup Endpoint: When a POST request is to '/signup', the server expects to receive an email and password in the request body. It then adds the email and password to the USERS array, but only if the user with the given email doesn't already exist. It responds with a status code 200 regardless of the outcome.

3.Login Endpoint**: When a POST request is made to '/login', the server expects to receive an email and password in the request body. It then checks if a user with the provided email exists in the USERS array and verifies if the password matches. If the password matches, it responds with a status code 200 sends back a token. If the password doesn't match, it responds with a status code 401.

4 Questions Endpoint: When a GET request is made to '/', the server responds with all the questions in the QUESTIONS array.

  1. Sub Endpoint: When a GET request is made to '/submissions the server should return the user's submissions for a specific problem, but the logic for this is not yet implemented.

  2. When a POST request is to '/submissions', the server should let the user submit a problem. However, the logic for accepting or rejecting the solution randomly and storing the submission in the SUBMISSION array is not yet implemented. The server responds with a 'Hello World!' message.

  3. The code also includes a comment about creating a route that an admin add a new problem and ensuring that only admins can do that, but it's as a hard todo and is not yet implemented.

Overall, server handles user sign-up, login, retrieval of questions, and submission of problems, but some functionalities are not fully implemented as indicated by the comments in the code.