Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions src/models/cart.model.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
import { type Product } from "./product.model";
import { type User } from "./user.model";

export interface CartItem {
id: number;
import type {
Cart as PrismaCart,
CartItem as PrismaCartItem,
} from "generated/prisma/client";

export type CartItem = PrismaCartItem & {
product: Pick<
Product,
"id" | "title" | "imgSrc" | "alt" | "price" | "isOnSale"
>;
quantity: number;
createdAt: string;
updatedAt: string;
}
};

export interface Cart {
id: number;
userId: User["id"] | null;
sessionCartId: string;
items: CartItem[];
createdAt: string;
updatedAt: string;
}
export type Cart = PrismaCart;

export interface CartItemInput {
productId: Product["id"];
Expand All @@ -28,3 +21,21 @@ export interface CartItemInput {
price: Product["price"];
imgSrc: Product["imgSrc"];
}

// Tipo para representar un producto simplificado en el carrito

export type CartProductInfo = Pick<
Product,
"id" | "title" | "imgSrc" | "alt" | "price" | "isOnSale"
>;

// Tipo para representar un item de carrito con su producto
export type CartItemWithProduct = {
product: CartProductInfo;
quantity: number;
};

// Tipo para el carrito con items y productos incluidos
export type CartWithItems = Cart & {
items: CartItem[];
};
17 changes: 0 additions & 17 deletions src/models/product.model.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
// import { type Category } from "./category.model";

import type { Product as PrismaProduct } from "generated/prisma/client";

// export interface Product {
// id: number;
// title: string;
// imgSrc: string;
// alt: string | null;
// price: number;
// description: string | null;
// categoryId: number;
// // categorySlug: Category["slug"];
// isOnSale: boolean;
// features: string[];
// createdAt: string;
// updatedAt: string;
// }

export type Product = Omit<PrismaProduct, "price"> & {
price: number;
};
224 changes: 0 additions & 224 deletions src/repositories/cart.repository.ts

This file was deleted.

4 changes: 2 additions & 2 deletions src/routes/root/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
Separator,
} from "@/components/ui";
import { getCart } from "@/lib/cart";
import type { Cart } from "@/models/cart.model";
import type { CartWithItems } from "@/models/cart.model";
import { getCurrentUser } from "@/services/auth.service";
import { createRemoteItems } from "@/services/cart.service";
import { commitSession, getSession } from "@/session.server";
Expand Down Expand Up @@ -45,7 +45,7 @@ export async function action({ request }: Route.ActionArgs) {
export async function loader({ request }: Route.LoaderArgs) {
const session = await getSession(request.headers.get("Cookie"));
const sessionCartId = session.get("sessionCartId");
let cart: Cart | null = null;
let cart: CartWithItems | null = null;

// Obtenemos el usuario actual (autenticado o no)
const user = await getCurrentUser(request);
Expand Down
Loading