diff --git a/backend/graphql/resolvers/taskResolvers.ts b/backend/graphql/resolvers/taskResolvers.ts index 53dc760a..f80c5874 100644 --- a/backend/graphql/resolvers/taskResolvers.ts +++ b/backend/graphql/resolvers/taskResolvers.ts @@ -46,13 +46,13 @@ const taskResolvers = { const tasks = await taskService.getTasksByStartDate(startDate); return tasks; }, - getTasksByEndDate: async ( - _parent: undefined, - { endDate }: { endDate: Date }, - ): Promise => { - const tasks = await taskService.getTasksByEndDate(endDate); - return tasks; - }, + // getTasksByEndDate: async ( + // _parent: undefined, + // { endDate }: { endDate: Date }, + // ): Promise => { + // const tasks = await taskService.getTasksByEndDate(endDate); + // return tasks; + // }, getTasksByStatus: async ( _parent: undefined, { status }: { status: Status }, diff --git a/backend/graphql/types/taskType.ts b/backend/graphql/types/taskType.ts index f65c19b2..e0b47e63 100644 --- a/backend/graphql/types/taskType.ts +++ b/backend/graphql/types/taskType.ts @@ -10,9 +10,19 @@ const taskType = gql` } enum Recurrence_Frequency { - DAILY - WEEKLY - BI_WEEKLY + ONE_TIME + REPEATS_PER_WEEK_SELECTED + REPEATS_PER_WEEK_ONCE + } + + enum DaysOfWeek { + MONDAY + TUESDAY + WEDNESDAY + THURSDAY + FRIDAY + SATURDAY + SUNDAY } enum TaskType { @@ -30,6 +40,10 @@ const taskType = gql` creditValue: Int! location: TaskLocationDTO! tasksAssigned: [TaskAssignedDTO!] + endDate: DateTime + recurrenceFrequency: Recurrence_Frequency! + specificDay: DaysOfWeek + repeatDays: [DaysOfWeek!] } type TaskLocationDTO { @@ -44,6 +58,10 @@ const taskType = gql` description: String! creditValue: Int! locationId: Int! + endDate: DateTime + recurrenceFrequency: Recurrence_Frequency! + specificDay: DaysOfWeek + repeatDays: [DaysOfWeek!] } input InputTaskAssignedDTO { @@ -52,8 +70,6 @@ const taskType = gql` assignerId: Int status: Status startDate: DateTime - endDate: DateTime - recurrenceFrequency: Recurrence_Frequency comments: String } @@ -64,8 +80,6 @@ const taskType = gql` assignerId: Int! status: Status! startDate: DateTime! - endDate: DateTime! - recurrenceFrequency: Recurrence_Frequency comments: String } @@ -75,7 +89,7 @@ const taskType = gql` getTasksByAssigneeId(assigneeId: Int!): [TaskAssignedDTO] getTasksByAssignerId(assignerId: Int!): [TaskAssignedDTO] getTasksByStartDate(startDate: DateTime!): [TaskAssignedDTO] - getTasksByEndDate(endDate: DateTime!): [TaskAssignedDTO] + # getTasksByEndDate(endDate: DateTime!): [TaskAssignedDTO] getTasksByStatus(status: Status!): [TaskAssignedDTO] } diff --git a/backend/migrations/20240321203401_refactor/migration.sql b/backend/migrations/20241010235436_task_refactor/migration.sql similarity index 92% rename from backend/migrations/20240321203401_refactor/migration.sql rename to backend/migrations/20241010235436_task_refactor/migration.sql index 859a9bd7..b72a267f 100644 --- a/backend/migrations/20240321203401_refactor/migration.sql +++ b/backend/migrations/20241010235436_task_refactor/migration.sql @@ -5,10 +5,13 @@ CREATE TYPE "UserType" AS ENUM ('STAFF', 'RESIDENT'); CREATE TYPE "TaskType" AS ENUM ('REQUIRED', 'OPTIONAL', 'CHORE', 'ACHIEVEMENT'); -- CreateEnum -CREATE TYPE "Status" AS ENUM ('PENDING_APPROVAL', 'ASSIGNED', 'INCOMPLETE', 'COMPLETE', 'EXCUSED'); +CREATE TYPE "DaysOfWeek" AS ENUM ('MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY'); + +-- CreateEnum +CREATE TYPE "RecurrenceFrequency" AS ENUM ('ONE_TIME', 'REPEATS_PER_WEEK_SELECTED', 'REPEATS_PER_WEEK_ONCE'); -- CreateEnum -CREATE TYPE "RecurrenceFrequency" AS ENUM ('DAILY', 'WEEKLY', 'BI_WEEKLY'); +CREATE TYPE "Status" AS ENUM ('PENDING_APPROVAL', 'ASSIGNED', 'INCOMPLETE', 'COMPLETE', 'EXCUSED'); -- CreateTable CREATE TABLE "users" ( @@ -56,6 +59,10 @@ CREATE TABLE "tasks" ( "description" TEXT NOT NULL, "credit_value" DOUBLE PRECISION NOT NULL, "location_id" INTEGER NOT NULL, + "end_date" TIMESTAMP(3), + "recurrence_frequency" "RecurrenceFrequency" NOT NULL, + "specific_day" "DaysOfWeek", + "repeat_days" "DaysOfWeek"[], CONSTRAINT "tasks_pkey" PRIMARY KEY ("id") ); @@ -76,9 +83,7 @@ CREATE TABLE "tasks_assigned" ( "assigner_id" INTEGER, "assignee_id" INTEGER NOT NULL, "status" "Status" NOT NULL, - "start_date" DATE NOT NULL, - "end_date" DATE, - "recurrence_frequency" "RecurrenceFrequency", + "start_date" TIMESTAMP(3) NOT NULL, "comments" TEXT, CONSTRAINT "tasks_assigned_pkey" PRIMARY KEY ("id") diff --git a/backend/prisma/index.ts b/backend/prisma/index.ts index 822612f2..55a64069 100644 --- a/backend/prisma/index.ts +++ b/backend/prisma/index.ts @@ -4,9 +4,10 @@ import { TaskType, Status, RecurrenceFrequency, + DaysOfWeek, } from "@prisma/client"; -export { UserType, TaskType, Status, RecurrenceFrequency }; +export { UserType, TaskType, Status, RecurrenceFrequency, DaysOfWeek }; const prisma = new PrismaClient(); diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index db1d6513..f1c85c7e 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -66,16 +66,36 @@ enum TaskType { ACHIEVEMENT } +enum DaysOfWeek { + MONDAY + TUESDAY + WEDNESDAY + THURSDAY + FRIDAY + SATURDAY + SUNDAY +} + +enum RecurrenceFrequency { + ONE_TIME + REPEATS_PER_WEEK_SELECTED + REPEATS_PER_WEEK_ONCE +} + model Task { - id Int @id @default(autoincrement()) - type TaskType - title String - description String - creditValue Float @map("credit_value") - location TaskLocation @relation(fields: [locationId], references: [id], onDelete: Cascade, onUpdate: Cascade) - locationId Int @map("location_id") - tasksAssigned TaskAssigned[] - relatedWarnings Warning[] + id Int @id @default(autoincrement()) + type TaskType + title String + description String + creditValue Float @map("credit_value") + location TaskLocation @relation(fields: [locationId], references: [id], onDelete: Cascade, onUpdate: Cascade) + locationId Int @map("location_id") + tasksAssigned TaskAssigned[] + relatedWarnings Warning[] + endDate DateTime? @map("end_date") + recurrenceFrequency RecurrenceFrequency @map("recurrence_frequency") + specificDay DaysOfWeek? @map("specific_day") // used for one time tasks + repeatDays DaysOfWeek[] @map("repeat_days") // used for repeating tasks @@map("tasks") } @@ -89,20 +109,6 @@ model TaskLocation { @@map("task_locations") } -enum Status { - PENDING_APPROVAL - ASSIGNED - INCOMPLETE - COMPLETE - EXCUSED -} - -enum RecurrenceFrequency { - DAILY - WEEKLY - BI_WEEKLY -} - model TaskAssigned { id Int @id @default(autoincrement()) task Task @relation(fields: [taskId], references: [id]) @@ -113,13 +119,19 @@ model TaskAssigned { assigneeId Int @map("assignee_id") status Status startDate DateTime @map("start_date") - endDate DateTime @map("end_date") - recurrenceFrequency RecurrenceFrequency? @map("recurrence_frequency") comments String? @@map("tasks_assigned") } +enum Status { + PENDING_APPROVAL + ASSIGNED + INCOMPLETE + COMPLETE + EXCUSED +} + model Warning { id Int @id @default(autoincrement()) assigner Staff? @relation(fields: [assignerId], references: [userId], onDelete: SetNull, onUpdate: Cascade) diff --git a/backend/services/implementations/taskService.ts b/backend/services/implementations/taskService.ts index 81df7d0e..80c401cb 100644 --- a/backend/services/implementations/taskService.ts +++ b/backend/services/implementations/taskService.ts @@ -91,20 +91,20 @@ class TaskService implements ITaskService { } } - async getTasksByEndDate(endDate: Date): Promise { - try { - const tasks = await prisma.taskAssigned.findMany({ - where: { - endDate, - }, - }); - - return tasks; - } catch (error: unknown) { - Logger.error(`Failed to get tasks. Reason = ${getErrorMessage(error)}`); - throw error; - } - } + // async getTasksByEndDate(endDate: Date): Promise { + // try { + // const tasks = await prisma.taskAssigned.findMany({ + // where: { + // endDate, + // }, + // }); + + // return tasks; + // } catch (error: unknown) { + // Logger.error(`Failed to get tasks. Reason = ${getErrorMessage(error)}`); + // throw error; + // } + // } async getTasksByStatus(status: Status): Promise { try { @@ -132,6 +132,10 @@ class TaskService implements ITaskService { location: { connect: { id: task.locationId }, }, + endDate: task.endDate, + recurrenceFrequency: task.recurrenceFrequency, + specificDay: task.specificDay, + repeatDays: task.repeatDays, }, include: { location: true, @@ -201,8 +205,6 @@ class TaskService implements ITaskService { }, status: taskAssigned.status, startDate: taskAssigned.startDate, - endDate: taskAssigned.endDate, - recurrenceFrequency: taskAssigned.recurrenceFrequency, comments: taskAssigned.comments, }, }); diff --git a/backend/services/interfaces/taskService.ts b/backend/services/interfaces/taskService.ts index 2cf4c99b..abc93f6d 100644 --- a/backend/services/interfaces/taskService.ts +++ b/backend/services/interfaces/taskService.ts @@ -1,4 +1,9 @@ -import { TaskType, Status, RecurrenceFrequency } from "../../prisma"; +import { + TaskType, + Status, + RecurrenceFrequency, + DaysOfWeek, +} from "../../prisma"; export interface TaskDTO { id: number; @@ -7,6 +12,10 @@ export interface TaskDTO { description: string; creditValue: number; location: TaskLocationDTO; + endDate: Date | null; + recurrenceFrequency: RecurrenceFrequency; + specificDay: DaysOfWeek | null; + repeatDays: DaysOfWeek[]; } export interface TaskLocationDTO { @@ -21,6 +30,10 @@ export interface InputTaskDTO { description: string; creditValue: number; locationId: number; + endDate: Date | null; + recurrenceFrequency: RecurrenceFrequency; + specificDay: DaysOfWeek | null; + repeatDays: DaysOfWeek[]; } export interface InputTaskAssignedDTO { @@ -29,8 +42,6 @@ export interface InputTaskAssignedDTO { assignerId?: number; status: Status; startDate: Date; - endDate: Date; - recurrenceFrequency?: RecurrenceFrequency; comments?: string; } @@ -41,8 +52,6 @@ export interface TaskAssignedDTO { assigneeId: number; status: Status; startDate: Date; - endDate: Date; - recurrenceFrequency: RecurrenceFrequency | null; comments: string | null; } @@ -93,7 +102,7 @@ interface ITaskService { * @returns a list of TaskDTOs ending on the provided date * @throws Error if task retrieval fails */ - getTasksByEndDate(endDate: Date): Promise; + // getTasksByEndDate(endDate: Date): Promise; /** * Get all tasks by a status