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
14 changes: 9 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js",
"test": "echo \"Error: no test specified\" && exit 1"
"db:generate": "prisma generate",
"db:push": "prisma db push",
"db: migrate": "prisma migrate dev",
"db:studio": "prisma studio"

},
"keywords": [
"nodejs",
Expand All @@ -19,13 +23,13 @@
"author": "Duraan",
"license": "MIT",
"dependencies": {
"express": "^4.18.2",
"cors": "^2.8.5",
"@prisma/client": "^5.7.1",
"body-parser": "^1.20.2",
"@prisma/client": "^5.7.1"
"cors": "^2.8.5",
"express": "^4.18.2"
},
"devDependencies": {
"nodemon": "^3.0.1",
"prisma": "^5.7.1"
"prisma": "^5.22.0"
}
}
19 changes: 18 additions & 1 deletion prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,31 @@ model Task {

model Subtask {

id Int @id @default(autoincrement())
title String
description String
completed Boolean @default(false)
task Task @relation(fields: [taskId], references: [id],onDelete:Cascade)
taskId String // Foreign key to Task
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}



// TODO: Create an enum for the status of the task with the following values (pending, in_progress, completed, cancelled)
enum TaskStatus {

pending
in_progress
completed
cancelled
}

// Create an enum for the priority of the task with the following values (low, medium, high, urgent)
enum Priority {
low
medium
high
urgent

}
43 changes: 34 additions & 9 deletions services/taskServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@ export async function getAllTasks() {
});
}



// Get task by ID
export async function getTaskById(id) {
try {

// TODO: Check if task exists

// TODO: If not, throw an error

// TODO: If it does, return the task

// TODO: Check if task exists
const student = await prisma.student.findUnique({
where:{id} ,
})
// TODO: If not, throw an error

if (!student){
throw new Error('student not found')
}
// TODO: If it does, return the task
return student;

} catch (error) {
throw new Error(`Error retrieving task: ${error.message}`);
Expand All @@ -32,8 +38,27 @@ export async function createTask(taskData) {
taskData.status === "in-progress" ? "in_progress" : taskData.status;


// TODO: Create the new task where all the task data is in "taskData", also create the subtasks with the data in "taskData.subtasks". Return the created task and it's subtasks using the include option.

// TODO: Create the new task where all the task data is in "taskData", also create the subtasks with the data
// in "taskData.subtasks". Return the created task and it's subtasks using the include option.
const createdTask = await prisma.task.create({
data: {
...taskData,
status: status,

subtasks: {
createMany: {
data: taskData.subtasks.map(subtask => ({
...subtask,

completed: subtask.completed ?? false
}))
}
}
},
include: {
subtasks: true
}
})

} catch (error) {
throw new Error(`Error creating task: ${error.message}`);
Expand Down