Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# flyctl launch added from .gitignore
# compiled output
dist
node_modules
build

# Logs
**/logs
**/*.log
**/npm-debug.log*
**/pnpm-debug.log*
**/yarn-debug.log*
**/yarn-error.log*
**/lerna-debug.log*

# OS
**/.DS_Store

# Tests
coverage
.nyc_output

# IDEs and editors
.idea
**/.project
**/.classpath
**/.c9
**/*.launch
**/.settings
**/*.sublime-workspace

# IDE - VSCode
**/.vscode/*
!**/.vscode/settings.json
!**/.vscode/tasks.json
!**/.vscode/launch.json
!**/.vscode/extensions.json

# dotenv environment variable files
**/.env
**/.env.development.local
**/.env.test.local
**/.env.production.local
**/.env.local

# temp directory
**/.temp
**/.tmp

# Runtime data
**/pids
**/*.pid
**/*.seed
**/*.pid.lock

# Diagnostic reports (https://nodejs.org/api/report.html)
**/report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
fly.toml
18 changes: 18 additions & 0 deletions .github/workflows/fly-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# See https://fly.io/docs/app-guides/continuous-deployment-with-github-actions/

name: Fly Deploy
on:
push:
branches:
- main
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
concurrency: deploy-group # optional: ensure only one action runs at a time
steps:
- uses: actions/checkout@v4
- uses: superfly/flyctl-actions/setup-flyctl@master
- run: flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
15 changes: 15 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from node:20

WORKDIR /app

COPY package.json ./

RUN npm i

COPY . .

RUN npm run build

EXPOSE 3000

CMD ["npm", "run", "start:prod"]
249 changes: 249 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,252 @@ The application will run on `http://localhost:3000`.
### Time Estimate:

The exercise should take approximately **20 minutes** to complete.


# Senior Backend Coding Exercise Sample Payloads

### Users
```bash

Signup User

API: https://senior-backend-coding-exercise.fly.dev/users/signup
Method: POST

Payload: {
"name": "steve",
"email": "abc@test.com",
"password": "encrypted"
}

Response: {
"success": true,
"message": "User created successfully",
"data": {
"id": "5dew2s8um",
"name": "abc@test.com",
"email": "steve",
"password": "encrypted"
}
}

Fetch User Details

API: https://senior-backend-coding-exercise.fly.dev/users/single-user/5dew2s8um
Method: GET

Response:
{
"success": true,
"message": "User details fetched successfully",
"data":
{
"id": "5dew2s8um",
"name": "abc@test.com",
"email": "steve",
"password": "encrypted"
}
}

Fetch All Users

API: https://senior-backend-coding-exercise.fly.dev/users/all-users
Method: GET

Response:
{
"success": true,
"message": "Users fetched successfully",
"data": [
{
"id": "5dew2s8um",
"name": "abc@test.com",
"email": "steve",
"password": "encrypted"
}
]
}

Update profile

API: https://senior-backend-coding-exercise.fly.dev/users/update-profile
Method: POST
Payload:
{
"userId":"fqeuzrhee",
"name": "tony",
"email": "tony@stark.in",
"password": "double_enc"
}

Response:
{
"success": true,
"message": "User updated successfully"
}


Delete User

API: https://senior-backend-coding-exercise.fly.dev/users/delete-user
Method: POST
Payload:
{
"userId": "hsgqx70tp"
}

Response:
{
"success": true,
"message": "User deleted successfully"
}
```

### Products
```bash
Add new Products
API: https://senior-backend-coding-exercise.fly.dev/products/create-product
Method: POST
Payload:
{
"name": "mobiles",
"description": "a simple mobile device"
}

Response:
{
"success": true,
"message": "Product created successfully",
"data": {
"id": "epefon9gr",
"name": "mobiles",
"description": "a simple mobile device"
}
}


Fetch Product Details
API: https://senior-backend-coding-exercise.fly.dev/products/single-product/epefon9gr
Method: GET

Response:
{
"success": true,
"message": "Product details fetched successfully",
"data": {
"id": "epefon9gr",
"name": "mobiles",
"description": "a simple mobile device"
}
}


Fetch All Products
API: https://senior-backend-coding-exercise.fly.dev/products/all-products
Method: GET

Response:
{
"success": true,
"message": "Products fetched successfully",
"data": [
{
"id": "epefon9gr",
"name": "mobiles",
"description": "a simple mobile device"
}
]
}


Update Product
API: https://senior-backend-coding-exercise.fly.dev/products/update-product
Method: POST
Payload:
{
"productId":"epefon9gr",
"name": "Nothing Phone (1)",
"description": "A brand new nothing phone (1)(R)"
}

Response:
{
"success": true,
"message": "Product updated successfully"
}

Delete Product
API: https://senior-backend-coding-exercise.fly.dev/products/delete-product
Method: POST
Payload:
{
"productId": "epefon9gr"
}

Response:
{
"success": true,
"message": "Product deleted successfully"
}

```

### Orders
```bash
Add Orders
API: https://senior-backend-coding-exercise.fly.dev/order/add
Method: POST
Payload:
{
"productId":"xh945mdtb",
"userId":"gvs9athpt",
"quantity": 2
}

Response:
{
"success": true,
"message": "Order created successfully",
"data": {
"id": "842cm5c2x",
"productId": "xh945mdtb",
"quantity": 2,
"userId": "gvs9athpt"
}
}


Fetch Product Details
API: https://senior-backend-coding-exercise.fly.dev/order/842cm5c2x
Method: GET
Response:
{
"success": true,
"message": "Order details fetched successfully",
"data": {
"id": "842cm5c2x",
"productId": "xh945mdtb",
"quantity": 2,
"userId": "gvs9athpt"
}
}


Fetch All Orders
API: https://senior-backend-coding-exercise.fly.dev/order/all
Method: GET
Response:
{
"success": true,
"message": "Orders fetched successfully",
"data": [
{
"id": "842cm5c2x",
"productId": "xh945mdtb",
"quantity": 2,
"userId": "gvs9athpt"
}
]
}

```
22 changes: 22 additions & 0 deletions fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# fly.toml app configuration file generated for senior-backend-coding-exercise on 2025-01-25T11:26:33+05:30
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'senior-backend-coding-exercise'
primary_region = 'mia'

[build]

[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = 'stop'
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[[vm]]
memory = '2gb'
cpu_kind = 'shared'
cpus = 1
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
"@nestjs/common": "^10.0.0",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"cors": "^2.8.5",
"reflect-metadata": "^0.2.0",
"rxjs": "^7.8.1"
},
Expand Down
9 changes: 9 additions & 0 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Controller, Get } from '@nestjs/common';

@Controller()
export class AppController {
@Get('')
checkServer() {
return 'Server is up and running';
}
}
Loading