From 905f3a1cb8c319a7e12b67c8baabe41a32f650aa Mon Sep 17 00:00:00 2001 From: KathleenX7 Date: Thu, 3 Oct 2024 20:39:57 -0400 Subject: [PATCH 1/5] updated task schema --- backend/prisma/schema.prisma | 62 +++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index db1d651..73ba6dd 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -66,16 +66,36 @@ enum TaskType { ACHIEVEMENT } +enum DaysOfWeek { + MONDAY + TUESDAY + WEDNESDAY + THURSDAY + FRIDA + 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_day") // 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) From d79cbb8fb0cb396c4b79e5454d66c758ebf772c4 Mon Sep 17 00:00:00 2001 From: KathleenX7 Date: Thu, 3 Oct 2024 22:01:59 -0400 Subject: [PATCH 2/5] update APIs --- backend/graphql/resolvers/taskResolvers.ts | 14 +- backend/graphql/types/taskType.ts | 30 ++- .../20241004015234_refactor/migration.sql | 172 ++++++++++++++++++ backend/prisma/index.ts | 3 +- backend/prisma/schema.prisma | 2 +- .../services/implementations/taskService.ts | 34 ++-- backend/services/interfaces/taskService.ts | 21 ++- 7 files changed, 237 insertions(+), 39 deletions(-) create mode 100644 backend/migrations/20241004015234_refactor/migration.sql diff --git a/backend/graphql/resolvers/taskResolvers.ts b/backend/graphql/resolvers/taskResolvers.ts index 53dc760..f80c587 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 f65c19b..3695872 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 + FRIDA + 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/20241004015234_refactor/migration.sql b/backend/migrations/20241004015234_refactor/migration.sql new file mode 100644 index 0000000..740525e --- /dev/null +++ b/backend/migrations/20241004015234_refactor/migration.sql @@ -0,0 +1,172 @@ +-- CreateEnum +CREATE TYPE "UserType" AS ENUM ('STAFF', 'RESIDENT'); + +-- CreateEnum +CREATE TYPE "TaskType" AS ENUM ('REQUIRED', 'OPTIONAL', 'CHORE', 'ACHIEVEMENT'); + +-- CreateEnum +CREATE TYPE "DaysOfWeek" AS ENUM ('MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDA', 'SATURDAY', 'SUNDAY'); + +-- CreateEnum +CREATE TYPE "RecurrenceFrequency" AS ENUM ('ONE_TIME', 'REPEATS_PER_WEEK_SELECTED', 'REPEATS_PER_WEEK_ONCE'); + +-- CreateEnum +CREATE TYPE "Status" AS ENUM ('PENDING_APPROVAL', 'ASSIGNED', 'INCOMPLETE', 'COMPLETE', 'EXCUSED'); + +-- CreateTable +CREATE TABLE "users" ( + "id" SERIAL NOT NULL, + "type" "UserType" NOT NULL, + "auth_id" TEXT NOT NULL, + "email" TEXT NOT NULL, + "phone_number" TEXT, + "first_name" TEXT NOT NULL, + "last_name" TEXT NOT NULL, + "display_name" TEXT, + "profile_picture_url" TEXT, + "is_active" BOOLEAN NOT NULL DEFAULT true, + + CONSTRAINT "users_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "staff" ( + "user_id" INTEGER NOT NULL, + "is_admin" BOOLEAN NOT NULL DEFAULT false, + + CONSTRAINT "staff_pkey" PRIMARY KEY ("user_id") +); + +-- CreateTable +CREATE TABLE "residents" ( + "user_id" INTEGER NOT NULL, + "resident_id" INTEGER NOT NULL, + "birth_date" DATE NOT NULL, + "room_number" INTEGER NOT NULL, + "credits" DOUBLE PRECISION NOT NULL DEFAULT 0, + "date_joined" DATE NOT NULL DEFAULT CURRENT_TIMESTAMP, + "date_left" DATE, + "notes" TEXT, + + CONSTRAINT "residents_pkey" PRIMARY KEY ("user_id") +); + +-- CreateTable +CREATE TABLE "tasks" ( + "id" SERIAL NOT NULL, + "type" "TaskType" NOT NULL, + "title" TEXT NOT NULL, + "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") +); + +-- CreateTable +CREATE TABLE "task_locations" ( + "id" SERIAL NOT NULL, + "title" TEXT NOT NULL, + "description" TEXT NOT NULL, + + CONSTRAINT "task_locations_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "tasks_assigned" ( + "id" SERIAL NOT NULL, + "task_id" INTEGER NOT NULL, + "assigner_id" INTEGER, + "assignee_id" INTEGER NOT NULL, + "status" "Status" NOT NULL, + "start_date" TIMESTAMP(3) NOT NULL, + "comments" TEXT, + + CONSTRAINT "tasks_assigned_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "warnings" ( + "id" SERIAL NOT NULL, + "assigner_id" INTEGER, + "resident_id" INTEGER NOT NULL, + "related_task_id" INTEGER, + "title" TEXT NOT NULL, + "description" TEXT NOT NULL, + "date_issued" DATE NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "warnings_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "notifications" ( + "id" SERIAL NOT NULL, + "author_id" INTEGER, + "title" TEXT NOT NULL, + "message" TEXT NOT NULL, + "created_at" DATE NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "notifications_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "notifications_received" ( + "id" SERIAL NOT NULL, + "notification_id" INTEGER NOT NULL, + "recipient_id" INTEGER NOT NULL, + "seen" BOOLEAN NOT NULL DEFAULT false, + + CONSTRAINT "notifications_received_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "users_auth_id_key" ON "users"("auth_id"); + +-- CreateIndex +CREATE UNIQUE INDEX "users_email_key" ON "users"("email"); + +-- CreateIndex +CREATE UNIQUE INDEX "users_phone_number_key" ON "users"("phone_number"); + +-- CreateIndex +CREATE UNIQUE INDEX "residents_resident_id_key" ON "residents"("resident_id"); + +-- AddForeignKey +ALTER TABLE "staff" ADD CONSTRAINT "staff_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "residents" ADD CONSTRAINT "residents_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "tasks" ADD CONSTRAINT "tasks_location_id_fkey" FOREIGN KEY ("location_id") REFERENCES "task_locations"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "tasks_assigned" ADD CONSTRAINT "tasks_assigned_task_id_fkey" FOREIGN KEY ("task_id") REFERENCES "tasks"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "tasks_assigned" ADD CONSTRAINT "tasks_assigned_assigner_id_fkey" FOREIGN KEY ("assigner_id") REFERENCES "staff"("user_id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "tasks_assigned" ADD CONSTRAINT "tasks_assigned_assignee_id_fkey" FOREIGN KEY ("assignee_id") REFERENCES "residents"("user_id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "warnings" ADD CONSTRAINT "warnings_assigner_id_fkey" FOREIGN KEY ("assigner_id") REFERENCES "staff"("user_id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "warnings" ADD CONSTRAINT "warnings_resident_id_fkey" FOREIGN KEY ("resident_id") REFERENCES "residents"("user_id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "warnings" ADD CONSTRAINT "warnings_related_task_id_fkey" FOREIGN KEY ("related_task_id") REFERENCES "tasks"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "notifications" ADD CONSTRAINT "notifications_author_id_fkey" FOREIGN KEY ("author_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "notifications_received" ADD CONSTRAINT "notifications_received_notification_id_fkey" FOREIGN KEY ("notification_id") REFERENCES "notifications"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "notifications_received" ADD CONSTRAINT "notifications_received_recipient_id_fkey" FOREIGN KEY ("recipient_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/backend/prisma/index.ts b/backend/prisma/index.ts index 822612f..55a6406 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 73ba6dd..5124bf5 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -95,7 +95,7 @@ model Task { endDate DateTime? @map("end_date") recurrenceFrequency RecurrenceFrequency @map("recurrence_frequency") specificDay DaysOfWeek? @map("specific_day") // used for one time tasks - repeatDays DaysOfWeek[] @map("repeat_day") // used for repeating tasks + repeatDays DaysOfWeek[] @map("repeat_days") // used for repeating tasks @@map("tasks") } diff --git a/backend/services/implementations/taskService.ts b/backend/services/implementations/taskService.ts index 81df7d0..80c401c 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 2cf4c99..abc93f6 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 From b6ef199ad65fa53425eeb9c1d9a2fc8ef57b6442 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 10 Oct 2024 19:36:13 -0400 Subject: [PATCH 3/5] Fix: mild typo --- backend/prisma/schema.prisma | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 5124bf5..f1c85c7 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -71,7 +71,7 @@ enum DaysOfWeek { TUESDAY WEDNESDAY THURSDAY - FRIDA + FRIDAY SATURDAY SUNDAY } From 6715e2007f743ef06fe56fec4957efc747d356e8 Mon Sep 17 00:00:00 2001 From: Jesse Huang Date: Thu, 10 Oct 2024 19:38:56 -0400 Subject: [PATCH 4/5] Delete backend/migrations/20241004015234_refactor/migration.sql nvm not needed --- .../20241004015234_refactor/migration.sql | 172 ------------------ 1 file changed, 172 deletions(-) delete mode 100644 backend/migrations/20241004015234_refactor/migration.sql diff --git a/backend/migrations/20241004015234_refactor/migration.sql b/backend/migrations/20241004015234_refactor/migration.sql deleted file mode 100644 index 740525e..0000000 --- a/backend/migrations/20241004015234_refactor/migration.sql +++ /dev/null @@ -1,172 +0,0 @@ --- CreateEnum -CREATE TYPE "UserType" AS ENUM ('STAFF', 'RESIDENT'); - --- CreateEnum -CREATE TYPE "TaskType" AS ENUM ('REQUIRED', 'OPTIONAL', 'CHORE', 'ACHIEVEMENT'); - --- CreateEnum -CREATE TYPE "DaysOfWeek" AS ENUM ('MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDA', 'SATURDAY', 'SUNDAY'); - --- CreateEnum -CREATE TYPE "RecurrenceFrequency" AS ENUM ('ONE_TIME', 'REPEATS_PER_WEEK_SELECTED', 'REPEATS_PER_WEEK_ONCE'); - --- CreateEnum -CREATE TYPE "Status" AS ENUM ('PENDING_APPROVAL', 'ASSIGNED', 'INCOMPLETE', 'COMPLETE', 'EXCUSED'); - --- CreateTable -CREATE TABLE "users" ( - "id" SERIAL NOT NULL, - "type" "UserType" NOT NULL, - "auth_id" TEXT NOT NULL, - "email" TEXT NOT NULL, - "phone_number" TEXT, - "first_name" TEXT NOT NULL, - "last_name" TEXT NOT NULL, - "display_name" TEXT, - "profile_picture_url" TEXT, - "is_active" BOOLEAN NOT NULL DEFAULT true, - - CONSTRAINT "users_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "staff" ( - "user_id" INTEGER NOT NULL, - "is_admin" BOOLEAN NOT NULL DEFAULT false, - - CONSTRAINT "staff_pkey" PRIMARY KEY ("user_id") -); - --- CreateTable -CREATE TABLE "residents" ( - "user_id" INTEGER NOT NULL, - "resident_id" INTEGER NOT NULL, - "birth_date" DATE NOT NULL, - "room_number" INTEGER NOT NULL, - "credits" DOUBLE PRECISION NOT NULL DEFAULT 0, - "date_joined" DATE NOT NULL DEFAULT CURRENT_TIMESTAMP, - "date_left" DATE, - "notes" TEXT, - - CONSTRAINT "residents_pkey" PRIMARY KEY ("user_id") -); - --- CreateTable -CREATE TABLE "tasks" ( - "id" SERIAL NOT NULL, - "type" "TaskType" NOT NULL, - "title" TEXT NOT NULL, - "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") -); - --- CreateTable -CREATE TABLE "task_locations" ( - "id" SERIAL NOT NULL, - "title" TEXT NOT NULL, - "description" TEXT NOT NULL, - - CONSTRAINT "task_locations_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "tasks_assigned" ( - "id" SERIAL NOT NULL, - "task_id" INTEGER NOT NULL, - "assigner_id" INTEGER, - "assignee_id" INTEGER NOT NULL, - "status" "Status" NOT NULL, - "start_date" TIMESTAMP(3) NOT NULL, - "comments" TEXT, - - CONSTRAINT "tasks_assigned_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "warnings" ( - "id" SERIAL NOT NULL, - "assigner_id" INTEGER, - "resident_id" INTEGER NOT NULL, - "related_task_id" INTEGER, - "title" TEXT NOT NULL, - "description" TEXT NOT NULL, - "date_issued" DATE NOT NULL DEFAULT CURRENT_TIMESTAMP, - - CONSTRAINT "warnings_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "notifications" ( - "id" SERIAL NOT NULL, - "author_id" INTEGER, - "title" TEXT NOT NULL, - "message" TEXT NOT NULL, - "created_at" DATE NOT NULL DEFAULT CURRENT_TIMESTAMP, - - CONSTRAINT "notifications_pkey" PRIMARY KEY ("id") -); - --- CreateTable -CREATE TABLE "notifications_received" ( - "id" SERIAL NOT NULL, - "notification_id" INTEGER NOT NULL, - "recipient_id" INTEGER NOT NULL, - "seen" BOOLEAN NOT NULL DEFAULT false, - - CONSTRAINT "notifications_received_pkey" PRIMARY KEY ("id") -); - --- CreateIndex -CREATE UNIQUE INDEX "users_auth_id_key" ON "users"("auth_id"); - --- CreateIndex -CREATE UNIQUE INDEX "users_email_key" ON "users"("email"); - --- CreateIndex -CREATE UNIQUE INDEX "users_phone_number_key" ON "users"("phone_number"); - --- CreateIndex -CREATE UNIQUE INDEX "residents_resident_id_key" ON "residents"("resident_id"); - --- AddForeignKey -ALTER TABLE "staff" ADD CONSTRAINT "staff_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "residents" ADD CONSTRAINT "residents_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "tasks" ADD CONSTRAINT "tasks_location_id_fkey" FOREIGN KEY ("location_id") REFERENCES "task_locations"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "tasks_assigned" ADD CONSTRAINT "tasks_assigned_task_id_fkey" FOREIGN KEY ("task_id") REFERENCES "tasks"("id") ON DELETE RESTRICT ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "tasks_assigned" ADD CONSTRAINT "tasks_assigned_assigner_id_fkey" FOREIGN KEY ("assigner_id") REFERENCES "staff"("user_id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "tasks_assigned" ADD CONSTRAINT "tasks_assigned_assignee_id_fkey" FOREIGN KEY ("assignee_id") REFERENCES "residents"("user_id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "warnings" ADD CONSTRAINT "warnings_assigner_id_fkey" FOREIGN KEY ("assigner_id") REFERENCES "staff"("user_id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "warnings" ADD CONSTRAINT "warnings_resident_id_fkey" FOREIGN KEY ("resident_id") REFERENCES "residents"("user_id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "warnings" ADD CONSTRAINT "warnings_related_task_id_fkey" FOREIGN KEY ("related_task_id") REFERENCES "tasks"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "notifications" ADD CONSTRAINT "notifications_author_id_fkey" FOREIGN KEY ("author_id") REFERENCES "users"("id") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "notifications_received" ADD CONSTRAINT "notifications_received_notification_id_fkey" FOREIGN KEY ("notification_id") REFERENCES "notifications"("id") ON DELETE CASCADE ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "notifications_received" ADD CONSTRAINT "notifications_received_recipient_id_fkey" FOREIGN KEY ("recipient_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; From 04916d3cecc34e68b40045e237b3cb8c8db4b0d6 Mon Sep 17 00:00:00 2001 From: Jesse Huang <87463074+jeessh@users.noreply.github.com> Date: Thu, 10 Oct 2024 19:55:38 -0400 Subject: [PATCH 5/5] fix typos & added migrations --- backend/graphql/types/taskType.ts | 2 +- .../migration.sql | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) rename backend/migrations/{20240321203401_refactor => 20241010235436_task_refactor}/migration.sql (92%) diff --git a/backend/graphql/types/taskType.ts b/backend/graphql/types/taskType.ts index 3695872..e0b47e6 100644 --- a/backend/graphql/types/taskType.ts +++ b/backend/graphql/types/taskType.ts @@ -20,7 +20,7 @@ const taskType = gql` TUESDAY WEDNESDAY THURSDAY - FRIDA + FRIDAY SATURDAY SUNDAY } 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 859a9bd..b72a267 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")