Skip to content
Snippets Groups Projects
Commit fd1a466a authored by Bernard Roland (Student Com20)'s avatar Bernard Roland (Student Com20)
Browse files

Implement part of the team adapter

parent 4b1ad06a
No related branches found
No related tags found
No related merge requests found
import { apiRoot } from 'config';
import { getAuthHeader } from './auth';
import { User } from './user';
import { Project } from './project';
import { Work } from './work';
export interface Team { export interface Team {
id: string; id: string;
name: string; name: string;
role?: string; role?: string;
} }
export interface TeamRole {
id: string;
name: string;
}
export interface TeamMember extends User {
role: TeamRole;
}
type TeamProject = Exclude<Project, 'teams'>;
export async function getTeams(): Promise<Team[]> {
try {
const response = await fetch(`${apiRoot}/team/`, { headers: getAuthHeader() });
if (response.ok) {
return (await response.json()).teams;
} else {
throw new Error("Failed to get teams");
}
} catch (e) {
throw e;
}
}
export async function getTeam(uuid: string): Promise<Team> {
try {
const response = await fetch(`${apiRoot}/team/${uuid}`, { headers: getAuthHeader() });
if (response.ok) {
return (await response.json()).team;
} else {
throw new Error("Failed to get team");
}
} catch (e) {
throw e;
}
}
export async function getTeamMembers(uuid: string): Promise<TeamMember[]> {
try {
const response = await fetch(`${apiRoot}/team/${uuid}/members`, { headers: getAuthHeader() });
if (response.ok) {
return (await response.json()).members;
} else {
throw new Error("Failed to get team members");
}
} catch (e) {
throw e;
}
}
export async function getTeamRoles(uuid: string): Promise<TeamRole[]> {
try {
const response = await fetch(`${apiRoot}/team/${uuid}/roles`, { headers: getAuthHeader() });
if (response.ok) {
return (await response.json()).roles;
} else {
throw new Error("Failed to get team roles");
}
} catch (e) {
throw e;
}
}
export async function getTeamProjects(uuid: string): Promise<TeamProject[]> {
try {
const response = await fetch(`${apiRoot}/team/${uuid}/projects`, { headers: getAuthHeader() });
if (response.ok) {
return (await response.json()).projects;
} else {
throw new Error("Failed to get team projects");
}
} catch (e) {
throw e;
}
}
export async function getTeamWork(uuid: string): Promise<Work[]> {
try {
const response = await fetch(`${apiRoot}/team/${uuid}/work`, { headers: getAuthHeader() });
if (response.ok) {
return (await response.json()).work;
} else {
throw new Error("Failed to get team work");
}
} catch (e) {
throw e;
}
}
...@@ -5,6 +5,13 @@ import { getAuthHeader } from './auth'; ...@@ -5,6 +5,13 @@ import { getAuthHeader } from './auth';
import { Task } from './task'; import { Task } from './task';
import { Work } from './work'; import { Work } from './work';
export interface User {
id: string;
username: string;
realname?: string;
email?: string;
}
export async function exists(username: string) { export async function exists(username: string) {
try { try {
const response = await fetch(`${apiRoot}/user/name/${username}`); const response = await fetch(`${apiRoot}/user/name/${username}`);
...@@ -15,13 +22,6 @@ export async function exists(username: string) { ...@@ -15,13 +22,6 @@ export async function exists(username: string) {
} }
} }
export interface User {
id: string;
username: string;
realname?: string;
email?: string;
}
export async function getCurrentUser(): Promise<User> { export async function getCurrentUser(): Promise<User> {
try { try {
const response = await fetch(`${apiRoot}/user/`, { headers: getAuthHeader() }); const response = await fetch(`${apiRoot}/user/`, { headers: getAuthHeader() });
...@@ -35,7 +35,7 @@ export async function getCurrentUser(): Promise<User> { ...@@ -35,7 +35,7 @@ export async function getCurrentUser(): Promise<User> {
} }
} }
export async function getTasks(): Promise<Array<Task>> { export async function getUserTasks(): Promise<Array<Task>> {
try { try {
const response = await fetch(`${apiRoot}/user/tasks`, { headers: getAuthHeader() }); const response = await fetch(`${apiRoot}/user/tasks`, { headers: getAuthHeader() });
if (response.ok) { if (response.ok) {
...@@ -52,7 +52,7 @@ export async function getTasks(): Promise<Array<Task>> { ...@@ -52,7 +52,7 @@ export async function getTasks(): Promise<Array<Task>> {
} }
} }
export async function getWork(): Promise<Work> { export async function getUserWork(): Promise<Work> {
try { try {
const response = await fetch(`${apiRoot}/user/work`, { headers: getAuthHeader() }); const response = await fetch(`${apiRoot}/user/work`, { headers: getAuthHeader() });
if (response.ok) { if (response.ok) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment