dishplanner/frontend/app/utils/api/userDishApi.ts

19 lines
657 B
TypeScript
Raw Normal View History

2025-10-13 14:57:11 +02:00
import { apiRequest } from "@/utils/api/apiRequest";
import { UserDishType } from "@/types/ScheduledUserDishType";
export const listUserDishes = async (): Promise<UserDishType[]> => {
const token = localStorage.getItem('token');
if (!token) throw new Error('No token found in localStorage.');
return apiRequest.get(`/api/user-dishes`, { headers: { Authorization: `Bearer ${ token }` } })
.then((data) => {
if (data?.payload?.user_dishes) return data.payload.user_dishes as UserDishType[];
throw new Error('SOMETHING WENT WRONG');
})
.catch((error) => {
throw error;
});
};