Skip to content

Commit

Permalink
Update api per code review comments from James.
Browse files Browse the repository at this point in the history
  • Loading branch information
srpiatt committed Feb 28, 2024
1 parent 3e4e4c8 commit ada1c65
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
26 changes: 9 additions & 17 deletions src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,13 @@ import { browser } from '$app/environment';
// TODO: fix any types
/* eslint-disable @typescript-eslint/no-explicit-any */

let token = '';
if (browser) {
token = sessionStorage.getItem('token') || '';
}

async function send({
method,
path,
token,
data
}: {
method: string;
path: string;
token: string;
data?: any; //TODO: Change this
}) {
const opts: { method: string; headers: { [key: string]: string }; body?: string } = {
Expand All @@ -30,12 +23,11 @@ async function send({
opts.body = JSON.stringify(data);
}

if (sessionStorage.token) {
token = sessionStorage.token;
}

if (token) {
opts.headers['Authorization'] = `Token ${token}`;
if (browser) {
const token = sessionStorage.getItem('token');
if (token) {
opts.headers['Authorization'] = `Token ${token}`;
}
}

console.debug('fetching', `${window.location.origin}/${path}`, opts);
Expand All @@ -54,17 +46,17 @@ async function send({
}

export function get(path: string) {
return send({ method: 'GET', path, token });
return send({ method: 'GET', path });
}

export function del(path: string) {
return send({ method: 'DELETE', path, token });
return send({ method: 'DELETE', path });
}

export function post(path: string, data: any) {
return send({ method: 'POST', path, token, data });
return send({ method: 'POST', path, data });
}

export function put(path: string, data: any) {
return send({ method: 'PUT', path, token, data });
return send({ method: 'PUT', path, data });
}
1 change: 0 additions & 1 deletion tests/routes/dataset/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ test.describe('dataset', () => {
);
await page.goto('/dataset');


// Then
await expect(page.getByText('Active Datasets', { exact: true })).toBeVisible();
await expect(page.getByText(mockData[0].query.uuid, { exact: true })).toBeVisible();
Expand Down

0 comments on commit ada1c65

Please sign in to comment.