This assessment is designed to build a platform where users can act as both buyers and sellers, similar to Fiverr. The platform is based on NodeJS and Express, uses GraphQL for APIs, and MongoDB for database management.
The following technologies are used in this project:
- NodeJS: JavaScript runtime built on Chrome's V8 engine.
- Express: Minimal and flexible Node.js web application framework.
- GraphQL: A query language for your API.
- MongoDB: A document database used to store data in a NoSQL format.
The project contains the following pre-built models:
- User: Represents a user of the platform who can act as both a buyer and seller.
- Listings: Represents services/products that a seller offers.
- Bookings (Orders): Represents bookings or purchases made by buyers on listings.
- Ratings: Represents ratings given by buyers to orders/listings.
Each module consists of the following files:
- Graph File (
.graphql.ts): Contains all GraphQL type definitions for the module. - Schema File (
.schema.ts): Defines the MongoDB schema and maps it to the corresponding collection. - Resolver File (
.resolver.ts): Contains the GraphQL resolvers for queries and mutations. - Service File (
.service.ts): Implements business logic and handles interactions between the resolver and database.
You are tasked to create a JWT Service class using the Singleton pattern. This class will be used in the Auth module. The JWT service must:
- Be implemented as a Singleton.
- Encapsulate the signing secret (
SECRET_KEY) from the.envfile. - Provide methods for signing JWT tokens.
You will implement the authentication logic for the platform. The requirements are:
- Users can sign up and receive a JWT valid for buyer operations by default.
- Users can log in and receive a JWT valid for buyer operations.
- Users can switch roles (from buyer to seller and vice versa) using the
switchRolemutation. This mutation will:- Accept the current JWT and return a new one valid for the opposite role (buyer ↔ seller).
Implement the User Module with the following queries and mutations:
- getUser: Returns the user’s profile data.
- updateUser: Allows the user to update their profile.
- deleteUser: Allows the user to delete their profile.
Ensure that you define the necessary MongoDB schema and GraphQL types for the User model.
You will complete the Listings Module. The requirements are:
- A user with a valid seller JWT can:
- Create a listing.
- Update their own listings.
- Delete their own listings.
- Mark an order as completed (On their own listings only)
You will implement the Bookings/Orders Module. The requirements are:
- A user with a valid buyer JWT can:
- Book an order on a listing that is not their own.
- Note that orders cannot be updated once created.
- Rate the order/seller once the booking status is set to
completed.
Implement the following queries for the Fiverr Admin:
- Fetch the top 5 most-rated sellers.
- Fetch the top 5 most-rated listings.
- Fetch the top 5 buyers with the most orders.
You are required to complete each task in a separate branch and create a pull request (PR) for each task. Follow the steps below for each task:
- Fork this repository into your own GitHub account before beginning the tasks. You are not allowed to push to this repository.
- For Task 1, create a branch named
task1frommainand create a PR to merge it back intomain. - For Task 2, create a branch named
task2fromtask1and create a PR to merge it intotask1. - For Task 3, create a branch named
task3fromtask2and create a PR to merge it intotask2, and so on.
You will explain your solutions as needed in each PR. Please send us your repo link when you are ready to submit.
- Clone the repository:
git clone https://github.com/Staunchglobal/mern-sse-assignment.git cd mern-sse-assignment - Install dependencies:
npm install
- Create a
.envfile and add the required variables such asSECRET_KEYandMONGODB_URLconnection string. - Start the server:
npm start
For any questions or clarifications, feel free to reach out.