File tree Expand file tree Collapse file tree 8 files changed +282
-331
lines changed Expand file tree Collapse file tree 8 files changed +282
-331
lines changed Original file line number Diff line number Diff line change 11import { type Product } from "./product.model" ;
2- import { type User } from "./user.model" ;
32
4- export interface CartItem {
5- id : number ;
3+ import type {
4+ Cart as PrismaCart ,
5+ CartItem as PrismaCartItem ,
6+ } from "generated/prisma/client" ;
7+
8+ export type CartItem = PrismaCartItem & {
69 product : Pick <
710 Product ,
811 "id" | "title" | "imgSrc" | "alt" | "price" | "isOnSale"
912 > ;
10- quantity : number ;
11- createdAt : string ;
12- updatedAt : string ;
13- }
13+ } ;
1414
15- export interface Cart {
16- id : number ;
17- userId : User [ "id" ] | null ;
18- sessionCartId : string ;
19- items : CartItem [ ] ;
20- createdAt : string ;
21- updatedAt : string ;
22- }
15+ export type Cart = PrismaCart ;
2316
2417export interface CartItemInput {
2518 productId : Product [ "id" ] ;
@@ -28,3 +21,21 @@ export interface CartItemInput {
2821 price : Product [ "price" ] ;
2922 imgSrc : Product [ "imgSrc" ] ;
3023}
24+
25+ // Tipo para representar un producto simplificado en el carrito
26+
27+ export type CartProductInfo = Pick <
28+ Product ,
29+ "id" | "title" | "imgSrc" | "alt" | "price" | "isOnSale"
30+ > ;
31+
32+ // Tipo para representar un item de carrito con su producto
33+ export type CartItemWithProduct = {
34+ product : CartProductInfo ;
35+ quantity : number ;
36+ } ;
37+
38+ // Tipo para el carrito con items y productos incluidos
39+ export type CartWithItems = Cart & {
40+ items : CartItem [ ] ;
41+ } ;
Original file line number Diff line number Diff line change 1- // import { type Category } from "./category.model";
2-
31import type { Product as PrismaProduct } from "generated/prisma/client" ;
42
5- // export interface Product {
6- // id: number;
7- // title: string;
8- // imgSrc: string;
9- // alt: string | null;
10- // price: number;
11- // description: string | null;
12- // categoryId: number;
13- // // categorySlug: Category["slug"];
14- // isOnSale: boolean;
15- // features: string[];
16- // createdAt: string;
17- // updatedAt: string;
18- // }
19-
203export type Product = Omit < PrismaProduct , "price" > & {
214 price : number ;
225} ;
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ import {
1717 Separator ,
1818} from "@/components/ui" ;
1919import { getCart } from "@/lib/cart" ;
20- import type { Cart } from "@/models/cart.model" ;
20+ import type { CartWithItems } from "@/models/cart.model" ;
2121import { getCurrentUser } from "@/services/auth.service" ;
2222import { createRemoteItems } from "@/services/cart.service" ;
2323import { commitSession , getSession } from "@/session.server" ;
@@ -45,7 +45,7 @@ export async function action({ request }: Route.ActionArgs) {
4545export async function loader ( { request } : Route . LoaderArgs ) {
4646 const session = await getSession ( request . headers . get ( "Cookie" ) ) ;
4747 const sessionCartId = session . get ( "sessionCartId" ) ;
48- let cart : Cart | null = null ;
48+ let cart : CartWithItems | null = null ;
4949
5050 // Obtenemos el usuario actual (autenticado o no)
5151 const user = await getCurrentUser ( request ) ;
You can’t perform that action at this time.
0 commit comments