2022-04-07 22:54:15 +00:00
|
|
|
import { Channel } from "../types/channel";
|
2022-04-17 00:49:20 +00:00
|
|
|
import { getTAUrl } from "./constants";
|
|
|
|
|
|
|
|
const TA_BASE_URL = getTAUrl();
|
2022-04-07 22:54:15 +00:00
|
|
|
|
2022-04-13 18:08:32 +00:00
|
|
|
export const getChannels = async (token: string): Promise<Channel> => {
|
2022-04-17 00:49:20 +00:00
|
|
|
if (!token) {
|
|
|
|
throw new Error(`Unable to fetch channels, no token provided`);
|
|
|
|
}
|
|
|
|
|
|
|
|
const response = await fetch(`${TA_BASE_URL.server}/api/channel/`, {
|
2022-04-13 20:53:39 +00:00
|
|
|
headers: {
|
|
|
|
Accept: "application/json",
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
Authorization: `Token ${token}`,
|
|
|
|
mode: "no-cors",
|
|
|
|
},
|
|
|
|
});
|
2022-04-13 18:08:32 +00:00
|
|
|
if (!response.ok) {
|
|
|
|
throw new Error("Error getting channel information");
|
|
|
|
}
|
|
|
|
return response.json();
|
2022-04-07 22:54:15 +00:00
|
|
|
};
|