We're building an E-Commerce Backend backend services. Follow the instructions below to get started with your project and then carry out the tasks asked for further down.
- Clone this repository:
git clone <repository-url>
-
cd to cloned repository
-
install packages by running
npm install
To provide you with a simple way to test your API endpoints locally, you can use the following extension:
REST Client for Visual Studio Code
We have provided a basic file that have the API definitions of the provided endpoints. To use it do the following:
- Open the
requests.http
file in the root of the app. - Click the Send request link next to each request to invoke a request to that specific endpoint.
- View the result in the sidepanel.
You can use this simple API client to test your own endpoints, or use an alternative software (such as Postman) if you prefer.
To run the backend application execute:
npm run start
Application is served on http://localhost:3000 and is a nestjs application connected to sqlite database and contain these basic APIs:
- POST request to add order/user/product
- DELETE request to remove order/user/product
- GET request to get all orders/products
Request examples could be found in file requests.http
While this API gives us the basic abilities to create, fetch, and delete items, it's far from sufficient for our app.
We want you to carry out the following tasks:
- go to file
src/app/app.module.ts
and uncomment code on lines 8, 12, 19, 25 - try to fix bugs appeared in app (note: there is 3 errors, appeared next after fixing previous)
- on
POST http://localhost:3000/orders/add
instead of passinguserId
as a body parameter fetch user fromUserService
readuserId
and add to order
- on
POST http://localhost:3000/orders/add
fetch products fromProduct
repository, and instead of passingtotalAmount
as body paramter calculate product prices and sum them up
4. Implement functionality to fetch orders only placed by current user filtered by userId
added automatically
- on
GET http://localhost:3000/orders
fetchuserId
fromUserService
and filter orders by user
- To provide you with a simple way to view the database, you can use the following extension: SQLite Viwer
- Execute
node index.js
to run the suboptimal query against the SQLite database. - Optimize the provided SQL query in the
index.js
file and explain your solution.
Your task is to optimize the SQL query provided in index.js
to improve performance then run node index.js
to see the result.
- Consider techniques like indexing, query refactoring, or aggregation (Apply database change via
index.js
or directly in the database) - Provide a brief explanation of the optimizations you applied.
Hint: Use command sqlite3 ecommerce.db
to open and connect to the ecommerce.db
database.
- Effectiveness of the optimizations.
- Clarity in explaining the rationale behind the chosen methods.
- Understanding of SQL and database performance considerations.
Best of luck!