You can access the deployed version of the app at https://loan-app-black.vercel.app/.
To access the admin panel, use the following credentials:
- Email:
admin@gmail.com
- Password:
1234
This project consists of a frontend and a backend. The frontend is built using React and Vite, while the backend is built using Node.js and Express.
Make sure you have the following installed on your machine:
- Node.js (version 14 or higher)
- npm (Node package manager)
-
Navigate to the server directory:
cd server
-
Install the dependencies:
npm install
-
Start the server using Nodemon:
npm run server
This will start the server and watch for changes in the
index.js
file.
-
Navigate to the frontend directory:
cd frontend
-
Install the dependencies:
npm install
-
Start the development server:
npm run dev
This will start the Vite development server, and you can access the frontend at
http://localhost:3000
(or the port specified in your Vite configuration).
- Endpoint:
POST /api/auth/register
- Request Body:
{ "name": "string", "email": "string", "password": "string" }
- Response:
- 201 Created: User registered successfully.
- 400 Bad Request: User already exists.
- 500 Internal Server Error: Error message.
- Endpoint:
POST /api/auth/login
- Request Body:
{ "email": "string", "password": "string" }
- Response:
- 200 OK: Returns user details and JWT token.
- 401 Unauthorized: Invalid email or password.
- 500 Internal Server Error: Error message.
- Endpoint:
POST /api/loans
- Request Body:
{ "amount": "number", "term": "number" }
- Response:
- 201 Created: Returns the created loan object.
- 500 Internal Server Error: Error message.
- Endpoint:
GET /api/loans
- Response:
- 200 OK: Returns an array of loans for the authenticated user or all loans if the user is an admin.
- 500 Internal Server Error: Error message.
- Endpoint:
PATCH /api/loans/:id/status
- Request Body:
{ "status": "string" // 'PENDING', 'APPROVED', or 'PAID' }
- Response:
- 200 OK: Returns the updated loan object.
- 404 Not Found: Loan not found.
- 401 Unauthorized: Not authorized.
- 500 Internal Server Error: Error message.
- Endpoint:
POST /api/loans/:id/repayment
- Response:
- 200 OK: Returns the updated loan object.
- 404 Not Found: Loan not found.
- 401 Unauthorized: Not authorized.
- 400 Bad Request: All repayments are already paid.
- 500 Internal Server Error: Error message.
const userSchema = new mongoose.Schema({
name: String,
email: { type: String, unique: true },
password: String,
role: { type: String, enum: ['customer', 'admin'], default: 'customer' }
});
- Fields:
name
: User's name (required).email
: User's email (required, unique).password
: User's password (required).role
: User's role (default is 'customer').
const loanSchema = new mongoose.Schema({
userId: { type: mongoose.Schema.Types.ObjectId, ref: 'User', required: true },
amount: Number,
term: Number,
status: { type: String, enum: ['PENDING', 'APPROVED', 'PAID'], default: 'PENDING' },
repayments: [{
amount: Number,
dueDate: Date,
status: { type: String, enum: ['PENDING', 'PAID'], default: 'PENDING' }
}]
});
- Fields:
userId
: Reference to the User model (required).amount
: Total loan amount (required).term
: Loan term in weeks (required).status
: Current status of the loan (default is 'PENDING').repayments
: Array of repayment objects containing amount, due date, and status.
This project is licensed under the ISC License.