20 lines
622 B
TypeScript
20 lines
622 B
TypeScript
import axios from "axios";
|
|
import type { GetRecipeOfTheWeekResponse } from "../types/api/recipe";
|
|
import type { Recipe } from "../types/recipe";
|
|
import type { ApiError } from "../types/api/error";
|
|
|
|
|
|
export async function GetRecipeOfTheWeek (): Promise<Recipe | ApiError> {
|
|
const response = await axios.get<GetRecipeOfTheWeekResponse>("http://localhost:3000/v2/api/recipe/of-the-week");
|
|
|
|
if (response.status !== 200 || response.data.recipe === undefined) {
|
|
const err: ApiError = {
|
|
status: response.data.status,
|
|
message: response.data.message
|
|
};
|
|
return err;
|
|
}
|
|
|
|
return response.data.recipe;
|
|
}
|