- You have learned the basics of Node.js and Express.js, now let's test your knowledge of how to setup API endpoints with this Task Management project using Prisma ORM and Supabase database.
- Fork and Clone this project repository in your terminal
- CD into the project base directory
cd Week19_Task_Management_NodeJS_Prisma - Install dependencies:
npm install
- Create a
.envfile in the root directory with your Supabase database URL - Complete the Prisma schema and service functions (see tasks below)
- Generate Prisma client and push schema to database:
npx prisma generate npx prisma db push
- Start the server:
npm run dev
- The server will run on
http://localhost:3000
The project currently has a basic task management API with the following structure:
Main Task Operations:
GET /api/tasks- Get all tasks (Already implemented)GET /api/tasks/:id- Get task by ID (Already implemented)POST /api/tasks- Create new task (Already implemented)PUT /api/tasks/:id- Update entire task (Already implemented)DELETE /api/tasks/:id- Delete specific task (Already implemented)
Note: The routes are already implemented. You need to complete the underlying service functions and Prisma schema.
Each task has the following structure:
{
"id": "cmdsdprqh0000gtd47ipm0qrx",
"title": "Task Title",
"description": "Task description",
"status": "pending|in-progress|completed|cancelled",
"priority": "low|medium|high|urgent",
"dueDate": "2024-01-15",
"assignedTo": "John Doe",
"subtasks": [
{
"id": "cmdsdq3z50002gtd4okxc927x",
"title": "Subtask Title",
"description": "Subtask description",
"completed": false
}
],
"createdAt": "2024-01-01T10:00:00.000Z",
"updatedAt": "2024-01-01T10:00:00.000Z"
}You need to complete the following:
Location: prisma/schema.prisma
The schema file is partially completed with TODO comments. You need to complete the following models and enums:
Subtask Model:
model Subtask {
id String @id @default(cuid())
title String
description String
completed Boolean @default(false)
taskId String
task Task @relation(fields: [taskId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("subtasks")
}TaskStatus Enum:
enum TaskStatus {
pending
in_progress
completed
cancelled
}Priority Enum:
enum Priority {
low
medium
high
urgent
}Location: .env
- Add your Supabase database URL
- Set the application port and environment
Location: services/taskServices.js - getTaskById function
The function has TODO comments that need to be implemented:
- Check if task exists using Prisma
- If not found, throw an error
- If found, return the task with subtasks included
Location: services/taskServices.js - createTask function
The function has TODO comments that need to be implemented:
- Create the new task using Prisma with all task data from taskData
- Create subtasks if provided in taskData.subtasks
- Return the created task with subtasks included using the include option
You can use Postman or curl to test your endpoints.
Objective: Add filtering capabilities to the GET /api/tasks endpoint.
Requirements:
- Update the getAllTasks function in
services/taskServices.jsto accept filters - Add query parameter support for filtering by status, priority, or assignedTo
- Implement search functionality for task titles
- Add pagination for large datasets
Objective: Add category support to tasks.
Requirements:
- Create a Category model in the Prisma schema
- Add category relationship to tasks
- Update the Task model to include categoryId
- Implement category-based filtering
By completing this project, you will demonstrate understanding of:
- Prisma ORM Setup - Database schema design and Prisma client configuration
- Supabase Integration - Cloud database setup and connection
- RESTful API Design - Proper endpoint naming and HTTP methods
- Data Validation - Input validation and sanitization using Prisma
- Error Handling - HTTP status codes and error responses
- Express.js Routing - Route parameters and query strings
- Async/Await - Handling asynchronous database operations
- Service Layer Architecture - Separating business logic from routes
- Complete the Prisma schema with all required models and relationships (Subtask model, TaskStatus enum, Priority enum)
- Configure environment variables with Supabase credentials
- Complete getTaskById function with proper error handling and task existence checks
- Complete createTask function with validation and subtask support
- Test all endpoints using curl or Postman
- Optional: Implement stretch goals with filtering and categories
- Check the existing code - Study the implemented functions for patterns
- Read Prisma documentation - Understand the Prisma client methods
- Check Supabase dashboard - Verify your database connection
- Test frequently - Test each function as you build it
- Ask questions - Don't hesitate to ask for clarification
Good luck with your implementation! 🚀