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
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ coverage/
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)
Expand All @@ -28,6 +29,7 @@ bower_components
# node-waf configuration
.lock-wscript


# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

Expand Down Expand Up @@ -69,6 +71,11 @@ typings/
.env.test.local
.env.production.local

12




# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
"scripts": {
"start": "node server.js",
"dev": "nodemon server.js",
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"db:generate" : "prisma generate",
"db-push": "prisma db-push",
"db-studio": "prisma studio"
},
"keywords": [
"nodejs",
Expand Down
37 changes: 21 additions & 16 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}
Expand All @@ -11,32 +8,40 @@ datasource db {
}

model Task {
id String @id @default(cuid())
id String @id @default(cuid())
title String
description String
status TaskStatus
priority Priority
status TaskStatus @default(pending)
priority Priority @default(low)
dueDate DateTime?
assignedTo String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
subtasks Subtask[]

@@map("tasks")
}

// TODO: Create a Subtask model that has a (title, description, completed, taskId, task, createdAt, updatedAt) where taskId is a foreign key to the Task model and task is a relation to the Task model

model Subtask {

id String @id @default(cuid())
taskId String
title String
completed Boolean @default(false)
description String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
task Task @relation(fields: [taskId], references: [id])
}

// 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
}
1 change: 1 addition & 0 deletions routes/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,4 @@ router.delete("/tasks/:id", async (req, res) => {
});

export default router;

49 changes: 47 additions & 2 deletions services/taskServices.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Priority } from "@prisma/client";
import prisma from "../lib/prisma.js";

// Simpler approach - just get all tasks
Expand All @@ -10,13 +11,26 @@ export async function getAllTasks() {

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


try {
const task = await prisma.task.findUnique({
where: {id},
include: {subtasks: true}
})
// TODO: Check if task exists

if (!task && !id) {

// TODO: If not, throw an error

throw new Error `task with ${id} is not found`

}

// TODO: If it does, return the task

return task


} catch (error) {
Expand All @@ -32,7 +46,38 @@ 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 CreateTask = await prisma.task.create({
data: {
title: taskData.title,
description: taskData.description,
status,
priority: taskData.priority,
dueDate: taskData.dueDate,
assignedTo: taskData.assignedTo,

subtasks: {
create: taskData.subtasks.map((subtask) => ({
title: subtask.title,
description: subtask.description,
completed: subtask.completed || false,
})) || [],
}
},

include: {
subtasks: true,
},



})

return CreateTask;



} catch (error) {
Expand Down