diff --git a/src/lib/api/addTask.ts b/src/lib/api/addTask.ts index 7b8c31be..70828185 100644 --- a/src/lib/api/addTask.ts +++ b/src/lib/api/addTask.ts @@ -1,4 +1,4 @@ -import apiFetch from './fetch2'; +import fetch2 from './fetch2'; // Requires that user be authenticated. export async function addTask( @@ -7,7 +7,7 @@ export async function addTask( cents: number, recurrence?: Record ): Promise { - const response = await apiFetch('me/tasks', true, 'POST', { + const response = await fetch2('me/tasks', true, 'POST', { task, due, cents, diff --git a/src/lib/api/editTask.ts b/src/lib/api/editTask.ts index 2ce85157..625a551d 100644 --- a/src/lib/api/editTask.ts +++ b/src/lib/api/editTask.ts @@ -1,4 +1,4 @@ -import apiFetch from './fetch1'; +import fetch1 from './fetch1'; // Requires that user be authenticated. export async function editTask( @@ -6,7 +6,7 @@ export async function editTask( due: string, cents: number ): Promise { - const response = await apiFetch(`me/tasks/${id}`, true, 'PUT', { + const response = await fetch1(`me/tasks/${id}`, true, 'PUT', { due, cents, }); diff --git a/src/lib/api/fetch1.spec.ts b/src/lib/api/fetch1.spec.ts index 6574561f..fdffde95 100644 --- a/src/lib/api/fetch1.spec.ts +++ b/src/lib/api/fetch1.spec.ts @@ -1,11 +1,11 @@ -import apiFetch from './fetch1'; +import fetch1 from './fetch1'; import { expect, it, describe, vi } from 'vitest'; vi.mock('./fetch1', () => { return vi.importActual('./fetch1'); }); -describe('apiFetch', () => { +describe('fetch1', () => { it('uses localStorage token', async () => { fetchMock.mockResponse(JSON.stringify({})); @@ -14,7 +14,7 @@ describe('apiFetch', () => { global.localStorage.setItem('token', token); const url = 'https://example.com'; - await apiFetch(url); + await fetch1(url); expect(fetch).toHaveBeenCalledWith( expect.anything(), diff --git a/src/lib/api/getCheckoutSession.ts b/src/lib/api/getCheckoutSession.ts index 3847ebd6..aab63e2f 100644 --- a/src/lib/api/getCheckoutSession.ts +++ b/src/lib/api/getCheckoutSession.ts @@ -1,7 +1,7 @@ -import apiFetch from './fetch1'; +import fetch1 from './fetch1'; export async function getCheckoutSession(): Promise { - const response = await apiFetch('payments/checkout/session'); + const response = await fetch1('payments/checkout/session'); return response.json() as Promise; } diff --git a/src/lib/api/getMe.ts b/src/lib/api/getMe.ts index 9dd9de74..87e79a39 100644 --- a/src/lib/api/getMe.ts +++ b/src/lib/api/getMe.ts @@ -1,7 +1,7 @@ -import apiFetch from './fetch1'; +import fetch1 from './fetch1'; export async function getMe(): Promise { - const response = await apiFetch('me', true); + const response = await fetch1('me', true); if (!response.ok) { throw new Error('Failed to get me'); diff --git a/src/lib/api/getTasks.ts b/src/lib/api/getTasks.ts index 4bb2f35f..98e91b24 100644 --- a/src/lib/api/getTasks.ts +++ b/src/lib/api/getTasks.ts @@ -1,7 +1,7 @@ -import apiFetch from './fetch1'; +import fetch1 from './fetch1'; export async function getTasks(): Promise { - const response = await apiFetch('me/tasks', true); + const response = await fetch1('me/tasks', true); return response.json(); } diff --git a/src/lib/api/getTimezones.ts b/src/lib/api/getTimezones.ts index d6906e37..aa07cf7d 100644 --- a/src/lib/api/getTimezones.ts +++ b/src/lib/api/getTimezones.ts @@ -1,7 +1,7 @@ -import apiFetch from './fetch1'; +import fetch1 from './fetch1'; export async function getTimezones(): Promise { - const response = await apiFetch('timezones'); + const response = await fetch1('timezones'); return response.json() as Promise; } diff --git a/src/lib/api/register.ts b/src/lib/api/register.ts index bd20111c..6291cce2 100644 --- a/src/lib/api/register.ts +++ b/src/lib/api/register.ts @@ -1,4 +1,4 @@ -import apiFetch from './fetch1'; +import fetch1 from './fetch1'; export default function register( name: string, @@ -7,7 +7,7 @@ export default function register( timezone: string, checkoutSessionId: string | null ): Promise { - return apiFetch('account/register', false, 'POST', { + return fetch1('account/register', false, 'POST', { name: name, email: email, password: password, diff --git a/src/lib/api/updatePassword.ts b/src/lib/api/updatePassword.ts index 91a67072..de38f41e 100644 --- a/src/lib/api/updatePassword.ts +++ b/src/lib/api/updatePassword.ts @@ -1,10 +1,10 @@ -import apiFetch from './fetch1'; +import fetch1 from './fetch1'; export function updatePassword( oldPassword: string, newPassword: string ): Promise { - return apiFetch('me', true, 'PUT', { + return fetch1('me', true, 'PUT', { old_password: oldPassword, new_password: newPassword, }); diff --git a/src/lib/api/updateTask.ts b/src/lib/api/updateTask.ts index 9641d76d..c75efc81 100644 --- a/src/lib/api/updateTask.ts +++ b/src/lib/api/updateTask.ts @@ -1,4 +1,4 @@ -import apiFetch from './fetch1'; +import fetch1 from './fetch1'; export interface TaskInput { complete?: boolean; @@ -7,5 +7,5 @@ export interface TaskInput { // Requires that user be authenticated. export function updateTask(taskId: string, data: TaskInput): Promise { - return apiFetch('me/tasks/' + taskId, true, 'PUT', data); + return fetch1('me/tasks/' + taskId, true, 'PUT', data); } diff --git a/src/lib/api/useGetApiToken.ts b/src/lib/api/useGetApiToken.ts index fd3050bd..77940c4d 100644 --- a/src/lib/api/useGetApiToken.ts +++ b/src/lib/api/useGetApiToken.ts @@ -1,5 +1,5 @@ import { useMutation } from 'react-query'; -import apiFetch from './fetch1'; +import fetch1 from './fetch1'; import { UseMutationResult } from 'react-query'; export function useGetApiToken(): UseMutationResult< @@ -9,7 +9,7 @@ export function useGetApiToken(): UseMutationResult< unknown > { return useMutation('api-token', async () => { - const response = await apiFetch('me/token', true, 'GET'); + const response = await fetch1('me/token', true, 'GET'); return response.text(); }); }