{"id":21964637,"url":"https://github.com/apollo-level2-web-dev/l2-b2-assignment-2","last_synced_at":"2026-03-05T23:03:11.392Z","repository":{"id":208652901,"uuid":"720669724","full_name":"Apollo-Level2-Web-Dev/L2-B2-assignment-2","owner":"Apollo-Level2-Web-Dev","description":"Assignment-2 (Batch-2)","archived":false,"fork":false,"pushed_at":"2023-11-22T17:05:18.000Z","size":12,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-01-28T01:16:59.674Z","etag":null,"topics":["assignment","assignment-2","assignment2","batch-2"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Apollo-Level2-Web-Dev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-19T07:50:15.000Z","updated_at":"2024-07-09T23:28:37.000Z","dependencies_parsed_at":"2024-11-29T12:37:28.156Z","dependency_job_id":null,"html_url":"https://github.com/Apollo-Level2-Web-Dev/L2-B2-assignment-2","commit_stats":null,"previous_names":["apollo-level2-web-dev/l2-b2-assignment-2"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apollo-Level2-Web-Dev%2FL2-B2-assignment-2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apollo-Level2-Web-Dev%2FL2-B2-assignment-2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apollo-Level2-Web-Dev%2FL2-B2-assignment-2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Apollo-Level2-Web-Dev%2FL2-B2-assignment-2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Apollo-Level2-Web-Dev","download_url":"https://codeload.github.com/Apollo-Level2-Web-Dev/L2-B2-assignment-2/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245021714,"owners_count":20548392,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assignment","assignment-2","assignment2","batch-2"],"created_at":"2024-11-29T12:26:18.628Z","updated_at":"2026-03-05T23:03:06.352Z","avatar_url":"https://github.com/Apollo-Level2-Web-Dev.png","language":null,"readme":"# Mongoose Express CRUD Mastery\n**Objective:** Develop a Node.js Express application with TypeScript as the programming language, integrating MongoDB with Mongoose for user data and order management. Ensure data integrity through validation using Joi/Zod.\n\n### Set up the Project\n\n- Create a new Node.js Express project.\n- Set up a MongoDB database using Mongoose for storing user and order data.\n\n### Define Data Models\n\n- Create Mongoose models for User data based on the provided data structure. (You can follow sample-data.json file for ideas)\n- Define appropriate data types, validations.\n\n### Data Types List\n\n- `userId` (number): A unique identifier for the user.\n- `username` (string): Denotes the user's unique username, ensuring uniqueness across the system.\n- `password` (string): Represents the user's password. The password is securely stored in hashed form, utilizing the bcrypt algorithm for hashing.\n- `fullName` (object): An object containing the first and last name of the user.\n    - `firstName` (string): The first name of the user.\n    - `lastName` (string): The last name of the user.\n- `age` (number): The age of the user.\n- `email` (string): The email address of the user.\n- `isActive` (boolean): A flag indicating whether the user is active or not.\n- `hobbies` (array of strings): An array containing the hobbies of the user.\n- `address` (object): An object containing the street, city, and country of the user's address.\n    - `street` (string): The street of the user's address.\n    - `city` (string): The city of the user's address.\n    - `country` (string): The country of the user's address.\n- `orders` (array of objects): An array containing the orders of the user.\n    - `productName` (string): The name of the product in the order.\n    - `price` (number): The price of the product in the order.\n    - `quantity` (number): The quantity of the product in the order.\n\n\n## Main Section (50 Marks):\n\n### User Management:\n\n### 1. Create a new user\n\n- Endpoint: **POST /api/users**\n- Request Body:\n\n```json\n{\n    \"userId\": \"number\",\n    \"username\": \"string\",\n    \"password\": \"string\",\n    \"fullName\": {\n        \"firstName\": \"string\",\n        \"lastName\": \"string\"\n    },\n    \"age\": \"number\",\n    \"email\": \"string\",\n    \"isActive\": \"boolean\",\n    \"hobbies\": [\n        \"string\",\n        \"string\"\n    ],\n    \"address\": {\n        \"street\": \"string\",\n        \"city\": \"string\",\n        \"country\": \"string\"\n    }\n}\n```\n\n- Response: Newly created user object. **Make sure that the password field is not included in the response data.**\n\n```json\n{\n    \"success\": true,\n    \"message\": \"User created successfully!\",\n    \"data\": {\n        \"userId\": \"number\",\n        \"username\": \"string\",\n        \"fullName\": {\n            \"firstName\": \"string\",\n            \"lastName\": \"string\"\n        },\n        \"age\": \"number\",\n        \"email\": \"string\",\n        \"isActive\": \"boolean\",\n        \"hobbies\": [\n            \"string\",\n            \"string\"\n        ],\n        \"address\": {\n            \"street\": \"string\",\n            \"city\": \"string\",\n            \"country\": \"string\"\n        }\n    }\n}\n```\n\n### 2. Retrieve a list of all users\n\n- Endpoint: **GET /api/users**\n- Response: List of user objects. Each object should only contain `username`, `fullName`, `age`, `email`, `address` . Apply suitable field filtering to exclusively retrieve the necessary information. \n\n```json\n{\n    \"success\": true,\n    \"message\": \"Users fetched successfully!\",\n    \"data\": [\n        {\n            \"username\": \"string\",\n            \"fullName\": {\n                \"firstName\": \"string\",\n                \"lastName\": \"string\"\n            },\n            \"age\": \"number\",\n            \"email\": \"string\",\n            \"address\": {\n                \"street\": \"string\",\n                \"city\": \"string\",\n                \"country\": \"string\"\n            }\n        },\n        // more objects...\n    ]\n}\n```\n\n### 3. Retrieve a specific user by ID\n\n- Endpoint: **GET /api/users/:userId**\n\n- Response: User object and make sure that the password field is not included in the response data. If you can't find information about the user, show a clear message. Use either `instance` or `static` method to determine if the user exist or not. (Use the [format for error messages](#sample-error-response) that is given below.)\n\n```json\n{\n    \"success\": true,\n    \"message\": \"User fetched successfully!\",\n    \"data\": {\n        \"userId\": \"number\",\n        \"username\": \"string\",\n        \"fullName\": {\n            \"firstName\": \"string\",\n            \"lastName\": \"string\"\n        },\n        \"age\": \"number\",\n        \"email\": \"string\",\n        \"isActive\": \"boolean\",\n        \"hobbies\": [\n            \"string\",\n            \"string\"\n        ],\n        \"address\": {\n            \"street\": \"string\",\n            \"city\": \"string\",\n            \"country\": \"string\"\n        }\n    }\n}\n```\n\n### 4. Update user information\n\n- Endpoint: **PUT /api/users/:userId**\n\n- Request Body: Updated user data (similar structure as in user creation).\n\n- Response: Updated user object and make sure that the password field is not included in the response data. If you can't find information about the user, show a clear message. Use either `instance` or `static` method to determine if the user exist or not.  (Use the [format for error messages](#sample-error-response) that is given below.)\n\n```json\n{\n    \"success\": true,\n    \"message\": \"User updated successfully!\",\n    \"data\": {\n        \"userId\": \"number\",\n        \"username\": \"string\",\n        \"fullName\": {\n            \"firstName\": \"string\",\n            \"lastName\": \"string\"\n        },\n        \"age\": \"number\",\n        \"email\": \"string\",\n        \"isActive\": \"boolean\",\n        \"hobbies\": [\n            \"string\",\n            \"string\"\n        ],\n        \"address\": {\n            \"street\": \"string\",\n            \"city\": \"string\",\n            \"country\": \"string\"\n        }\n    }\n}\n```\n\n### 5. Delete a user\n\n- Endpoint: **DELETE /api/users/:userId**\n\n- Response: Success message or,  If you can't find information about the user, show a clear message. Use either `instance` or `static` method to determine if the user exist or not.  (Use the [format for error messages](#sample-error-response) that is given below.).\n\n```json\n{\n\t\"success\": true,\n\t\"message\": \"User deleted successfully!\",\n\t\"data\" : null\n}\n```\n\n## Bonus Section (10 marks):\n\n### Order Management:\n\n1. Add New Product in Order\n\nIf the 'orders' property already exists for a user, append a new product to it. Otherwise, create an 'orders' array within the user object and then add the order data.\n\n- Endpoint: **PUT /api/users/:userId/orders**\n\n- Request Body: If you can't find information about the user, show a clear message. Use either `instanceof` or `static` method to display this error message.  (Use the [format for error messages](#sample-error-response) that is given below.)\n\n```json\n{\n    \"productName\": \"string\",\n    \"price\": \"number\",\n    \"quantity\": \"number\"\n}\n```\n\n- Response: \n\n```json\n{\n    \"success\": true,\n    \"message\": \"Order created successfully!\",\n    \"data\": null\n}\n```\n\n### 2. Retrieve all orders for a specific user\n\n- Endpoint: **GET /api/users/:userId/orders**\n\n- Response: List of order objects for the specified user or, If you can't find information about the user, show a clear message. Use either `instance` or `static` method to determine if the user exist or not.  (Use the [format for error messages](#sample-error-response) that is given below.)\n\n\n```json\n{\n    \"success\": true,\n    \"message\": \"Order fetched successfully!\",\n    \"data\": {\n        \"orders\": [\n            {\n                \"productName\": \"Product 1\",\n                \"price\": 23.56,\n                \"quantity\": 2\n            },\n            {\n                \"productName\": \"Product 2\",\n                \"price\": 23.56,\n                \"quantity\": 5\n            }\n        ]\n    }\n}\n```\n\n### 3. **Calculate Total Price of Orders for a Specific User**\n\n- Endpoint: **GET /api/users/:userId/orders/total-price**\n- Response: Total price of all orders for the specified user or, If you can't find information about the user, show a clear message. Use either `instance` or `static` method to determine if the user exist or not (Use the [format for error messages](#sample-error-response) that is given below.)\n\n```json\n{\n    \"success\": true,\n    \"message\": \"Total price calculated successfully!\",\n    \"data\": {\n        \"totalPrice\": 454.32\n    }\n}\n```\n\n### Sample Error Response\n\n```json\n{\n    \"success\": false,\n    \"message\": \"User not found\",\n    \"error\": {\n        \"code\": 404,\n        \"description\": \"User not found!\"\n    }\n}\n```\n\n## Validation with Joi/Zod\n\n- Use Joi/zod to validate incoming data for user and order creation and updating operations.\n- Ensure that the data adheres to the structure defined in the models.\n- Handle validation errors gracefully and provide meaningful error messages in the API responses.\n\n## Instruction\n\n1. **Coding Quality:**\n    - Write clean, modular, and well-organized code.\n    - Follow consistent naming conventions for variables, functions, and routes.\n    - Use meaningful names that reflect the purpose of variables and functions.\n    - Ensure that the code is readable.\n2. **Comments:**\n    - Try to provide inline comments to explain complex sections of code or logic.\n3. **API Endpoint Adherence:**\n    - Strictly follow the provided API endpoint structure and naming conventions.\n    - Ensure that the request and response formats match the specifications outlined in the assignment.\n4. **Validation and Error Handling:**\n    - Implement validation using Joi/zod for both user and order data.\n    - Handle validation errors gracefully and provide meaningful error messages in the API responses.\n    - Implement error handling for scenarios like user not found, validation errors.\n5. **Coding Tools and Libraries:**\n    - Avoid the use of AI tools or libraries for generating code. Write the code manually to demonstrate a clear understanding of the concepts.\n    - Utilize only the specified libraries like Express, Mongoose, Joi and avoid unnecessary dependencies.\n6. **Coding Style:**\n    - Consider using linting tools (e.g., ESLint) to enforce coding style and identify potential issues.\n    - Ensure there are at least 10 commits in your GitHub repository.\n\n***Not following the specified API endpoint structure, naming conventions, and other instructions will result in a deduction of marks.***\n\n### **Submission:**\n\n- Share the GitHub repository link and the live deployment link as part of your submission.\n- Include a README file with clear instructions on how to run the application locally.\n\n### **Deadline:**\n\n- 60 marks: November 24, 2023, 11:59 PM\n- 50 marks: November 25, 2023, 11:59 PM\n- 30 marks: After 25, November, 11.59PM","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapollo-level2-web-dev%2Fl2-b2-assignment-2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapollo-level2-web-dev%2Fl2-b2-assignment-2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapollo-level2-web-dev%2Fl2-b2-assignment-2/lists"}