Skip to content

Commit beeef7f

Browse files
authored
Merge pull request #256 from codeableorg/grupo-3-mike
feat: update cart schema and service to use attribute_value_id instead of product_id
2 parents dc11176 + 1bf4cd9 commit beeef7f

File tree

7 files changed

+273
-80
lines changed

7 files changed

+273
-80
lines changed

prisma/initial_data.ts

Lines changed: 86 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,16 @@ export const categories = [
2929
},
3030
];
3131

32+
export const variantAttributes = [
33+
{ name: "no aplica" },
34+
{ name: "talla" },
35+
{ name: "dimensiones" },
36+
]
37+
3238
export const products = [
3339
{
3440
title: "Polo React",
3541
imgSrc: `${imagesBaseUrl}/polos/polo-react.png`,
36-
price: 20.0,
3742
description:
3843
"Viste tu pasión por React con estilo y comodidad en cada línea de código.",
3944
categoryId: 1,
@@ -48,7 +53,6 @@ export const products = [
4853
{
4954
title: "Polo JavaScript",
5055
imgSrc: `${imagesBaseUrl}/polos/polo-js.png`,
51-
price: 20.0,
5256
description:
5357
"Deja que tu amor por JavaScript hable a través de cada hilo de este polo.",
5458
categoryId: 1,
@@ -63,7 +67,6 @@ export const products = [
6367
{
6468
title: "Polo Node.js",
6569
imgSrc: `${imagesBaseUrl}/polos/polo-node.png`,
66-
price: 20.0,
6770
description:
6871
"Conéctate al estilo con este polo de Node.js, tan robusto como tu código.",
6972
categoryId: 1,
@@ -78,7 +81,6 @@ export const products = [
7881
{
7982
title: "Polo TypeScript",
8083
imgSrc: `${imagesBaseUrl}/polos/polo-ts.png`,
81-
price: 20.0,
8284
description:
8385
"Tipa tu estilo con precisión: lleva tu pasión por TypeScript en cada hilo.",
8486
categoryId: 1,
@@ -93,7 +95,6 @@ export const products = [
9395
{
9496
title: "Polo Backend Developer",
9597
imgSrc: `${imagesBaseUrl}/polos/polo-backend.png`,
96-
price: 25.0,
9798
description:
9899
"Domina el servidor con estilo: viste con orgullo tu título de Backend Developer.",
99100
categoryId: 1,
@@ -108,7 +109,6 @@ export const products = [
108109
{
109110
title: "Polo Frontend Developer",
110111
imgSrc: `${imagesBaseUrl}/polos/polo-frontend.png`,
111-
price: 25.0,
112112
description:
113113
"Construye experiencias con estilo: luce con orgullo tu polo de Frontend Developer.",
114114
categoryId: 1,
@@ -123,7 +123,6 @@ export const products = [
123123
{
124124
title: "Polo Full-Stack Developer",
125125
imgSrc: `${imagesBaseUrl}/polos/polo-fullstack.png`,
126-
price: 25.0,
127126
description:
128127
"Domina ambos mundos con estilo: lleva tu título de FullStack Developer en cada línea de tu look.",
129128
categoryId: 1,
@@ -138,7 +137,6 @@ export const products = [
138137
{
139138
title: "Polo It's A Feature",
140139
imgSrc: `${imagesBaseUrl}/polos/polo-feature.png`,
141-
price: 15.0,
142140
description:
143141
"Cuando el bug se convierte en arte: lleva con orgullo tu polo 'It's a feature'.",
144142
categoryId: 1,
@@ -153,7 +151,6 @@ export const products = [
153151
{
154152
title: "Polo It Works On My Machine",
155153
imgSrc: `${imagesBaseUrl}/polos/polo-works.png`,
156-
price: 15.0,
157154
description:
158155
"El clásico del desarrollador: presume tu confianza con 'It works on my machine'.",
159156
categoryId: 1,
@@ -168,7 +165,6 @@ export const products = [
168165
{
169166
title: "Sticker JavaScript",
170167
imgSrc: `${imagesBaseUrl}/stickers/sticker-js.png`,
171-
price: 2.99,
172168
description:
173169
"Muestra tu amor por JavaScript con este elegante sticker clásico.",
174170
categoryId: 3,
@@ -183,7 +179,6 @@ export const products = [
183179
{
184180
title: "Sticker React",
185181
imgSrc: `${imagesBaseUrl}/stickers/sticker-react.png`,
186-
price: 2.49,
187182
description:
188183
"Decora tus dispositivos con el icónico átomo giratorio de React.",
189184
categoryId: 3,
@@ -198,7 +193,6 @@ export const products = [
198193
{
199194
title: "Sticker Git",
200195
imgSrc: `${imagesBaseUrl}/stickers/sticker-git.png`,
201-
price: 3.99,
202196
description:
203197
"Visualiza el poder del control de versiones con este sticker de Git.",
204198
categoryId: 3,
@@ -213,7 +207,6 @@ export const products = [
213207
{
214208
title: "Sticker Docker",
215209
imgSrc: `${imagesBaseUrl}/stickers/sticker-docker.png`,
216-
price: 2.99,
217210
description:
218211
"La adorable ballena de Docker llevando contenedores en un sticker único.",
219212
categoryId: 3,
@@ -228,7 +221,6 @@ export const products = [
228221
{
229222
title: "Sticker Linux",
230223
imgSrc: `${imagesBaseUrl}/stickers/sticker-linux.png`,
231-
price: 2.49,
232224
description:
233225
"El querido pingüino Tux, mascota oficial de Linux, en formato sticker.",
234226
categoryId: 3,
@@ -243,7 +235,6 @@ export const products = [
243235
{
244236
title: "Sticker VS Code",
245237
imgSrc: `${imagesBaseUrl}/stickers/sticker-vscode.png`,
246-
price: 2.49,
247238
description: "El elegante logo del editor favorito de los desarrolladores.",
248239
categoryId: 3,
249240
isOnSale: false,
@@ -257,7 +248,6 @@ export const products = [
257248
{
258249
title: "Sticker GitHub",
259250
imgSrc: `${imagesBaseUrl}/stickers/sticker-github.png`,
260-
price: 2.99,
261251
description:
262252
"El alojamiento de repositorios más popular en un sticker de alta calidad.",
263253
categoryId: 3,
@@ -272,7 +262,6 @@ export const products = [
272262
{
273263
title: "Sticker HTML",
274264
imgSrc: `${imagesBaseUrl}/stickers/sticker-html.png`,
275-
price: 2.99,
276265
description:
277266
"El escudo naranja de HTML5, el lenguaje que estructura la web.",
278267
categoryId: 3,
@@ -287,7 +276,6 @@ export const products = [
287276
{
288277
title: "Taza JavaScript",
289278
imgSrc: `${imagesBaseUrl}/tazas/taza-js.png`,
290-
price: 14.99,
291279
description:
292280
"Disfruta tu café mientras programas con el logo de JavaScript.",
293281
categoryId: 2,
@@ -302,7 +290,6 @@ export const products = [
302290
{
303291
title: "Taza React",
304292
imgSrc: `${imagesBaseUrl}/tazas/taza-react.png`,
305-
price: 13.99,
306293
description:
307294
"Una taza que hace render de tu bebida favorita con estilo React.",
308295
categoryId: 2,
@@ -317,7 +304,6 @@ export const products = [
317304
{
318305
title: "Taza Git",
319306
imgSrc: `${imagesBaseUrl}/tazas/taza-git.png`,
320-
price: 12.99,
321307
description: "Commit a tu rutina diaria de café con esta taza de Git.",
322308
categoryId: 2,
323309
isOnSale: false,
@@ -331,7 +317,6 @@ export const products = [
331317
{
332318
title: "Taza SQL",
333319
imgSrc: `${imagesBaseUrl}/tazas/taza-sql.png`,
334-
price: 15.99,
335320
description: "Tu amor por los lenguajes estructurados en una taza de SQL.",
336321
categoryId: 2,
337322
isOnSale: false,
@@ -345,7 +330,6 @@ export const products = [
345330
{
346331
title: "Taza Linux",
347332
imgSrc: `${imagesBaseUrl}/tazas/taza-linux.png`,
348-
price: 13.99,
349333
description: "Toma tu café con la libertad que solo Linux puede ofrecer.",
350334
categoryId: 2,
351335
isOnSale: false,
@@ -359,7 +343,6 @@ export const products = [
359343
{
360344
title: "Taza GitHub",
361345
imgSrc: `${imagesBaseUrl}/tazas/taza-github.png`,
362-
price: 14.99,
363346
description: "Colabora con tu café en esta taza con el logo de GitHub.",
364347
categoryId: 2,
365348
isOnSale: false,
@@ -371,3 +354,83 @@ export const products = [
371354
],
372355
},
373356
];
357+
358+
export const variantAttributeValues = [
359+
// --- POLOS (talla: S, M, L) ---
360+
{ attributeId: 1, productId: 1, value: "S", price: 20.0 },
361+
{ attributeId: 1, productId: 1, value: "M", price: 20.0 },
362+
{ attributeId: 1, productId: 1, value: "L", price: 20.0 },
363+
364+
{ attributeId: 1, productId: 2, value: "S", price: 20.0 },
365+
{ attributeId: 1, productId: 2, value: "M", price: 20.0 },
366+
{ attributeId: 1, productId: 2, value: "L", price: 20.0 },
367+
368+
{ attributeId: 1, productId: 3, value: "S", price: 20.0 },
369+
{ attributeId: 1, productId: 3, value: "M", price: 20.0 },
370+
{ attributeId: 1, productId: 3, value: "L", price: 20.0 },
371+
372+
{ attributeId: 1, productId: 4, value: "S", price: 20.0 },
373+
{ attributeId: 1, productId: 4, value: "M", price: 20.0 },
374+
{ attributeId: 1, productId: 4, value: "L", price: 20.0 },
375+
376+
{ attributeId: 1, productId: 5, value: "S", price: 25.0 },
377+
{ attributeId: 1, productId: 5, value: "M", price: 25.0 },
378+
{ attributeId: 1, productId: 5, value: "L", price: 25.0 },
379+
380+
{ attributeId: 1, productId: 6, value: "S", price: 25.0 },
381+
{ attributeId: 1, productId: 6, value: "M", price: 25.0 },
382+
{ attributeId: 1, productId: 6, value: "L", price: 25.0 },
383+
384+
{ attributeId: 1, productId: 7, value: "S", price: 25.0 },
385+
{ attributeId: 1, productId: 7, value: "M", price: 25.0 },
386+
{ attributeId: 1, productId: 7, value: "L", price: 25.0 },
387+
388+
{ attributeId: 1, productId: 8, value: "S", price: 15.0 },
389+
{ attributeId: 1, productId: 8, value: "M", price: 15.0 },
390+
{ attributeId: 1, productId: 8, value: "L", price: 15.0 },
391+
392+
{ attributeId: 1, productId: 9, value: "S", price: 15.0 },
393+
{ attributeId: 1, productId: 9, value: "M", price: 15.0 },
394+
{ attributeId: 1, productId: 9, value: "L", price: 15.0 },
395+
396+
// --- STICKERS (dimensiones: 3x3, 6x6, 9x9) ---
397+
{ attributeId: 2, productId: 10, value: "3x3", price: 2.99 },
398+
{ attributeId: 2, productId: 10, value: "6x6", price: 3.99 },
399+
{ attributeId: 2, productId: 10, value: "9x9", price: 4.99 },
400+
401+
{ attributeId: 2, productId: 11, value: "3x3", price: 2.49 },
402+
{ attributeId: 2, productId: 11, value: "6x6", price: 3.49 },
403+
{ attributeId: 2, productId: 11, value: "9x9", price: 4.49 },
404+
405+
{ attributeId: 2, productId: 12, value: "3x3", price: 3.99 },
406+
{ attributeId: 2, productId: 12, value: "6x6", price: 4.99 },
407+
{ attributeId: 2, productId: 12, value: "9x9", price: 5.99 },
408+
409+
{ attributeId: 2, productId: 13, value: "3x3", price: 2.99 },
410+
{ attributeId: 2, productId: 13, value: "6x6", price: 3.99 },
411+
{ attributeId: 2, productId: 13, value: "9x9", price: 4.99 },
412+
413+
{ attributeId: 2, productId: 14, value: "3x3", price: 2.49 },
414+
{ attributeId: 2, productId: 14, value: "6x6", price: 3.49 },
415+
{ attributeId: 2, productId: 14, value: "9x9", price: 4.49 },
416+
417+
{ attributeId: 2, productId: 15, value: "3x3", price: 2.49 },
418+
{ attributeId: 2, productId: 15, value: "6x6", price: 3.49 },
419+
{ attributeId: 2, productId: 15, value: "9x9", price: 4.49 },
420+
421+
{ attributeId: 2, productId: 16, value: "3x3", price: 2.99 },
422+
{ attributeId: 2, productId: 16, value: "6x6", price: 3.99 },
423+
{ attributeId: 2, productId: 16, value: "9x9", price: 4.99 },
424+
425+
{ attributeId: 2, productId: 17, value: "3x3", price: 2.99 },
426+
{ attributeId: 2, productId: 17, value: "6x6", price: 3.99 },
427+
{ attributeId: 2, productId: 17, value: "9x9", price: .99 },
428+
429+
// --- TAZAS (no aplica: Único) ---
430+
{ attributeId: 3, productId: 18, value: "Único", price: 14.99 },
431+
{ attributeId: 3, productId: 19, value: "Único", price: 13.99 },
432+
{ attributeId: 3, productId: 20, value: "Único", price: 12.99 },
433+
{ attributeId: 3, productId: 21, value: "Único", price: 15.99 },
434+
{ attributeId: 3, productId: 22, value: "Único", price: 13.99 },
435+
{ attributeId: 3, productId: 23, value: "Único", price: 14.99 },
436+
];
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `price` on the `products` table. All the data in the column will be lost.
5+
6+
*/
7+
-- AlterTable
8+
ALTER TABLE "products" DROP COLUMN "price";
9+
10+
-- CreateTable
11+
CREATE TABLE "variants_attributes" (
12+
"id" SERIAL NOT NULL,
13+
"name" TEXT NOT NULL,
14+
"created_at" TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
15+
"updated_at" TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
16+
17+
CONSTRAINT "variants_attributes_pkey" PRIMARY KEY ("id")
18+
);
19+
20+
-- CreateTable
21+
CREATE TABLE "variants_attributes_values" (
22+
"id" SERIAL NOT NULL,
23+
"attribute_id" INTEGER NOT NULL,
24+
"product_id" INTEGER NOT NULL,
25+
"value" TEXT NOT NULL,
26+
"price" DECIMAL(10,2) NOT NULL,
27+
"created_at" TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
28+
"updated_at" TIMESTAMP(0) NOT NULL DEFAULT CURRENT_TIMESTAMP,
29+
30+
CONSTRAINT "variants_attributes_values_pkey" PRIMARY KEY ("id")
31+
);
32+
33+
-- CreateIndex
34+
CREATE UNIQUE INDEX "variants_attributes_name_key" ON "variants_attributes"("name");
35+
36+
-- CreateIndex
37+
CREATE UNIQUE INDEX "variants_attributes_values_attribute_id_product_id_value_key" ON "variants_attributes_values"("attribute_id", "product_id", "value");
38+
39+
-- AddForeignKey
40+
ALTER TABLE "variants_attributes_values" ADD CONSTRAINT "variants_attributes_values_attribute_id_fkey" FOREIGN KEY ("attribute_id") REFERENCES "variants_attributes"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
41+
42+
-- AddForeignKey
43+
ALTER TABLE "variants_attributes_values" ADD CONSTRAINT "variants_attributes_values_product_id_fkey" FOREIGN KEY ("product_id") REFERENCES "products"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
Warnings:
3+
4+
- You are about to drop the column `product_id` on the `cart_items` table. All the data in the column will be lost.
5+
- A unique constraint covering the columns `[cart_id,attribute_value_id]` on the table `cart_items` will be added. If there are existing duplicate values, this will fail.
6+
- Added the required column `attribute_value_id` to the `cart_items` table without a default value. This is not possible if the table is not empty.
7+
8+
*/
9+
-- DropForeignKey
10+
ALTER TABLE "cart_items" DROP CONSTRAINT "cart_items_product_id_fkey";
11+
12+
-- DropIndex
13+
DROP INDEX "cart_items_cart_id_product_id_key";
14+
15+
-- AlterTable
16+
ALTER TABLE "cart_items" DROP COLUMN "product_id",
17+
ADD COLUMN "attribute_value_id" INTEGER NOT NULL;
18+
19+
-- CreateIndex
20+
CREATE UNIQUE INDEX "cart_items_cart_id_attribute_value_id_key" ON "cart_items"("cart_id", "attribute_value_id");
21+
22+
-- AddForeignKey
23+
ALTER TABLE "cart_items" ADD CONSTRAINT "cart_items_attribute_value_id_fkey" FOREIGN KEY ("attribute_value_id") REFERENCES "variants_attributes_values"("id") ON DELETE CASCADE ON UPDATE CASCADE;

0 commit comments

Comments
 (0)