TypeScript and Advanced JavaScript
Overview
In this assessment, you will apply the skills you’ve developed throughout the TypeScript and Advanced JavaScript module to build a functional, real-world application. This project will test your understanding of TypeScript features, object-oriented programming (OOP) principles, asynchronous operations, error handling, and API interaction. You will have 5.5 hours to complete this assessment.
You will create an E-commerce Product Management System using TypeScript. The final deliverable will include a GitHub repository with your project and a written reflection on your approach and the challenges you faced.
Time Allotment
- Time: 5.5 hours
Instructions
Part 1: Project Setup
-
Set Up Your Project:
-
Create a new directory for the project and initialize it with npm:
mkdir e-commerce-system cd e-commerce-system npm init -y
-
Install TypeScript and other necessary dependencies:
npm install typescript @types/node --save-dev
-
Create a
tsconfig.json
file to configure TypeScript:npx tsc --init
-
-
Organize Your Folder Structure:
- Your project should have the following structure:
e-commerce-system/ ├── src/ │ ├── models/ │ │ ├── Product.ts │ ├── services/ │ │ └── apiService.ts │ ├── utils/ │ │ ├── discountCalculator.ts │ │ ├── errorHandler.ts │ │ └── taxCalculator.ts │ └── main.ts └── tsconfig.json
- Your project should have the following structure:
Part 2: API Research
- API Research:
- Research and analyze the Dummy JSON Products API .
- You will be implementing features that interact with this API.
- Project Planning:
- Based on your API research, plan the structure of your project. You will need to create API requests, handle errors, and display product information.
- Before you begin coding, create a project plan and outline the steps you’ll take to implement the API interactions and display product data.
- Ensure you have thoroughly read through the requirements for the project below before you begin planning it.
Part 3: Implementation
-
Develop Product Class:
- Product Base Class (
Product.ts
):- Define a
Product
class that includes the appropriate properties based on data provided in the API response. - Include methods
displayDetails()
andgetPriceWithDiscount()
, and implement them appropriately based on the provided data.
- Define a
- Product Base Class (
-
Implement Utilities:
- Discount Calculator Module (
discountCalculator.ts
):- Create a
calculateDiscount()
function to handle discount calculations for products. - This function should return the dollar amount that a product is discounted by. For example, if a product costs $100 and has a 10% discount, the function should return $10.
- Create a
- Tax Calculator Module (
taxCalculator.ts
):- Create a
calculateTax()
function to handle tax calculations for products. - This function should return the dollar amount that a product is taxed at. For example, if a product costs 10.
- Note that the
product
data returned from the API does not include ataxPercentage
field like it includes adiscountPercentage
field. Apply a default standard tax rate of 4.75% to each product; however, products with acategory
of “groceries” should only be taxed at 3%.
- Create a
- Discount Calculator Module (
-
Handle Asynchronous Operations:
- API Service (
apiService.ts
):- Create API requests using
async/await
and Promises. - Implement functions to fetch product data and handle errors using
try/catch
.
- Create API requests using
- API Service (
-
Error Handling Utility:
- Error Handler Module (
errorHandler.ts
):- Implement a custom error class and functions to handle different types of errors gracefully.
- Error Handler Module (
-
Create the Main Application:
- Main Entry File (
index.ts
):- Import the product classes, tax calculator, and API service.
- Create instances of
Product
by fetching product data from the API. - Use asynchronous functions to fetch product data and display it.
- Demonstrate error handling and OOP principles in action.
- Main Entry File (
Part 4: Testing and Finalizing
-
Compile Your Code:
- Use TypeScript to compile your code:
npx tsc
- Use TypeScript to compile your code:
-
Run Your Application:
- Use Node.js to run your compiled JavaScript code:
node dist/index.js
- Use Node.js to run your compiled JavaScript code:
-
Test and Debug:
- Test all functionalities to ensure they work as expected.
- Check for any TypeScript errors or runtime issues and resolve them.
Part 5: (Optional) User Interface
Ensure the project is fully functional before creating a user interface. With any additional time, you can implement a user interface for the application. Creating an interface will allow you to demonstrate your project in a more visually appealing way, as well as include it within your portfolio.
-
Create User Interface:
- Create a basic user interface using HTML.
-
Implement User Interaction:
- Add event listeners to handle user input and interactions.
- Update the UI based on user actions and API responses.
-
Style the UI:
- Use CSS to style the user interface.
Deliverables
You must submit the following items via Canvas:
-
GitHub Repository:
- Link to your GitHub repository with the complete project code.
- Ensure your repository is publicly accessible or that the appropriate permissions are granted for review.
-
Reflection Document:
- Write a reflection of roughly 300 words addressing:
- How you implemented TypeScript features and OOP principles.
- The challenges you encountered and how you overcame them.
- How you handled asynchronous operations and error management.
- Write a reflection of roughly 300 words addressing:
Rubric for Evaluation
Criteria | Excellent (5 points) | Good (4 points) | Satisfactory (3 points) | Needs Improvement (1-2 points) | Points |
---|---|---|---|---|---|
TypeScript Implementation | Comprehensive use of TypeScript features with no errors; code is type-safe and uses advanced features effectively. | Adequate use of TypeScript features with minor issues; most code is type-safe. | Basic use of TypeScript; several type-related warnings or errors present. | Minimal or incorrect use of TypeScript; code contains significant type-related errors. | __ / 5 |
Object-Oriented Design | Correct and efficient implementation of OOP principles; classes are modular and promote code reusability. | Most OOP principles implemented correctly; minor issues with structure or modularity. | Basic implementation of OOP; structure may be confusing or inefficient. | Incorrect or missing OOP principles; classes are poorly structured or incomplete. | __ / 5 |
Asynchronous Operations | Effective use of async/await and Promises; operations are non-blocking and efficient. | Use of async/await is mostly correct; minor inefficiencies or blocking issues. | Basic use of asynchronous operations; code may have blocking or inefficient behavior. | Incorrect use of asynchronous operations; code is blocking or inefficient. | __ / 5 |
Error Handling | Comprehensive error handling; custom error classes implemented and errors managed gracefully. | Adequate error handling; minor issues with implementation or coverage. | Basic error handling present; limited use of custom error classes or robust handling. | Minimal or no error handling; application crashes or behaves unpredictably. | __ / 5 |
Code Quality and Documentation | Code is clean, well-organized, and follows best practices; comprehensive comments and documentation provided. | Code is organized with minor issues; adequate comments and documentation. | Code is difficult to follow; minimal comments or documentation. | Code is disorganized and lacks documentation; difficult to understand or maintain. | __ / 5 |
Submission Guidelines
- GitHub Repository: Submit the link to your repository on Canvas.
- Reflection Document: Upload your written reflection as a separate file or include it in your repository as a Markdown file.
Ensure that your submission is complete and follows all instructions.