Skip to content

Commit

Permalink
feat: getTaskByID now works
Browse files Browse the repository at this point in the history
  • Loading branch information
jeessh committed Nov 4, 2023
1 parent 60e5821 commit 42e888f
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 29 deletions.
9 changes: 9 additions & 0 deletions backend/typescript/graphql/resolvers/taskResolvers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import TaskService from "../../services/implementations/taskService";
import UserService from "../../services/implementations/userService";
import IUserService from "../../services/interfaces/userService";
import type {
TaskDTO,
ITaskService,
} from '../../services/interfaces/taskService'

const task
12 changes: 6 additions & 6 deletions backend/typescript/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ model user {

model task {
id Int @id @default(autoincrement())
category category @relation(fields: [category_id], references: [id])
category_id Int
category category? @relation(fields: [category_id], references: [id])
category_id Int @unique
title String
status Statuses
description String
assignee resident @relation(fields: [assignee_id], references: [id])
assignee_id Int
assigner staff @relation(fields: [assigner_id], references: [id])
assigner_id Int
assignee resident? @relation(fields: [assignee_id], references: [id])
assignee_id Int @unique
assigner staff? @relation(fields: [assigner_id], references: [id])
assigner_id Int @unique
credit_value Float
start_date DateTime
end_date DateTime?
Expand Down
81 changes: 67 additions & 14 deletions backend/typescript/services/implementations/taskService.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
import ITaskService from "../interfaces/taskService";
import {TaskDTO, Status} from "../interfaces/taskService";
import { PrismaClient } from '@prisma/client'

const Prisma = new PrismaClient();
import prisma from '../../prisma';
import { Prisma } from "@prisma/client";

class TaskService implements ITaskService {
async getTaskById(taskId: string): Promise<TaskDTO> {
// async getTaskById(taskId: string): Promise<TaskDTO> {
// try {
// const task = await Prisma.task.findUnique({
// where: {
// id: Number(taskId)
// },

// });

// if (!task) {
// throw new Error(`help`);
// }

// return task;
// } catch (error: unknown) {
// throw error;
// }
// }

async getTaskById(taskId: string): Promise<Prisma.taskCreateInput> {
try {
const task = await Prisma.task.findUnique({
const task = await prisma.task.findUnique({
where: {
id: Number(taskId)
},

});

if (!task) {
Expand All @@ -24,34 +41,68 @@ class TaskService implements ITaskService {
}
}

async getTasksByCategoryId(categoryId: string): Promise<TaskDTO>{
async getTasksByCategoryId(categoryId: string): Promise<TaskDTO []>{
try {
const tasks = await Prisma.task.findMany({
where: {
id: Number(categoryId)
}
})

if (!tasks) {
throw new Error(`help`);
}

return tasks;
} catch (error: unknown) {
throw error;
}
}

async getTasksByAssigneeId(assigneeId: string): Promise<TaskDTO>{
return {

try {
const task = await Prisma.task.findUnique({
where: {
id: Number(assigneeId)
}
})

if (!task) {
throw new Error(`help`);
}

return task;
} catch (error: unknown) {
throw error;
}
}

async getTasksByAssignerId(assignerId: string): Promise<TaskDTO>{
return {

try {
const task = await Prisma.task.findUnique({
where: {
id: Number(assignerId)
}
})

if (!task) {
throw new Error(`help`);
}

return task;
} catch (error: unknown) {
throw error;
}
}

async createTask(task: TaskDTO): Promise<TaskDTO>{
return {

try {
const newTask = await Prisma.task.create({
data: task,
});
return newTask;
} catch (error: unknown) {
throw error;
}
}

Expand All @@ -66,4 +117,6 @@ class TaskService implements ITaskService {

}
}
}
}

export default TaskService
18 changes: 9 additions & 9 deletions backend/typescript/services/interfaces/taskService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,40 @@ export type Status = "Pending Approval" | "Incomplete" | "Complete" | "Excused";

export interface TaskDTO {
id: number;
//category: string;
category?: string;
category_id: number;
status: string;
description: string;
assignee_id: number;
//assignee: string;
assignee?: string;
assigner_id: number;
//assigner: string;
assigner?: string;
credit_value: number;
start_date: Date;
end_date: Date | null;
end_date?: Date | null;
comments: string;
recurrence_frequency: string;
//warnings
// warnings: warning []
}

import {Prisma} from "@prisma/client"
import {Prisma, category} from "@prisma/client"

interface ITaskService {
export interface ITaskService {
/**
* Get the task corresponding to the taskId
* @param id task id
* @returns a TaskDTO associated with the task id
* @throws Error if task retrieval fails
*/
getTaskById(taskId: string): Promise<TaskDTO>;
getTaskById(taskId: string): Promise<Prisma.taskCreateInput>;

/**
* Get all tasks belonging to a category
* @param categoryId category's id
* @returns a TaskDTO with category information
* @throws Error if task retrieval fails
*/
getTasksByCategoryId(categoryId: string): Promise<TaskDTO>;
getTasksByCategoryId(categoryId: string): Promise<TaskDTO []>;

/**
* Get all tasks assigned to a resident
Expand Down

0 comments on commit 42e888f

Please sign in to comment.