mirror of
https://github.com/ershisan99/it-incubator-todolist-ts-17-live-2024-08-17.git
synced 2025-12-16 20:59:30 +00:00
chore: add prettier and run it on all files
This commit is contained in:
@@ -1,118 +1,140 @@
|
||||
import axios from 'axios'
|
||||
|
||||
const settings = {
|
||||
withCredentials: true,
|
||||
headers: {
|
||||
'API-KEY': '1cdd9f77-c60e-4af5-b194-659e4ebd5d41'
|
||||
}
|
||||
withCredentials: true,
|
||||
headers: {
|
||||
'API-KEY': '1cdd9f77-c60e-4af5-b194-659e4ebd5d41',
|
||||
},
|
||||
}
|
||||
const instance = axios.create({
|
||||
baseURL: 'https://social-network.samuraijs.com/api/1.1/',
|
||||
...settings
|
||||
baseURL: 'https://social-network.samuraijs.com/api/1.1/',
|
||||
...settings,
|
||||
})
|
||||
|
||||
// api
|
||||
export const todolistsAPI = {
|
||||
getTodolists() {
|
||||
const promise = instance.get<TodolistType[]>('todo-lists');
|
||||
return promise;
|
||||
},
|
||||
createTodolist(title: string) {
|
||||
const promise = instance.post<ResponseType<{ item: TodolistType }>>('todo-lists', {title: title});
|
||||
return promise;
|
||||
},
|
||||
deleteTodolist(id: string) {
|
||||
const promise = instance.delete<ResponseType>(`todo-lists/${id}`);
|
||||
return promise;
|
||||
},
|
||||
updateTodolist(id: string, title: string) {
|
||||
const promise = instance.put<ResponseType>(`todo-lists/${id}`, {title: title});
|
||||
return promise;
|
||||
},
|
||||
getTasks(todolistId: string) {
|
||||
return instance.get<GetTasksResponse>(`todo-lists/${todolistId}/tasks`);
|
||||
},
|
||||
deleteTask(todolistId: string, taskId: string) {
|
||||
return instance.delete<ResponseType>(`todo-lists/${todolistId}/tasks/${taskId}`);
|
||||
},
|
||||
createTask(todolistId: string, taskTitile: string) {
|
||||
return instance.post<ResponseType<{ item: TaskType}>>(`todo-lists/${todolistId}/tasks`, {title: taskTitile});
|
||||
},
|
||||
updateTask(todolistId: string, taskId: string, model: UpdateTaskModelType) {
|
||||
return instance.put<ResponseType<TaskType>>(`todo-lists/${todolistId}/tasks/${taskId}`, model);
|
||||
}
|
||||
getTodolists() {
|
||||
const promise = instance.get<TodolistType[]>('todo-lists')
|
||||
return promise
|
||||
},
|
||||
createTodolist(title: string) {
|
||||
const promise = instance.post<ResponseType<{ item: TodolistType }>>(
|
||||
'todo-lists',
|
||||
{ title: title }
|
||||
)
|
||||
return promise
|
||||
},
|
||||
deleteTodolist(id: string) {
|
||||
const promise = instance.delete<ResponseType>(`todo-lists/${id}`)
|
||||
return promise
|
||||
},
|
||||
updateTodolist(id: string, title: string) {
|
||||
const promise = instance.put<ResponseType>(`todo-lists/${id}`, {
|
||||
title: title,
|
||||
})
|
||||
return promise
|
||||
},
|
||||
getTasks(todolistId: string) {
|
||||
return instance.get<GetTasksResponse>(`todo-lists/${todolistId}/tasks`)
|
||||
},
|
||||
deleteTask(todolistId: string, taskId: string) {
|
||||
return instance.delete<ResponseType>(
|
||||
`todo-lists/${todolistId}/tasks/${taskId}`
|
||||
)
|
||||
},
|
||||
createTask(todolistId: string, taskTitile: string) {
|
||||
return instance.post<ResponseType<{ item: TaskType }>>(
|
||||
`todo-lists/${todolistId}/tasks`,
|
||||
{ title: taskTitile }
|
||||
)
|
||||
},
|
||||
updateTask(todolistId: string, taskId: string, model: UpdateTaskModelType) {
|
||||
return instance.put<ResponseType<TaskType>>(
|
||||
`todo-lists/${todolistId}/tasks/${taskId}`,
|
||||
model
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
export type LoginParamsType = {
|
||||
email: string
|
||||
password: string
|
||||
rememberMe: boolean
|
||||
captcha?: string
|
||||
email: string
|
||||
password: string
|
||||
rememberMe: boolean
|
||||
captcha?: string
|
||||
}
|
||||
|
||||
export const authAPI = {
|
||||
login(data: LoginParamsType) {
|
||||
const promise = instance.post<ResponseType<{userId?: number}>>('auth/login', data);
|
||||
return promise;
|
||||
},
|
||||
logout() {
|
||||
const promise = instance.delete<ResponseType<{userId?: number}>>('auth/login');
|
||||
return promise;
|
||||
},
|
||||
me() {
|
||||
const promise = instance.get<ResponseType<{id: number; email: string; login: string}>>('auth/me');
|
||||
return promise
|
||||
}
|
||||
login(data: LoginParamsType) {
|
||||
const promise = instance.post<ResponseType<{ userId?: number }>>(
|
||||
'auth/login',
|
||||
data
|
||||
)
|
||||
return promise
|
||||
},
|
||||
logout() {
|
||||
const promise =
|
||||
instance.delete<ResponseType<{ userId?: number }>>('auth/login')
|
||||
return promise
|
||||
},
|
||||
me() {
|
||||
const promise =
|
||||
instance.get<ResponseType<{ id: number; email: string; login: string }>>(
|
||||
'auth/me'
|
||||
)
|
||||
return promise
|
||||
},
|
||||
}
|
||||
|
||||
// types
|
||||
export type TodolistType = {
|
||||
id: string
|
||||
title: string
|
||||
addedDate: string
|
||||
order: number
|
||||
id: string
|
||||
title: string
|
||||
addedDate: string
|
||||
order: number
|
||||
}
|
||||
export type ResponseType<D = {}> = {
|
||||
resultCode: number
|
||||
messages: Array<string>
|
||||
data: D
|
||||
resultCode: number
|
||||
messages: Array<string>
|
||||
data: D
|
||||
}
|
||||
|
||||
export enum TaskStatuses {
|
||||
New = 0,
|
||||
InProgress = 1,
|
||||
Completed = 2,
|
||||
Draft = 3
|
||||
New = 0,
|
||||
InProgress = 1,
|
||||
Completed = 2,
|
||||
Draft = 3,
|
||||
}
|
||||
|
||||
export enum TaskPriorities {
|
||||
Low = 0,
|
||||
Middle = 1,
|
||||
Hi = 2,
|
||||
Urgently = 3,
|
||||
Later = 4
|
||||
Low = 0,
|
||||
Middle = 1,
|
||||
Hi = 2,
|
||||
Urgently = 3,
|
||||
Later = 4,
|
||||
}
|
||||
|
||||
export type TaskType = {
|
||||
description: string
|
||||
title: string
|
||||
status: TaskStatuses
|
||||
priority: TaskPriorities
|
||||
startDate: string
|
||||
deadline: string
|
||||
id: string
|
||||
todoListId: string
|
||||
order: number
|
||||
addedDate: string
|
||||
description: string
|
||||
title: string
|
||||
status: TaskStatuses
|
||||
priority: TaskPriorities
|
||||
startDate: string
|
||||
deadline: string
|
||||
id: string
|
||||
todoListId: string
|
||||
order: number
|
||||
addedDate: string
|
||||
}
|
||||
export type UpdateTaskModelType = {
|
||||
title: string
|
||||
description: string
|
||||
status: TaskStatuses
|
||||
priority: TaskPriorities
|
||||
startDate: string
|
||||
deadline: string
|
||||
title: string
|
||||
description: string
|
||||
status: TaskStatuses
|
||||
priority: TaskPriorities
|
||||
startDate: string
|
||||
deadline: string
|
||||
}
|
||||
type GetTasksResponse = {
|
||||
error: string | null
|
||||
totalCount: number
|
||||
items: TaskType[]
|
||||
error: string | null
|
||||
totalCount: number
|
||||
items: TaskType[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user