Skip to content

Commit 0200e5a

Browse files
authored
Merge pull request #269 from codeableorg/branch-Jeff5
Branch jeff5
2 parents 3689831 + e4938aa commit 0200e5a

File tree

27 files changed

+938
-250
lines changed

27 files changed

+938
-250
lines changed

.react-router/types/+register.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ type Params = {
2929
"/account/orders": {};
3030
"/not-found": {};
3131
"/verify-email": {};
32+
"/chat": {};
3233
};

api/gemini-chat.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import express from "express";
2+
import { GoogleGenAI } from "@google/genai";
3+
4+
const router = express.Router();
5+
const ai = new GoogleGenAI({ apiKey: process.env.GOOGLE_API_KEY || "" });
6+
7+
router.post("/", async (req, res) => {
8+
const { message } = req.body;
9+
try {
10+
const chat = ai.chats.create({ model: "gemini-2.5-flash", history: [] });
11+
const response = await chat.sendMessage({ message });
12+
res.json({ text: response.text });
13+
} catch (err) {
14+
res.status(500).json({ error: "Error al contactar a Gemini" });
15+
}
16+
});
17+
18+
export default router;

api/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import express from "express";
2+
import cors from "cors";
3+
import geminiChatRouter from "./gemini-chat.js";
4+
5+
const app = express();
6+
app.use(express.json());
7+
app.use("/api/gemini-chat", geminiChatRouter);
8+
app.use(cors());
9+
10+
app.listen(3001, () => {
11+
console.log("API server listening on http://localhost:3001");
12+
});

prisma/initial_data.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,30 @@ export const categories = [
2929
},
3030
];
3131

32+
export const productVariant = [
33+
// Ejemplo para un producto Polo
34+
{ productTitle: "Polo React", sizes: ["small", "medium", "large"] },
35+
{ productTitle: "Polo JavaScript", sizes: ["small", "medium", "large"] },
36+
{ productTitle: "Polo Node.js", sizes: ["small", "medium", "large"] },
37+
{ productTitle: "Polo TypeScript", sizes: ["small", "medium", "large"] },
38+
{ productTitle: "Polo Backend Developer", sizes: ["small", "medium", "large"] },
39+
{ productTitle: "Polo Frontend Developer", sizes: ["small", "medium", "large"] },
40+
{ productTitle: "Polo Full-Stack Developer", sizes: ["small", "medium", "large"] },
41+
{ productTitle: "Polo It's A Feature", sizes: ["small", "medium", "large"] },
42+
{ productTitle: "Polo It Works On My Machine", sizes: ["small", "medium", "large"] },
43+
];
44+
45+
export const stickersVariant = [
46+
{ productTitle: "Sticker JavaScript", measure: ["3*3", "5*5", "10*10"] },
47+
{ productTitle: "Sticker React", measure: ["3*3", "5*5", "10*10"] },
48+
{ productTitle: "Sticker Git", measure: ["3*3", "5*5", "10*10"] },
49+
{ productTitle: "Sticker Docker", measure: ["3*3", "5*5", "10*10"] },
50+
{ productTitle: "Sticker Linux", measure: ["3*3", "5*5", "10*10"] },
51+
{ productTitle: "Sticker VS Code", measure: ["3*3", "5*5", "10*10"] },
52+
{ productTitle: "Sticker GitHub", measure: ["3*3", "5*5", "10*10"] },
53+
{ productTitle: "Sticker HTML", measure: ["3*3", "5*5", "10*10"] },
54+
];
55+
3256
export const products = [
3357
{
3458
title: "Polo React",

prisma/migrations/20250621010244_create_user_table/migration.sql

Lines changed: 0 additions & 15 deletions
This file was deleted.

prisma/migrations/20250621010843_update_ts_on_users/migration.sql

Lines changed: 0 additions & 3 deletions
This file was deleted.

prisma/migrations/20250625005548_convert_category_slug_to_enum/migration.sql

Lines changed: 0 additions & 26 deletions
This file was deleted.

prisma/migrations/20250806155625_add_payment_id_to_order/migration.sql

Lines changed: 0 additions & 2 deletions
This file was deleted.

prisma/migrations/20250621053111_proposed_schema/migration.sql renamed to prisma/migrations/20250826163128_init/migration.sql

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1+
-- CreateEnum
2+
CREATE TYPE "CategorySlug" AS ENUM ('polos', 'tazas', 'stickers');
3+
4+
-- CreateTable
5+
CREATE TABLE "users" (
6+
"id" SERIAL NOT NULL,
7+
"email" TEXT NOT NULL,
8+
"name" TEXT,
9+
"password" TEXT,
10+
"is_guest" BOOLEAN NOT NULL DEFAULT true,
11+
"created_at" TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
12+
"updated_at" TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
13+
14+
CONSTRAINT "users_pkey" PRIMARY KEY ("id")
15+
);
16+
117
-- CreateTable
218
CREATE TABLE "categories" (
319
"id" SERIAL NOT NULL,
420
"title" TEXT NOT NULL,
5-
"slug" TEXT NOT NULL,
21+
"slug" "CategorySlug" NOT NULL,
622
"img_src" TEXT,
723
"alt" TEXT,
824
"description" TEXT,
@@ -29,6 +45,25 @@ CREATE TABLE "products" (
2945
CONSTRAINT "products_pkey" PRIMARY KEY ("id")
3046
);
3147

48+
-- CreateTable
49+
CREATE TABLE "ProductVariant" (
50+
"id" SERIAL NOT NULL,
51+
"productId" INTEGER NOT NULL,
52+
"size" TEXT NOT NULL,
53+
54+
CONSTRAINT "ProductVariant_pkey" PRIMARY KEY ("id")
55+
);
56+
57+
-- CreateTable
58+
CREATE TABLE "stickersVariant" (
59+
"id" SERIAL NOT NULL,
60+
"productId" INTEGER NOT NULL,
61+
"measure" TEXT NOT NULL,
62+
"price" DECIMAL(10,2) NOT NULL,
63+
64+
CONSTRAINT "stickersVariant_pkey" PRIMARY KEY ("id")
65+
);
66+
3267
-- CreateTable
3368
CREATE TABLE "carts" (
3469
"id" SERIAL NOT NULL,
@@ -43,8 +78,11 @@ CREATE TABLE "carts" (
4378
-- CreateTable
4479
CREATE TABLE "cart_items" (
4580
"id" SERIAL NOT NULL,
46-
"cart_id" INTEGER NOT NULL,
47-
"product_id" INTEGER NOT NULL,
81+
"cartId" INTEGER NOT NULL,
82+
"productId" INTEGER NOT NULL,
83+
"productVariantId" INTEGER,
84+
"stickersVariantId" INTEGER,
85+
"price" DECIMAL(10,2) NOT NULL,
4886
"quantity" INTEGER NOT NULL,
4987
"created_at" TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
5088
"updated_at" TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
@@ -58,6 +96,7 @@ CREATE TABLE "orders" (
5896
"user_id" INTEGER NOT NULL,
5997
"total_amount" DECIMAL(10,2) NOT NULL,
6098
"email" TEXT NOT NULL,
99+
"payment_id" TEXT,
61100
"first_name" TEXT NOT NULL,
62101
"last_name" TEXT NOT NULL,
63102
"company" TEXT,
@@ -88,26 +127,41 @@ CREATE TABLE "order_items" (
88127
CONSTRAINT "order_items_pkey" PRIMARY KEY ("id")
89128
);
90129

130+
-- CreateIndex
131+
CREATE UNIQUE INDEX "users_email_key" ON "users"("email");
132+
91133
-- CreateIndex
92134
CREATE UNIQUE INDEX "categories_slug_key" ON "categories"("slug");
93135

94136
-- CreateIndex
95137
CREATE UNIQUE INDEX "carts_session_cart_id_key" ON "carts"("session_cart_id");
96138

97139
-- CreateIndex
98-
CREATE UNIQUE INDEX "cart_items_cart_id_product_id_key" ON "cart_items"("cart_id", "product_id");
140+
CREATE UNIQUE INDEX "cart_items_cartId_productId_productVariantId_stickersVarian_key" ON "cart_items"("cartId", "productId", "productVariantId", "stickersVariantId");
99141

100142
-- AddForeignKey
101143
ALTER TABLE "products" ADD CONSTRAINT "products_category_id_fkey" FOREIGN KEY ("category_id") REFERENCES "categories"("id") ON DELETE SET NULL ON UPDATE CASCADE;
102144

145+
-- AddForeignKey
146+
ALTER TABLE "ProductVariant" ADD CONSTRAINT "ProductVariant_productId_fkey" FOREIGN KEY ("productId") REFERENCES "products"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
147+
148+
-- AddForeignKey
149+
ALTER TABLE "stickersVariant" ADD CONSTRAINT "stickersVariant_productId_fkey" FOREIGN KEY ("productId") REFERENCES "products"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
150+
103151
-- AddForeignKey
104152
ALTER TABLE "carts" ADD CONSTRAINT "carts_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
105153

106154
-- AddForeignKey
107-
ALTER TABLE "cart_items" ADD CONSTRAINT "cart_items_cart_id_fkey" FOREIGN KEY ("cart_id") REFERENCES "carts"("id") ON DELETE CASCADE ON UPDATE CASCADE;
155+
ALTER TABLE "cart_items" ADD CONSTRAINT "cart_items_cartId_fkey" FOREIGN KEY ("cartId") REFERENCES "carts"("id") ON DELETE CASCADE ON UPDATE CASCADE;
156+
157+
-- AddForeignKey
158+
ALTER TABLE "cart_items" ADD CONSTRAINT "cart_items_productId_fkey" FOREIGN KEY ("productId") REFERENCES "products"("id") ON DELETE CASCADE ON UPDATE CASCADE;
159+
160+
-- AddForeignKey
161+
ALTER TABLE "cart_items" ADD CONSTRAINT "cart_items_productVariantId_fkey" FOREIGN KEY ("productVariantId") REFERENCES "ProductVariant"("id") ON DELETE SET NULL ON UPDATE CASCADE;
108162

109163
-- AddForeignKey
110-
ALTER TABLE "cart_items" ADD CONSTRAINT "cart_items_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "products"("id") ON DELETE CASCADE ON UPDATE CASCADE;
164+
ALTER TABLE "cart_items" ADD CONSTRAINT "cart_items_stickersVariantId_fkey" FOREIGN KEY ("stickersVariantId") REFERENCES "stickersVariant"("id") ON DELETE SET NULL ON UPDATE CASCADE;
111165

112166
-- AddForeignKey
113167
ALTER TABLE "orders" ADD CONSTRAINT "orders_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;

prisma/schema.prisma

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,19 @@ model Category {
5151
}
5252

5353
model Product {
54-
id Int @id @default(autoincrement())
54+
id Int @id @default(autoincrement())
5555
title String
56-
imgSrc String @map("img_src")
56+
imgSrc String @map("img_src")
5757
alt String?
58-
price Decimal @db.Decimal(10, 2)
58+
price Decimal @db.Decimal(10, 2)
5959
description String?
60-
categoryId Int? @map("category_id")
61-
isOnSale Boolean @default(false) @map("is_on_sale")
60+
categoryId Int? @map("category_id")
61+
isOnSale Boolean @default(false) @map("is_on_sale")
6262
features String[]
63-
createdAt DateTime @default(now()) @map("created_at") @db.Timestamp(0)
64-
updatedAt DateTime @default(now()) @map("updated_at") @db.Timestamp(0)
63+
createdAt DateTime @default(now()) @map("created_at") @db.Timestamp(0)
64+
updatedAt DateTime @default(now()) @map("updated_at") @db.Timestamp(0)
65+
variants ProductVariant[]
66+
stickersVariants stickersVariant[]
6567
6668
category Category? @relation(fields: [categoryId], references: [id], onDelete: SetNull)
6769
cartItems CartItem[]
@@ -70,6 +72,25 @@ model Product {
7072
@@map("products")
7173
}
7274

75+
model ProductVariant {
76+
id Int @id @default(autoincrement())
77+
product Product @relation(fields: [productId], references: [id])
78+
productId Int
79+
size String // 'small', 'medium', 'large'
80+
81+
cartItems CartItem[] @relation("CartItemToProductVariant")
82+
}
83+
84+
model stickersVariant {
85+
id Int @id @default(autoincrement())
86+
product Product @relation(fields: [productId], references: [id])
87+
productId Int
88+
measure String // '3*3', '5*5', '10*10'
89+
price Decimal @db.Decimal(10, 2)
90+
91+
cartItems CartItem[] @relation("CartItemTostickersVariant")
92+
}
93+
7394
model Cart {
7495
id Int @id @default(autoincrement())
7596
sessionCartId String @unique @default(dbgenerated("gen_random_uuid()")) @map("session_cart_id") @db.Uuid
@@ -84,17 +105,22 @@ model Cart {
84105
}
85106

86107
model CartItem {
87-
id Int @id @default(autoincrement())
88-
cartId Int @map("cart_id")
89-
productId Int @map("product_id")
90-
quantity Int
91-
createdAt DateTime @default(now()) @map("created_at") @db.Timestamp(0)
92-
updatedAt DateTime @default(now()) @map("updated_at") @db.Timestamp(0)
108+
id Int @id @default(autoincrement())
109+
cartId Int
110+
productId Int
111+
productVariantId Int?
112+
stickersVariantId Int?
113+
price Decimal @db.Decimal(10, 2)
114+
quantity Int
115+
createdAt DateTime @default(now()) @map("created_at") @db.Timestamp(0)
116+
updatedAt DateTime @default(now()) @map("updated_at") @db.Timestamp(0)
93117
94-
cart Cart @relation(fields: [cartId], references: [id], onDelete: Cascade)
95-
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
118+
cart Cart @relation(fields: [cartId], references: [id], onDelete: Cascade)
119+
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
120+
productVariant ProductVariant? @relation("CartItemToProductVariant", fields: [productVariantId], references: [id])
121+
stickersVariant stickersVariant? @relation("CartItemTostickersVariant", fields: [stickersVariantId], references: [id])
96122
97-
@@unique([cartId, productId], name: "unique_cart_item")
123+
@@unique([cartId, productId, productVariantId, stickersVariantId], name: "unique_cart_item")
98124
@@map("cart_items")
99125
}
100126

0 commit comments

Comments
 (0)