27 lines
499 B
TypeScript
27 lines
499 B
TypeScript
import fetcher from './fetcher';
|
|
|
|
export const getGroups = async ({ token }: { token: string }): Promise<Group[]> => {
|
|
const { data, status } = await fetcher.get(`/groups`, {
|
|
headers: {
|
|
Authorization: `Bearer ${token}`
|
|
}
|
|
});
|
|
|
|
const groups = data;
|
|
|
|
if (status !== 200) {
|
|
throw new Error('Failed to fetch groups');
|
|
}
|
|
|
|
if (!groups) {
|
|
return [] as Group[];
|
|
}
|
|
|
|
return groups as Group[];
|
|
};
|
|
|
|
export type Group = {
|
|
id: number;
|
|
name: string;
|
|
chapter?: number;
|
|
};
|