jidan_starter v1.0.2
šÆ Project Setup Guide
š 1. Database Preparation
Before running the project, ensure that the MySQL database is properly configured.
š¹ Check the migration file in migration/../migration.sql
and adjust it if necessary.
š¹ Configure .env
with MySQL connection details matching your server environment.
š 2. Install Dependencies
Run the following command to install all required dependencies:
npm install
āļø 3. Generate Prisma Client
After installing dependencies, run the following command to generate the Prisma Client:
npx prisma generate
š ļø 4. Synchronize Database with Prisma
To ensure the database schema matches Prisma, execute the following commands:
npx prisma db push
npx prisma db pull
š db push
applies the Prisma schema to the database.
š db pull
retrieves the schema from the database if any changes were made.
š 5. Check Database Connection
Use the following command to verify the database connection:
npx ts-node src/config/dbCheck.ts
š If the connection is successful, proceed to the next step.
š 6. Run the Project
Once all configurations are complete, start the server with:
npm run dev
š If successful, the server will be available at http://localhost:3000
.
š API Endpoints
š¤ User Management
š Create a new user:
POST http://localhost:3000/api/users
Request Body:
{ "username": "jojo", "email": "john@example.com", "password": "1234578A@" }
š User login:
POST http://localhost:3000/api/users/login
Request Body:
{ "email": "john@example.com", "password": "1234578A@" }
Response:
{ "message": "Login successful", "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJlbWFpbCI6ImpvaG5AZXhhbXBsZS5jb20iLCJ1c2VybmFtZSI6Impvam8iLCJpYXQiOjE3NDExMzUyMzEsImV4cCI6MTc0MTIyMTYzMX0.JjIYECNDcr1hS5TH1eRJwTFwR8ZbzRfeYMyQtWxy0KE", "user": { "user_id": 1, "username": "jojo", "email": "john@example.com" } }
š Retrieve all users (requires authentication):
GET http://localhost:3000/api/users/
Authorization: Bearer Token
š¤ Retrieve a user by ID (requires authentication):
GET http://localhost:3000/api/users/10
Authorization: Bearer Token
āļø Update a user by ID (requires authentication):
PUT http://localhost:3000/api/users/10
Authorization: Bearer Token
š¢ļø Soft delete a user (set
is_deleted
column totrue
, requires authentication):DELETE http://localhost:3000/api/users/soft/6
Authorization: Bearer Token
ā Delete a user permanently (requires authentication):
DELETE http://localhost:3000/api/users/6
Authorization: Bearer Token
š API Usage Instructions
- š Create an account first using the
POST /api/users
endpoint. - š Login using the
POST /api/users/login
endpoint to obtain a Bearer Token. - ā” Use the Bearer Token to access the following endpoints:
- GET (Retrieve all users or a specific user by ID)
- PUT (Update user information)
- DELETE (Soft delete a user)
- DELETE (Permanently delete a user)
š How to Use Bearer Token in Authorization
When making API requests that require authentication, include the Bearer Token in the request header:
Authorization: Bearer YOUR_TOKEN_HERE
Example using cURL:
curl -X GET "http://localhost:3000/api/users" -H "Authorization: Bearer YOUR_TOKEN_HERE"
ā ļø Notes
š Ensure MySQL is running before starting the project. š If there are schema changes, always run:
npx prisma generate
npx prisma db push
š Security Reminder: Do not expose your .env
file in public repositories.
š Happy Coding & Enjoy! š