Files
dmenu-plus-front/src/app/[name]/(Main)/cart/lib/cartUtils.ts
T
hamid zarghami 194533ec5f
Build and Deploy Docker Images / build_and_deploy (push) Has been cancelled
fast navigate + cache
2026-06-03 15:08:09 +03:30

37 lines
1005 B
TypeScript

import type { CartItem } from '../types/Types';
import type { Food } from '@/app/[name]/(Main)/types/Types';
export function cartItemToFood(item: CartItem): Food {
return {
id: item.foodId,
category: '',
title: item.foodTitle,
desc: '',
content: [],
price: item.price,
prepareTime: 0,
isActive: true,
images: [],
inPlaceServe: true,
pickupServe: true,
discount: item.discount,
isSpecialOffer: false,
};
}
export function guestCartItemsToFoods(
items: Record<string | number, { quantity: number }>,
foods: Food[]
): Food[] {
return Object.entries(items)
.filter(([, detail]) => detail?.quantity && detail.quantity > 0)
.map(([id]) => foods.find((food) => String(food.id) === String(id)))
.filter((food): food is Food => Boolean(food));
}
export function hasCartEntries(
items: Record<string | number, { quantity: number }>
): boolean {
return Object.values(items).some((detail) => detail?.quantity && detail.quantity > 0);
}