From 90506ed51c1c4e4a27ec4a8a982682219bbe5989 Mon Sep 17 00:00:00 2001 From: Brandon Farmer Date: Tue, 20 Nov 2018 13:57:25 -0800 Subject: [PATCH] Move delete and get by id tasks to generated client --- ui/src/tasks/actions/v2/index.ts | 18 ++++-------------- ui/src/tasks/api/v2/index.ts | 21 +++++++++------------ 2 files changed, 13 insertions(+), 26 deletions(-) diff --git a/ui/src/tasks/actions/v2/index.ts b/ui/src/tasks/actions/v2/index.ts index d1b6a48d32..20c148a9dc 100644 --- a/ui/src/tasks/actions/v2/index.ts +++ b/ui/src/tasks/actions/v2/index.ts @@ -196,16 +196,9 @@ export const updateTaskStatus = (task: Task) => async dispatch => { } } -export const deleteTask = (task: Task) => async ( - dispatch, - getState: GetStateFunc -) => { +export const deleteTask = (task: Task) => async dispatch => { try { - const { - links: {tasks: url}, - } = getState() - - await deleteTaskAPI(url, task.id) + await deleteTaskAPI(task.id) dispatch(populateTasks()) } catch (e) { @@ -248,12 +241,9 @@ export const selectTaskByID = (id: string) => async ( getState: GetStateFunc ): Promise => { try { - const { - orgs, - links: {tasks: url}, - } = getState() + const {orgs} = getState() - const task = await getTask(url, id) + const task = await getTask(id) const org = orgs.find(org => org.id === task.organizationId) return dispatch(setCurrentTask({...task, organization: org})) diff --git a/ui/src/tasks/api/v2/index.ts b/ui/src/tasks/api/v2/index.ts index 87e8d5e5bc..b0d7082229 100644 --- a/ui/src/tasks/api/v2/index.ts +++ b/ui/src/tasks/api/v2/index.ts @@ -1,5 +1,3 @@ -import AJAX from 'src/utils/ajax' - import {Task, TasksApi} from 'src/api' const getBasePath = () => { @@ -43,22 +41,21 @@ export const updateTaskStatus = async ( export const getUserTasks = async (user): Promise => { const api = createTaskAPI() - const {data} = await api.tasksGet('', user.id) + const after = '' + const {data} = await api.tasksGet(after, user.id) return data.tasks } -export const getTask = async (url, id): Promise => { - const completeUrl = `${url}/${id}` - const { - data: {task}, - } = await AJAX({url: completeUrl}) +export const getTask = async (id): Promise => { + const api = createTaskAPI() + const {data} = await api.tasksTaskIDGet(id) - return task + return data } -export const deleteTask = (url: string, taskID: string) => { - const completeUrl = `${url}/${taskID}` +export const deleteTask = (taskID: string) => { + const api = createTaskAPI() - return AJAX({url: completeUrl, method: 'DELETE'}) + return api.tasksTaskIDDelete(taskID) }