19 lines
657 B
TypeScript
19 lines
657 B
TypeScript
|
|
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;
|
||
|
|
});
|
||
|
|
};
|