Skip to content

Commit

Permalink
Merge pull request #110 from uwblueprint/kathleen-megan/update-task-s…
Browse files Browse the repository at this point in the history
…chema

Update task schema and APIs
  • Loading branch information
jeessh authored Oct 10, 2024
2 parents d012eb2 + 04916d3 commit 893035e
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 68 deletions.
14 changes: 7 additions & 7 deletions backend/graphql/resolvers/taskResolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ const taskResolvers = {
const tasks = await taskService.getTasksByStartDate(startDate);
return tasks;
},
getTasksByEndDate: async (
_parent: undefined,
{ endDate }: { endDate: Date },
): Promise<TaskAssignedDTO[]> => {
const tasks = await taskService.getTasksByEndDate(endDate);
return tasks;
},
// getTasksByEndDate: async (
// _parent: undefined,
// { endDate }: { endDate: Date },
// ): Promise<TaskAssignedDTO[]> => {
// const tasks = await taskService.getTasksByEndDate(endDate);
// return tasks;
// },
getTasksByStatus: async (
_parent: undefined,
{ status }: { status: Status },
Expand Down
30 changes: 22 additions & 8 deletions backend/graphql/types/taskType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -30,6 +40,10 @@ const taskType = gql`
creditValue: Int!
location: TaskLocationDTO!
tasksAssigned: [TaskAssignedDTO!]
endDate: DateTime
recurrenceFrequency: Recurrence_Frequency!
specificDay: DaysOfWeek
repeatDays: [DaysOfWeek!]
}
type TaskLocationDTO {
Expand All @@ -44,6 +58,10 @@ const taskType = gql`
description: String!
creditValue: Int!
locationId: Int!
endDate: DateTime
recurrenceFrequency: Recurrence_Frequency!
specificDay: DaysOfWeek
repeatDays: [DaysOfWeek!]
}
input InputTaskAssignedDTO {
Expand All @@ -52,8 +70,6 @@ const taskType = gql`
assignerId: Int
status: Status
startDate: DateTime
endDate: DateTime
recurrenceFrequency: Recurrence_Frequency
comments: String
}
Expand All @@ -64,8 +80,6 @@ const taskType = gql`
assignerId: Int!
status: Status!
startDate: DateTime!
endDate: DateTime!
recurrenceFrequency: Recurrence_Frequency
comments: String
}
Expand All @@ -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]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" (
Expand Down Expand Up @@ -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")
);
Expand All @@ -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")
Expand Down
3 changes: 2 additions & 1 deletion backend/prisma/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
62 changes: 37 additions & 25 deletions backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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])
Expand All @@ -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)
Expand Down
34 changes: 18 additions & 16 deletions backend/services/implementations/taskService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ class TaskService implements ITaskService {
}
}

async getTasksByEndDate(endDate: Date): Promise<TaskAssignedDTO[]> {
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<TaskAssignedDTO[]> {
// 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<TaskAssignedDTO[]> {
try {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -201,8 +205,6 @@ class TaskService implements ITaskService {
},
status: taskAssigned.status,
startDate: taskAssigned.startDate,
endDate: taskAssigned.endDate,
recurrenceFrequency: taskAssigned.recurrenceFrequency,
comments: taskAssigned.comments,
},
});
Expand Down
21 changes: 15 additions & 6 deletions backend/services/interfaces/taskService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { TaskType, Status, RecurrenceFrequency } from "../../prisma";
import {
TaskType,
Status,
RecurrenceFrequency,
DaysOfWeek,
} from "../../prisma";

export interface TaskDTO {
id: number;
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -29,8 +42,6 @@ export interface InputTaskAssignedDTO {
assignerId?: number;
status: Status;
startDate: Date;
endDate: Date;
recurrenceFrequency?: RecurrenceFrequency;
comments?: string;
}

Expand All @@ -41,8 +52,6 @@ export interface TaskAssignedDTO {
assigneeId: number;
status: Status;
startDate: Date;
endDate: Date;
recurrenceFrequency: RecurrenceFrequency | null;
comments: string | null;
}

Expand Down Expand Up @@ -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<TaskAssignedDTO[]>;
// getTasksByEndDate(endDate: Date): Promise<TaskAssignedDTO[]>;

/**
* Get all tasks by a status
Expand Down

0 comments on commit 893035e

Please sign in to comment.