Skip to content

Commit

Permalink
update task resposne type
Browse files Browse the repository at this point in the history
  • Loading branch information
SAINIAbhishek committed Oct 17, 2024
1 parent f28a5da commit b656338
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 35 deletions.
17 changes: 10 additions & 7 deletions frontend/src/api/task.api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { protectedRequest } from '@/lib/axios';
import {
TaskDeleteResponse,
TaskResponse,
TasksResponse,
TaskType,
UpdateCompletedTaskType,
UpdateImportantTaskType,
Expand All @@ -12,7 +15,7 @@ export const API_TASK_UPDATE = async (data: UpdateTaskType) => {
TaskType,
'title' | 'description' | 'completed' | 'important' | 'date'
>,
ApiResponse
TaskResponse
>({
url: `/tasks/${data.taskId}`,
method: 'PUT',
Expand All @@ -23,7 +26,7 @@ export const API_TASK_UPDATE = async (data: UpdateTaskType) => {
export const API_TASK_TOGGLE_IMPORTANT = async (
data: UpdateImportantTaskType,
) => {
return await protectedRequest<Pick<TaskType, 'important'>, ApiResponse>({
return await protectedRequest<Pick<TaskType, 'important'>, TaskResponse>({
url: `/tasks/${data.taskId}`,
method: 'PUT',
data: { important: data.important },
Expand All @@ -33,37 +36,37 @@ export const API_TASK_TOGGLE_IMPORTANT = async (
export const API_TASK_TOGGLE_COMPLETED = async (
data: UpdateCompletedTaskType,
) => {
return await protectedRequest<Pick<TaskType, 'completed'>, ApiResponse>({
return await protectedRequest<Pick<TaskType, 'completed'>, TaskResponse>({
url: `/tasks/${data.taskId}`,
method: 'PUT',
data: { completed: data.completed },
});
};

export const API_GET_TASK = async (taskId: string) => {
return await protectedRequest<null, ApiResponse>({
return await protectedRequest<null, TaskResponse>({
url: `/tasks/${taskId}`,
method: 'GET',
});
};

export const API_DELETE_TASK = async (taskId: string) => {
return await protectedRequest<null, ApiResponse>({
return await protectedRequest<null, TaskDeleteResponse>({
url: `/tasks/${taskId}`,
method: 'DELETE',
});
};

export const API_CREATE_TASK = async (data: TaskType) => {
return await protectedRequest<TaskType, ApiResponse>({
return await protectedRequest<TaskType, TaskResponse>({
url: `/tasks`,
method: 'POST',
data,
});
};

export const API_GET_TASKS = async (filter?: string) => {
return await protectedRequest<null, ApiResponse>({
return await protectedRequest<null, TasksResponse>({
url: `/tasks${filter ? `?filter=${filter}` : ''}`,
method: 'GET',
});
Expand Down
13 changes: 13 additions & 0 deletions frontend/src/features/tasks/types/task.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@ export type UpdateCompletedTaskType = UpdateTaskBaseType & {
};

export type UpdateTaskType = UpdateTaskBaseType & TaskBaseType;

export type TaskResponse = {
task: TaskType;
};

export type TasksResponse = {
tasks: TaskType[];
total: number;
};

export type TaskDeleteResponse = {
taskId: string;
};
11 changes: 0 additions & 11 deletions frontend/src/types/api-response.d.ts

This file was deleted.

6 changes: 0 additions & 6 deletions frontend/src/types/error.d.ts

This file was deleted.

11 changes: 0 additions & 11 deletions frontend/src/types/task.d.ts

This file was deleted.

0 comments on commit b656338

Please sign in to comment.