- This is a pet project to verify some knowledge, practice expressJS, with Prisma as ORM to make migrations, joi for validations, versioning for controllers, swagger as a doumentation and cors for validation
To setup the project
- Clone the repo
- Create at root the
.envfile
Example content:
DATABASE_URL="postgresql://YOUR_USERNAME:YOUR_PASSWORD@localhost:YOUR_PORT/YOUR_DATABASE?schema=public"
PORT=YOUR_APPLICATION_PORT
NODE_ENV=development
FRONTEND_URL=http://localhost:3001
JWT_SECRET=123456789012345678901234567890
JWT_EXPIRES_IN=30d
- Install the dependencies
Command: yarn install or yarn
- Then you can init prisma config & execute yout migrations from prisma to postgreSQL
Command: yarn prisma init
Command: yarn prisma migrate dev or npx prisma migrate deploy
4.0.1 Run the command to generated the prisma client
Command: npx prisma generate
4.1 If you want the Prisma Studio
Command: yarn prisma studio
- If always run success, then you can run run API
Command: yarn run dev
Table Task
Fields
- id String @id @default(uuid())
- title String
- description String?
- status String @default("pending")
- createdAt DateTime @default(now())
- updatedAt DateTime @updatedAt
Create Task
curl -X POST http://localhost:3000/api/tasks \
-H "Content-Type: application/json" \
-d '{"title": "My first task", "description": "This is a test task", "status": "pending"}'
Get Tasks
curl http://localhost:3000/api/tasks
Get Tasks with filtering
curl "http://localhost:3000/api/tasks?page=1&limit=5&status=pending"
Get Task by id
curl http://localhost:3000/api/tasks/{task-id}
Edit Task by id
curl -X PUT http://localhost:3000/api/tasks/{task-id} \
-H "Content-Type: application/json" \
-d '{"title": "Updated task", "status": "completed"}'
Delete Task by id
curl -X DELETE http://localhost:3000/api/tasks/{task-id}