From 282ceba26fc682abf48def2e1c9e587441fa877c Mon Sep 17 00:00:00 2001 From: KathleenX7 Date: Sat, 12 Oct 2024 11:30:24 -0400 Subject: [PATCH 1/2] Api contants --- .../src/APIClients/Mutations/TaskMutations.ts | 77 ++++++++++++++++ .../src/APIClients/Queries/TaskQueries.ts | 89 +++++++++++++++++++ frontend/src/APIClients/Types/TaskType.ts | 81 +++++++++++++++++ 3 files changed, 247 insertions(+) create mode 100644 frontend/src/APIClients/Mutations/TaskMutations.ts create mode 100644 frontend/src/APIClients/Queries/TaskQueries.ts create mode 100644 frontend/src/APIClients/Types/TaskType.ts diff --git a/frontend/src/APIClients/Mutations/TaskMutations.ts b/frontend/src/APIClients/Mutations/TaskMutations.ts new file mode 100644 index 00000000..7f8c96ec --- /dev/null +++ b/frontend/src/APIClients/Mutations/TaskMutations.ts @@ -0,0 +1,77 @@ +import { gql } from "@apollo/client"; + +export const CREATE_TASK = gql` + mutation CreateTask($task: InputTaskDTO!) { + createTask(task: $task) { + id + type + title + description + creditValue + endDate + recurrenceFrequency + specificDay + repeatDays + } + } +`; + +export const UPDATE_TASK = gql` + mutation UpdateTASK($taskId: Int!, $task: InputTaskDTO!) { + updateTask(taskId: $taskId, task: $task) { + id + type + title + description + creditValue + endDate + recurrenceFrequency + specificDay + repeatDays + } + } +`; + +export const DELETE_TASK = gql` + mutation DeleteStaff($taskId: Int!) { + deleteTask(taskId: $taskId) { + id + type + title + description + creditValue + endDate + recurrenceFrequency + specificDay + repeatDays + } + } +`; + +export const ASSIGN_TASK = gql` + mutation AssignTask($taskAssigned: InputTaskAssignedDTO!) { + assignTask(taskAssigned: $taskAssigned) { + id + taskId + assigneeId + assignerId + status + startDate + comments + } + } +`; + +export const CHANGE_TASK_STATUS = gql` + mutation ChangeTaskStatus($taskAssignedId: Int!, $status: Status!) { + changeTaskStatus(taskAssignedId: $taskAssignedId, status: $status) { + id + taskId + assigneeId + assignerId + status + startDate + comments + } + } +`; diff --git a/frontend/src/APIClients/Queries/TaskQueries.ts b/frontend/src/APIClients/Queries/TaskQueries.ts new file mode 100644 index 00000000..7607d5c1 --- /dev/null +++ b/frontend/src/APIClients/Queries/TaskQueries.ts @@ -0,0 +1,89 @@ +import { gql } from "@apollo/client"; + +export const GET_TASK_BY_ID = gql` + query getTaskById($taskId: Int!) { + getTaskById(taskId: $taskId) { + id + type + title + description + creditValue + endDate + recurrenceFrequency + specificDay + repeatDays + } + } +`; + +export const GET_TASKS_BY_TYPE = gql` + query getTaskById($type: TaskType!) { + getTasksByType(type: $type) { + id + type + title + description + creditValue + endDate + recurrenceFrequency + specificDay + repeatDays + } + } +`; + +export const GET_TASKS_BY_ASSIGNEE_ID = gql` + query getTasksByAssigneeId($assigneeId: Int!) { + getTasksByAssigneeId(assigneeId: $assigneeId) { + id + taskId + assigneeId + assignerId + status + startDate + comments + } + } +`; + +export const GET_TASKS_BY_ASSIGNER_ID = gql` + query GetTasksByAssignerId($assignerId: Int!) { + getTasksByAssignerId(assignerId: $assignerId) { + id + taskId + assigneeId + assignerId + status + startDate + comments + } + } +`; + +export const GET_TASKS_BY_START_DATE = gql` + query GetTasksByStartDate($startDate: DateTime!) { + getTasksByStartDate(startDate: $startDate) { + id + taskId + assigneeId + assignerId + status + startDate + comments + } + } +`; + +export const GET_TASKS_BY_STATUS = gql` + query GetTasksByStatus($status: Status!) { + getTasksByStatus(status: $status) { + id + taskId + assigneeId + assignerId + status + startDate + comments + } + } +`; diff --git a/frontend/src/APIClients/Types/TaskType.ts b/frontend/src/APIClients/Types/TaskType.ts new file mode 100644 index 00000000..bd4c193d --- /dev/null +++ b/frontend/src/APIClients/Types/TaskType.ts @@ -0,0 +1,81 @@ +export enum Status { + PENDING_APPROVAL = "PENDING_APPROVAL", + ASSIGNED = "ASSIGNED", + INCOMPLETE = "INCOMPLETE", + COMPLETE = "COMPLETE", + EXCUSED = "EXCUSED", +} + +export enum RecurrenceFrequency { + ONE_TIME = "ONE_TIME", + REPEATS_PER_WEEK_SELECTED = "REPEATS_PER_WEEK_SELECTED", + REPEATS_PER_WEEK_ONCE = "REPEATS_PER_WEEK_ONCE", +} + +export enum DaysOfWeek { + MONDAY = "MONDAY", + TUESDAY = "TUESDAY", + WEDNESDAY = "WEDNESDAY", + THURSDAY = "THURSDAY", + FRIDAY = "FRIDAY", + SATURDAY = "SATURDAY", + SUNDAY = "SUNDAY", +} + +export enum TaskTypeEnum { + REQUIRED = "REQUIRED", + OPTIONAL = "OPTIONAL", + CHORE = "CHORE", + ACHIEVEMENT = "ACHIEVEMENT", +} + +export type TaskLocation = { + id: number; + title: string; + description: string; +}; + +export type TaskResponse = { + id: number; + type: TaskTypeEnum; + title: string; + description: string; + creditValue: number; + location: TaskLocation; + tasksAssigned: TaskResponse[]; + endDate?: Date; + recurrenceFrequency: RecurrenceFrequency; + specificDay?: DaysOfWeek; + repeatDays?: DaysOfWeek[]; +}; + +export type TaskRequest = { + type: TaskTypeEnum; + title: string; + description: string; + creditValue: number; + locationId: number; + endDate?: Date; + recurrenceFrequency: RecurrenceFrequency; + specificDay?: DaysOfWeek; + repeatDays?: DaysOfWeek[]; +}; + +export type TaskAssignedResponse = { + id: number; + taskId: number; + assigneeId: number; + assignerId: number; + status: Status; + startDate: Date; + comments?: string; +}; + +export type TaskAssignedRequest = { + taskId?: number; + assigneeId?: number; + assignerId?: number; + status?: Status; + startDate?: Date; + comments?: string; +}; From 9a756b52b6b81cc94083d9454e245b68ac7eebe1 Mon Sep 17 00:00:00 2001 From: KathleenX7 Date: Sat, 12 Oct 2024 11:30:43 -0400 Subject: [PATCH 2/2] Add Testing in Tasks --- .../src/components/pages/tasks/TasksPage.tsx | 263 +++++++++++++++--- 1 file changed, 230 insertions(+), 33 deletions(-) diff --git a/frontend/src/components/pages/tasks/TasksPage.tsx b/frontend/src/components/pages/tasks/TasksPage.tsx index 0c826fcf..a03a08d0 100644 --- a/frontend/src/components/pages/tasks/TasksPage.tsx +++ b/frontend/src/components/pages/tasks/TasksPage.tsx @@ -11,7 +11,36 @@ import { Icon, } from "@chakra-ui/react"; import { Add, Search } from "@mui/icons-material"; +import { useMutation, useQuery } from "@apollo/client"; +import { + CREATE_TASK, + UPDATE_TASK, + DELETE_TASK, + ASSIGN_TASK, + CHANGE_TASK_STATUS, +} from "../../../APIClients/Mutations/TaskMutations"; + +import { + GET_TASK_BY_ID, + GET_TASKS_BY_TYPE, + GET_TASKS_BY_ASSIGNEE_ID, + GET_TASKS_BY_ASSIGNER_ID, + GET_TASKS_BY_START_DATE, + GET_TASKS_BY_STATUS, +} from "../../../APIClients/Queries/TaskQueries"; + +import { + Status, + RecurrenceFrequency, + DaysOfWeek, + TaskTypeEnum, + TaskLocation, + TaskResponse, + TaskRequest, + TaskAssignedRequest, + TaskAssignedResponse, +} from "../../../APIClients/Types/TaskType"; import TaskModal from "./TaskModal"; import { TaskType, @@ -49,6 +78,174 @@ const TasksPage = (): React.ReactElement => { const [taskFilter, setTaskFilter] = useState(""); + // const [createTask] = useMutation<{ createTask: TaskResponse }>(CREATE_TASK); + + // const [updateTask] = useMutation<{ + // taskID: number; + // taskId: TaskResponse; + // }>(UPDATE_TASK); + + // const [deleteTask] = useMutation<{ taskID: number }>(DELETE_TASK); + + // const [assignTask] = useMutation<{ assignTask: TaskAssignedResponse }>( + // ASSIGN_TASK, + // ); + + // const [changeTaskStatus] = useMutation<{ + // taskAssignedID: number; + // status: Status; + // }>(CHANGE_TASK_STATUS); + + // const { + // loading: taskByIdLoading, + // error: taskByIdError, + // data: taskByIdData, + // } = useQuery<{ taskId: number }>(GET_TASK_BY_ID, { + // variables: { taskId: 1 }, + // }); + // const taskById = React.useMemo(() => { + // return taskByIdData; + // }, [taskByIdData]); + + // const { + // loading: tasksbyTypeLoading, + // error: tasksByTypeError, + // data: tassByTypeData, + // } = useQuery<{ type: TaskTypeEnum }>(GET_TASKS_BY_TYPE, { + // variables: {type: TaskTypeEnum.REQUIRED}, + // }); + // const tasksByType = React.useMemo(() => { + // return tassByTypeData; + // }, [tassByTypeData]); + + // const { + // loading: tasksByAssigneeIdLoading, + // error: tasksByAssigneeIdError, + // data: tasksByAssigneeIdData, + // } = useQuery<{ assigneeId: number }>(GET_TASKS_BY_ASSIGNEE_ID, { + // variables: { assigneeId: 4 }, + // }); + // const tasksByAssigneeId = React.useMemo(() => { + // return tasksByAssigneeIdData; + // }, [tasksByAssigneeIdData]); + + // const { + // loading: tasksByAssignerIdLoading, + // error: tasksByAssignerIdError, + // data: tasksByAssignerIdData, + // } = useQuery<{ assignerId: number }>(GET_TASKS_BY_ASSIGNER_ID, { + // variables: { assignerId: 6 }, + // }); + // const tasksByAssignerId = React.useMemo(() => { + // return tasksByAssignerIdData; + // }, [tasksByAssignerIdData]); + + // const startDateVar = new Date("2011-10-05T14:48:00.000Z"); + // const { + // loading: tasksByStartDateLoading, + // error: tasksByStartDateError, + // data: taskByStartDateData, + // } = useQuery<{ startDate: Date }>(GET_TASKS_BY_START_DATE, { + // variables: { startDate: startDateVar }, + // }); + // const tasksByStartDate = React.useMemo(() => { + // return taskByStartDateData; + // }, [taskByStartDateData]); + + // const { + // loading: tasksByStatusLoading, + // error: tasksByStatusError, + // data: tasksByStatusData, + // } = useQuery<{ status: Status }>(GET_TASKS_BY_STATUS, { + // variables: { status: Status.ASSIGNED }, + // }); + // const tasksByStatus = React.useMemo(() => { + // return tasksByStatusData; + // }, [tasksByStatusData]); + + // const printTasks = () => { + // console.log(taskById); + // console.log(tasksByType); + // console.log(tasksByAssigneeId); + // console.log(tasksByAssignerId); + // console.log(tasksByStartDate); + // console.log(tasksByStatus); + // }; + + // const handleAddTask = async () => { + // try { + // const date = new Date(); + // // const formattedDate = date.toISOString().split("T")[0]; + + // const task: TaskRequest = { + // type: TaskTypeEnum.REQUIRED, + // title: "test task", + // description: "blah blah", + // creditValue: 5, + // locationId: 1234, + // endDate: date, + // recurrenceFrequency: RecurrenceFrequency.ONE_TIME, + // specificDay: DaysOfWeek.MONDAY, + // }; + // await createTask({ variables: { task } }); + // } catch (e) { + // console.log(e); + // } + // }; + + // const handleUpdateTask = async () => { + // try { + // const taskId = 1; + // const task: TaskRequest = { + // type: TaskTypeEnum.REQUIRED, + // title: "update name", + // description: "blah blah", + // creditValue: 7, + // locationId: 1234, + // recurrenceFrequency: RecurrenceFrequency.ONE_TIME, + // }; + // await updateTask({ variables: { taskId, task } }); + // } catch (e) { + // console.log(e); + // } + // }; + + // const handleDeleteTask = async () => { + // try { + // const taskId = 2; + // await deleteTask({ variables: { taskId } }); + // } catch (e) { + // console.log(e); + // } + // }; + + // const handleAssignTask = async () => { + // try { + // const task: TaskAssignedRequest = { + // taskId: 1, + // assigneeId: 4, + // assignerId: 6, + // status: Status.PENDING_APPROVAL, + // startDate: new Date(), + // comments: "asdlkasd", + // }; + + // await assignTask({ variables: { taskAssigned: task } }); + // } catch (e) { + // console.log(e); + // } + // }; + + // const handleChangeTaskStatus = async () => { + // try { + // const taskAssignedId = 1; + // const status = Status.ASSIGNED; + // await changeTaskStatus({ variables: { taskAssignedId, status } }); + // } catch (e) { + // console.log(e); + // } + // }; + useEffect(() => { // TODO: Fetch the task data from the API instead of using mock data setRequiredTasks(requiredTasks); @@ -89,39 +286,39 @@ const TasksPage = (): React.ReactElement => { }, [taskType]); return ( - - - - { - setTaskType("REQUIRED"); - }} - > - Required - - { - setTaskType("OPTIONAL"); - }} - > - Optional - - { - setTaskType("CUSTOM"); - }} - > - Custom - - { - setTaskType("CHORE"); - }} - > - Chores - - - + + + + { + setTaskType("REQUIRED"); + }} + > + Required + + { + setTaskType("OPTIONAL"); + }} + > + Optional + + { + setTaskType("CUSTOM"); + }} + > + Custom + + { + setTaskType("CHORE"); + }} + > + Chores + + +