32 lines
1.0 KiB
TypeScript
32 lines
1.0 KiB
TypeScript
import { axios } from "@/api/index";
|
|
import { Edition } from "@/data/edition";
|
|
import { prepare } from "@/routing";
|
|
import { EditionDTO, editionDtoTransformer, editionTeaserDtoTransformer } from "@/api/dto/edition";
|
|
|
|
const EDITIONS_ENDPOINT = "/editions";
|
|
const EDITION_INFO_ENDPOINT = "/editions/:key";
|
|
const REGISTER_ENDPOINT = "/register";
|
|
|
|
export async function available() {
|
|
const response = await axios.get(EDITIONS_ENDPOINT);
|
|
|
|
return (response.data || []).map(editionTeaserDtoTransformer.transform);
|
|
}
|
|
|
|
export async function join(key: string): Promise<boolean> {
|
|
try {
|
|
await axios.post(REGISTER_ENDPOINT, JSON.stringify(key), { headers: { "Content-Type": "application/json" } });
|
|
return true;
|
|
} catch (error) {
|
|
console.error(error);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export async function get(key: string): Promise<Edition | null> {
|
|
const response = await axios.get<EditionDTO>(prepare(EDITION_INFO_ENDPOINT, { key }));
|
|
const dto = response.data;
|
|
|
|
return editionDtoTransformer.transform(dto);
|
|
}
|