Swyt Coding Challenge Software Engineer application by Mudassar Ali
A simple API to manage products and their categories built with Express.js, TypeScript, PostgreSQL, and Prisma ORM.
- Backend: Express.js with TypeScript
- Database: PostgreSQL with Prisma ORM
- Security: CORS, Helmet
- Logger: Morgan
- Utilities: body-parser, dotenv
- Node.js (v21.6.2)
- npm (10.7.0)
- PostgreSQL (16.2)
-
Clone the Repository
git clone git@github.com:sahilbabu/swyt-technical-exercise.git cd backend
-
Install Dependencies
npm install
-
Configure Environment Variables
Create a
.env
file in the root directory:DATABASE_URL="postgresql://<username>:<password>@localhost:5432/<database>?schema=public" PORT=3000 API_URL="http://localhost:3000/api/v1/products" #for CLI version NODE_ENV=development
-
Set Up the Database
npx prisma migrate dev --name init
npm run dev
-
Run Unit Tests
npm run test
-
Categories API
1- Create Category Endpoint: POST /api/v1/categories Request Body:{ "name": "Category Name", "parentCategoryId": 1 // optional }
2- List Categories Endpoint: GET /api/v1/categories
-
Product API
1- Create Product Endpoint: POST /api/v1/products Request Body:{ "name": "Product Name", "description": "Product Description", "price": 10.99, "image": "http://example.com/image.jpg", // URL or file upload "categoryId": 1 }
2- List Product Endpoint: GET /api/v1/products Query Parameters: sortBy: Field to sort by (e.g., price). order: Sorting order (asc or desc). category: Filter by category ID. page: Page number for pagination. limit: Number of items per page.
-
Run the following command
npm run create-product
Before you begin, ensure you have the following installed on your machine:
cd vue3-app
npm install
npm run dev
-
Building for Production
npm run build
-
Run Cypress
npm run test:open
-
Run all tests in headless mode
npm run test