From 3c508700273fb8d794434f8b8dd09061021eb15a Mon Sep 17 00:00:00 2001 From: "Mr. David" <128073754+ProgrammerDATCH@users.noreply.github.com> Date: Thu, 1 Aug 2024 20:35:08 +0200 Subject: [PATCH] Correct product update images save & add seeds (#106) * Correct product update images save & add seeds * Fixes tests --- .../seeders/20240601224835-products.ts | 972 +++++++++++++++++- src/middlewares/validation.ts | 15 +- .../product/controller/productController.ts | 5 +- src/modules/product/test/product.spec.ts | 17 +- .../product/validation/productValidation.ts | 1 + 5 files changed, 967 insertions(+), 43 deletions(-) diff --git a/src/databases/seeders/20240601224835-products.ts b/src/databases/seeders/20240601224835-products.ts index 89e82435..2094c52c 100644 --- a/src/databases/seeders/20240601224835-products.ts +++ b/src/databases/seeders/20240601224835-products.ts @@ -1,5 +1,6 @@ /* eslint-disable comma-dangle */ import { QueryInterface } from "sequelize"; +import { v4 as uuidv4 } from "uuid"; import { productOneId, productTwoId, @@ -23,7 +24,7 @@ const productOne = { name: "Shoes", description: "Shoes are a crucial part of your wardrobe, providing not only style but also comfort and support for your feet.", - price: 19.99, + price: 32.21, discount: "10%", category: "Dress Shoes", expiryDate: new Date("2050-12-31"), @@ -70,7 +71,7 @@ const productThree = { name: "Flat TV", description: "A flat TV is a sleek and modern television designed to offer high-quality visuals and a seamless viewing experience. Featuring a slim profile and advanced display technology, such as LED, OLED, or QLED, flat TVs deliver vibrant colors, sharp contrasts, and clear images. They are available in various sizes to fit different spaces, from compact models for bedrooms to large screens for home theaters. ", - price: 19.99, + price: 698.88, discount: "8%", category: "Electronics", expiryDate: new Date("2040-12-31"), @@ -94,7 +95,7 @@ const productFour = { name: "Cable Mouse", description: "A cable mouse is a reliable and efficient pointing device for computers, featuring a wired connection for consistent performance and responsiveness. It offers precision and control, making it ideal for tasks ranging from everyday browsing to detailed graphic design. The cable ensures a stable connection without the need for batteries, and many models come with ergonomic designs to enhance comfort during extended use.", - price: 19.99, + price: 3, discount: "11%", category: "Computer Accessories", expiryDate: new Date("2050-12-31"), @@ -118,7 +119,7 @@ const productFive = { name: "Watch", description: "A watch is a timeless accessory that combines functionality with style, offering a convenient way to tell time while also making a fashion statement. Available in various designs, from classic analog to sleek digital models, watches cater to different preferences and occasions. They often feature durable materials like stainless steel or leather, with advanced features such as water resistance and additional functionalities like chronographs or smart capabilities.", - price: 19.99, + price: 38.91, discount: "17%", category: "Dress Watches", expiryDate: new Date("2050-12-31"), @@ -142,7 +143,7 @@ const productSix = { name: "Necklace", description: "A necklace is a versatile piece of jewelry worn around the neck, enhancing one's attire with elegance and personal flair. Available in an array of styles and materials, necklaces range from delicate chains adorned with pendants to elaborate designs featuring gemstones or precious metals. They serve as symbols of fashion, sentimentality, or cultural significance, complementing both casual and formal outfits with grace. Whether chosen for everyday wear or special occasions, a necklace adds a touch of sophistication and individuality to any ensemble.", - price: 19.99, + price: 198.62, discount: "18%", category: "Dress", expiryDate: new Date("2050-12-31"), @@ -166,7 +167,7 @@ const productSeven = { name: "Microphone", description: "A microphone, commonly referred to as a mic, is an essential audio device used to capture sound. It converts sound waves into electrical signals, making it crucial for a wide range of applications including recording, broadcasting, public speaking, and communication. Microphones come in various types, such as dynamic, condenser, and ribbon, each designed for specific uses and environments. With advancements in technology, modern microphones offer high-fidelity audio capture, noise reduction, and wireless capabilities, ensuring clear and accurate sound reproduction.", - price: 19.99, + price: 50, discount: "21%", category: "Electronics", expiryDate: new Date("2050-12-31"), @@ -190,7 +191,7 @@ const productEight = { name: "Camera", description: "A camera is a versatile device used to capture and record images and videos, preserving moments with clarity and detail. Cameras come in various types, including digital, DSLR, mirrorless, and action cameras, each catering to different photography needs and skill levels. Equipped with advanced features like high-resolution sensors, optical zoom, and various shooting modes, modern cameras allow users to capture everything from stunning landscapes to fast-moving action with precision. Whether for professional photography, personal memories, or creative projects, a camera is an indispensable tool for visual storytelling.", - price: 19.99, + price: 912.16, discount: "22%", category: "Electronics", expiryDate: new Date("2050-12-31"), @@ -293,6 +294,950 @@ const productTwelve = { expiryDate: new Date("2050-12-31"), expired: false, bonus: "Bonus 1", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 50, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productThirteen = { + id: uuidv4(), + shopId: shopOneId, + name: "Stainless Steel Kitchen Knife Set", + description: "Professional-grade 6-piece knife set with ergonomic handles and a wooden block.", + price: 149.99, + discount: "12%", + category: "Kitchen & Dining", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free knife sharpener", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 40, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productFourteen = { + id: uuidv4(), + shopId: shopTwoId, + name: "Organic Cotton Bath Towel Set", + description: "Luxurious 4-piece towel set made from 100% organic cotton, soft and absorbent.", + price: 59.99, + discount: "5%", + category: "Home & Bath", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free hand towel", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 75, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productFifteen = { + id: uuidv4(), + shopId: shopOneId, + name: "Wireless Gaming Mouse", + description: "High-precision optical sensor, customizable RGB lighting, and ergonomic design for extended gaming sessions.", + price: 79.99, + discount: "15%", + category: "Computer Accessories", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free mousepad", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 100, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productSixteen = { + id: uuidv4(), + shopId: shopTwoId, + name: "Portable Bluetooth Speaker", + description: "Waterproof, 20-hour battery life, and rich, immersive sound for outdoor adventures.", + price: 89.99, + discount: "10%", + category: "Electronics", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free carrying case", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 60, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productSeventeen = { + id: uuidv4(), + shopId: shopOneId, + name: "Yoga Mat with Carrying Strap", + description: "Eco-friendly, non-slip yoga mat with alignment lines and a convenient carrying strap.", + price: 39.99, + discount: "7%", + category: "Sports & Fitness", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free yoga block", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 120, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productEighteen = { + id: uuidv4(), + shopId: shopTwoId, + name: "Stainless Steel Water Bottle", + description: "Vacuum-insulated, 24oz capacity, keeps drinks cold for 24 hours or hot for 12 hours.", + price: 29.99, + discount: "0%", + category: "Outdoor & Recreation", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free bottle brush", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 200, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productNineteen = { + id: uuidv4(), + shopId: shopOneId, + name: "Wireless Noise-Cancelling Headphones", + description: "Over-ear headphones with active noise cancellation, 30-hour battery life, and premium audio quality.", + price: 249.99, + discount: "18%", + category: "Electronics", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free travel case", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 50, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productTwenty = { + id: uuidv4(), + shopId: shopTwoId, + name: "Smart Home Security Camera", + description: "1080p HD video, two-way audio, night vision, and mobile app control for home security.", + price: 129.99, + discount: "8%", + category: "Smart Home", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "1-month free cloud storage", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 80, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productTwentyOne = { + id: uuidv4(), + shopId: shopOneId, + name: "Men's Slim Fit Dress Shirt", + description: "Wrinkle-resistant cotton blend dress shirt, perfect for office or formal events.", + price: 45.99, + discount: "5%", + category: "Men's Clothing", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free collar stays", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 100, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productTwentyTwo = { + id: uuidv4(), + shopId: shopTwoId, + name: "Women's Running Shoes", + description: "Lightweight, breathable running shoes with superior cushioning and support.", + price: 89.99, + discount: "15%", + category: "Women's Footwear", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free pair of running socks", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 75, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productTwentyThree = { + id: uuidv4(), + shopId: shopOneId, + name: "Digital Kitchen Scale", + description: "Precise measuring up to 11 lbs, with tare function and multiple unit options.", + price: 24.99, + discount: "0%", + category: "Kitchen & Dining", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free recipe e-book", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 120, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productTwentyFour = { + id: uuidv4(), + shopId: shopTwoId, + name: "Facial Cleansing Brush", + description: "Waterproof electric facial cleansing brush with multiple speed settings.", + price: 39.99, + discount: "10%", + category: "Beauty & Personal Care", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free travel pouch", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 90, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productTwentyFive = { + id: uuidv4(), + shopId: shopOneId, + name: "Adjustable Dumbbell Set", + description: "Space-saving adjustable dumbbells, 5-52.5 lbs each, perfect for home gyms.", + price: 299.99, + discount: "7%", + category: "Sports & Fitness", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free workout guide", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 30, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productTwentySix = { + id: uuidv4(), + shopId: shopTwoId, + name: "Ergonomic Office Chair", + description: "Adjustable height and lumbar support, breathable mesh back for comfort.", + price: 179.99, + discount: "12%", + category: "Home Office", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free desk mat", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 50, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productTwentySeven = { + id: uuidv4(), + shopId: shopOneId, + name: "Smart WiFi Light Bulb", + description: "Color-changing LED bulb, voice control compatible, app-controlled scheduling.", + price: 29.99, + discount: "5%", + category: "Smart Home", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free smart plug", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 150, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productTwentyEight = { + id: uuidv4(), + shopId: shopTwoId, + name: "Leather Wallet for Men", + description: "Genuine leather bifold wallet with RFID blocking technology.", + price: 49.99, + discount: "0%", + category: "Accessories", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free money clip", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 100, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productTwentyNine = { + id: uuidv4(), + shopId: shopOneId, + name: "Electric Coffee Grinder", + description: "Stainless steel blade grinder with multiple grind settings for perfect coffee.", + price: 34.99, + discount: "8%", + category: "Kitchen & Dining", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free coffee scoop", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 80, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productThirty = { + id: uuidv4(), + shopId: shopTwoId, + name: "Wireless Car Charger Mount", + description: "Fast-charging, auto-clamping phone mount for car dashboard or air vent.", + price: 39.99, + discount: "10%", + category: "Automotive", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free USB car charger", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 70, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productThirtyOne = { + id: uuidv4(), + shopId: shopOneId, + name: "Portable Camping Stove", + description: "Compact propane camping stove with two burners, perfect for outdoor cooking.", + price: 69.99, + discount: "15%", + category: "Outdoor & Recreation", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free carrying case", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 40, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productThirtyTwo = { + id: uuidv4(), + shopId: shopTwoId, + name: "Wireless Gaming Controller", + description: "Ergonomic design, customizable buttons, compatible with PC and mobile devices.", + price: 59.99, + discount: "5%", + category: "Gaming", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free phone clip", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 100, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productThirtyThree = { + id: uuidv4(), + shopId: shopOneId, + name: "Wooden Chess Set", + description: "Handcrafted wooden chess set with felt-bottom pieces and folding board.", + price: 79.99, + discount: "0%", + category: "Toys & Games", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free strategy guide", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 30, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productThirtyFour = { + id: uuidv4(), + shopId: shopTwoId, + name: "Indoor Herb Garden Kit", + description: "Self-watering planter with LED grow light, perfect for kitchen herbs.", + price: 49.99, + discount: "10%", + category: "Home & Garden", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free herb seed pack", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 60, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productThirtyFive = { + id: uuidv4(), + shopId: shopOneId, + name: "Digital Drawing Tablet", + description: "10-inch graphic tablet with 8192 pressure levels and wireless stylus.", + price: 129.99, + discount: "12%", + category: "Electronics", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free software bundle", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 40, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productThirtySix = { + id: uuidv4(), + shopId: shopTwoId, + name: "Robotic Vacuum Cleaner", + description: "Smart navigation, app control, and self-charging for effortless cleaning.", + price: 249.99, + discount: "15%", + category: "Home Appliances", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free replacement filters", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 25, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productThirtySeven = { + id: uuidv4(), + shopId: shopOneId, + name: "Leather Messenger Bag", + description: "Genuine leather bag with padded laptop compartment and multiple pockets.", + price: 119.99, + discount: "8%", + category: "Bags & Luggage", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free leather care kit", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 50, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productThirtyEight = { + id: uuidv4(), + shopId: shopTwoId, + name: "Wireless Meat Thermometer", + description: "Bluetooth-enabled thermometer with app alerts and preset temperatures.", + price: 59.99, + discount: "5%", + category: "Kitchen & Dining", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free grill mitt", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 75, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productThirtyNine = { + id: uuidv4(), + shopId: shopOneId, + name: "Smart Door Lock", + description: "Keyless entry with fingerprint, code, and smartphone app access.", + price: 199.99, + discount: "10%", + category: "Smart Home", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free installation guide", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 40, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productForty = { + id: uuidv4(), + shopId: shopTwoId, + name: "Portable Espresso Maker", + description: "Manual espresso maker for travel, compatible with ground coffee and pods.", + price: 69.99, + discount: "0%", + category: "Kitchen & Dining", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free coffee sampler", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 60, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productFortyOne = { + id: uuidv4(), + shopId: shopOneId, + name: "Wireless Earbuds", + description: "True wireless earbuds with noise cancellation and 24-hour battery life.", + price: 129.99, + discount: "15%", + category: "Electronics", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free silicone ear tips set", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 100, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productFortyTwo = { + id: uuidv4(), + shopId: shopTwoId, + name: "Yoga Wheel", + description: "Durable yoga wheel for stretching and improving flexibility, supports up to 500 lbs.", + price: 39.99, + discount: "5%", + category: "Sports & Fitness", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free yoga strap", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 80, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productFortyThree = { + id: uuidv4(), + shopId: shopOneId, + name: "Smart Wi-Fi Air Purifier", + description: "HEPA air purifier with app control, air quality monitor, and quiet operation.", + price: 179.99, + discount: "12%", + category: "Home Appliances", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free replacement filter", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 50, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productFortyFour = { + id: uuidv4(), + shopId: shopTwoId, + name: "Electric Wine Opener", + description: "Rechargeable wine bottle opener with foil cutter and LED charging base.", + price: 29.99, + discount: "0%", + category: "Kitchen & Dining", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free wine stopper", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 120, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productFortyFive = { + id: uuidv4(), + shopId: shopOneId, + name: "Leather Watch Box", + description: "12-slot watch organizer with glass top and lock, lined with soft velvet.", + price: 59.99, + discount: "8%", + category: "Accessories", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free microfiber cleaning cloth", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 40, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productFortySix = { + id: uuidv4(), + shopId: shopTwoId, + name: "Portable Car Jump Starter", + description: "1000A peak current, built-in flashlight, and USB charging ports for emergencies.", + price: 79.99, + discount: "10%", + category: "Automotive", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free carrying case", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 70, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productFortySeven = { + id: uuidv4(), + shopId: shopOneId, + name: "Digital Bathroom Scale", + description: "Smart scale with body composition analysis and smartphone app sync.", + price: 49.99, + discount: "5%", + category: "Health & Wellness", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free body tape measure", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 90, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productFortyEight = { + id: uuidv4(), + shopId: shopTwoId, + name: "Collapsible Silicone Water Bottle", + description: "BPA-free, leak-proof, and easy to clean, perfect for travel and outdoor activities.", + price: 19.99, + discount: "0%", + category: "Outdoor & Recreation", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free carabiner clip", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 150, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productFortyNine = { + id: uuidv4(), + shopId: shopOneId, + name: "Adjustable Laptop Stand", + description: "Ergonomic aluminum stand with 6 adjustable angles, suitable for laptops up to 17 inches.", + price: 39.99, + discount: "7%", + category: "Office Products", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free cable organizer", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 80, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productFifty = { + id: uuidv4(), + shopId: shopTwoId, + name: "Sunrise Alarm Clock", + description: "Wake-up light with natural sunrise simulation, multiple sound options, and FM radio.", + price: 45.99, + discount: "10%", + category: "Home & Bedroom", + expiryDate: new Date("2050-12-31"), + expired: false, + bonus: "Free sleep mask", + images: [ + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100", + "https://placehold.co/100x100" + ], + quantity: 60, + status: "available", + createdAt: new Date(), + updatedAt: new Date(), +}; + +const productFiftyOne = { + id: uuidv4(), + shopId: shopOneId, + name: "Red Sneakers", + description: "Red Sneakers Women Shoes Woman Tennis Shoes Canvas Shoe Female Casual Shoes Ladies Sport Shoes Platform Sneaker Hollow Out Shoes", + price: 20.99, + discount: "6%", + category: "Women's Shoes", + expiryDate: new Date("2050-12-31T00:00:00Z"), + expired: false, + bonus: "Bonus 1", + images: [ + "https://res.cloudinary.com/du0vvcuiz/image/upload/v1721924368/ckqqguqwcg6gplhpp2za.jpg", + "https://res.cloudinary.com/du0vvcuiz/image/upload/v1721924368/itheprnho9dfqioddpmi.jpg", + "https://res.cloudinary.com/du0vvcuiz/image/upload/v1721924368/klb3npd418trkupivlnd.jpg", + "https://res.cloudinary.com/du0vvcuiz/image/upload/v1721924368/rxsfmonky2iegr7hnsbu.jpg", + "https://res.cloudinary.com/du0vvcuiz/image/upload/v1721924368/n8g2jwvsqip1d947flql.jpg" + ], + quantity: 5, + status: "available", + createdAt: new Date("2024-07-25T17:17:42.603Z"), + updatedAt: new Date("2024-07-30T15:24:48.418562Z"), +}; + +const productFiftyTwo = { + id: uuidv4(), + shopId: shopTwoId, + name: "Fashion T-Cross Paints", + description: "Fashion Solid Color Work Casual Multiple Pockets Men's Cargo Pants Classic Waist Drawcord Pure Cotton Youth Tide Male Trousers", + price: 7.99, + discount: "7%", + category: "Men's Clothes", + expiryDate: new Date("2050-12-31T00:00:00Z"), + expired: false, + bonus: "Bonus 1", + images: [ + "https://res.cloudinary.com/du0vvcuiz/image/upload/v1721923392/auilcu7ibtttacjonozl.jpg", + "https://res.cloudinary.com/du0vvcuiz/image/upload/v1721923393/egibnnshd2jmt335yzma.jpg", + "https://res.cloudinary.com/du0vvcuiz/image/upload/v1721923396/jojvqx5z6dunixeep1vd.jpg", + "https://res.cloudinary.com/du0vvcuiz/image/upload/v1721923392/gem1f2uotaw3rgcpd95z.jpg" + ], + quantity: 50, + status: "available", + createdAt: new Date("2024-07-25T17:17:42.603Z"), + updatedAt: new Date("2024-07-25T17:17:42.603Z"), +}; + +const productFiftyThree = { + id: uuidv4(), + shopId: shopOneId, + name: "Solid Black Label Paints", + description: "Fashion Solid Color Work Casual Multiple Pockets Men's Cargo Pants Classic Waist Drawcord Pure Cotton Youth Tide Male Trousers", + price: 15.99, + discount: "15%", + category: "Men's Clothes", + expiryDate: new Date("2050-12-31T00:00:00Z"), + expired: false, + bonus: "Bonus 1", images: [ "https://res.cloudinary.com/du0vvcuiz/image/upload/v1721924072/eoknuaiwroxnvg7zhuvm.webp", "https://res.cloudinary.com/du0vvcuiz/image/upload/v1721924072/xm6k5zjjbmy8viz01y0w.webp", @@ -302,8 +1247,8 @@ const productTwelve = { ], quantity: 50, status: "available", - createdAt: new Date(), - updatedAt: new Date(), + createdAt: new Date("2024-07-25T17:17:42.603Z"), + updatedAt: new Date("2024-07-25T17:17:42.603Z"), }; export const up = async (queryInterface: QueryInterface) => { @@ -319,7 +1264,14 @@ export const up = async (queryInterface: QueryInterface) => { productNine, productTen, productEleven, - productTwelve + productTwelve, + productThirteen, productFourteen, productFifteen, productSixteen, productSeventeen, productEighteen, + productNineteen, productTwenty, productTwentyOne, productTwentyTwo, productTwentyThree, productTwentyFour, + productTwentyFive, productTwentySix, productTwentySeven, productTwentyEight, productTwentyNine, + productThirty, productThirtyOne, productThirtyTwo, productThirtyThree, productThirtyFour, productThirtyFive, productThirtySix, + productThirtySeven, productThirtyEight, productThirtyNine, productForty, productFortyOne, productFortyTwo, productFortyThree, + productFortyFour, productFortyFive, productFortySix, productFortySeven, productFortyEight, productFortyNine, + productFifty, productFiftyOne, productFiftyTwo, productFiftyThree ]); }; diff --git a/src/middlewares/validation.ts b/src/middlewares/validation.ts index 34134536..e180b7e0 100644 --- a/src/middlewares/validation.ts +++ b/src/middlewares/validation.ts @@ -315,20 +315,7 @@ const isProductExist = async (req: any, res: Response, next: NextFunction) => { .status(httpStatus.NOT_FOUND) .json({ status: httpStatus.NOT_FOUND, message: "Not shop found." }); } - const isProductAvailable = - await productRepositories.findByModelsAndAttributes( - Products, - "name", - "shopId", - req.body.name, - shop.id - ); - if (isProductAvailable) { - return res.status(httpStatus.BAD_REQUEST).json({ - status: httpStatus.BAD_REQUEST, - message: "Please update the quantities.", - }); - } + req.shop = shop; next(); } catch (error) { diff --git a/src/modules/product/controller/productController.ts b/src/modules/product/controller/productController.ts index b843c3dc..0de1f205 100644 --- a/src/modules/product/controller/productController.ts +++ b/src/modules/product/controller/productController.ts @@ -204,15 +204,14 @@ const sellerUpdateProduct = async (req: ExtendRequest, res: Response) => { const images = uploadPromises && (await Promise.all(uploadPromises)); - const imagesArr = images + const imagesArr = (images && images.length > 0) ? images.map((image) => image.secure_url) : product.images; const updatedProductData = { ...product, ...req.body, - imagesArr, - expiryDate: new Date(), + images: imagesArr, }; const updatedProduct = await productRepositories.updateProduct( diff --git a/src/modules/product/test/product.spec.ts b/src/modules/product/test/product.spec.ts index a9f97d18..a2ecf8a5 100644 --- a/src/modules/product/test/product.spec.ts +++ b/src/modules/product/test/product.spec.ts @@ -504,22 +504,7 @@ describe("Product Middleware", () => { }); }); - it("should return 400 if the product already exists", async () => { - sinon - .stub(productRepositories, "findShopByAttributes") - .resolves({ id: 1 }); - sinon - .stub(productRepositories, "findByModelsAndAttributes") - .resolves(true); - - await isProductExist(req, res, next); - - expect(res.status).to.have.been.calledWith(httpStatus.BAD_REQUEST); - expect(res.json).to.have.been.calledWith({ - status: httpStatus.BAD_REQUEST, - message: "Please update the quantities.", - }); - }); + it("should call next if product does not exist", async () => { sinon diff --git a/src/modules/product/validation/productValidation.ts b/src/modules/product/validation/productValidation.ts index 12aa70fa..df558136 100644 --- a/src/modules/product/validation/productValidation.ts +++ b/src/modules/product/validation/productValidation.ts @@ -54,6 +54,7 @@ const productUpdateSchema = Joi.object({ expiryDate: Joi.date().optional(), expired: Joi.boolean().default(false).optional(), bonus: Joi.string().optional(), + quantity: Joi.string().optional(), }); const shopSchema = Joi.object({