Skip to content

Commit

Permalink
Merge pull request #250 from saurabhbakolia/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
saurabhbakolia authored Oct 26, 2024
2 parents b8b5ba3 + ca40b1e commit b177945
Show file tree
Hide file tree
Showing 43 changed files with 1,667,482 additions and 24,783 deletions.
12 changes: 12 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
npm run lint-fix && npm run lint-format

npm run lint-fix
if [ $? -ne 0 ]; then
echo "ESLint failed, aborting commit."
exit 1
fi

npm run lint-format
if [ $? -ne 0 ]; then
echo "Prettier formatting failed, aborting commit."
exit 1
fi
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"cSpell.words": [
"atleast",
"comingsoon",
"Ecommerce",
"registeration",
"SCROLLME"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ScrollMe is an open-source, feature-rich eCommerce platform that provides a mode
- [ ] **Checkout Process**: Easy and secure checkout experience.
- [ ] **Order History**: View past orders and order details.
- [ ] **Product Reviews and Ratings**: Users can review and rate products.
- [x] **Wishlist**: Save favorite items for later purchase.
- [x] **Wishlist**: Save favourite items for later purchase.
- [ ] **Payment Gateway Integration**: Add integration with payment providers like Stripe or PayPal.
- [x] **Responsive Design**: Optimized for all devices (mobile, tablet, and desktop).
Expand Down
8 changes: 6 additions & 2 deletions backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
MONGODB_URI = mongodb://localhost:27017 // You need to change this and add the database name.
SALT = "Some Randome Character"
MONGODB_DATABASE_NAME = scrollme
MONGODB_URI = mongodb://localhost:27017/scrollme
PRODUCTS_COLLECTION_NAME = products
SALT = 10
JWT_SECRET = someone
UNSPLASH_ACCESS_KEY=API_KEY
23 changes: 23 additions & 0 deletions backend/api/models/productModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const ProductSchema = new Schema(
type: Number,
required: true,
},
discounted_price: {
type: Number,
},
category: {
type: String,
trim: true,
Expand Down Expand Up @@ -59,6 +62,26 @@ const ProductSchema = new Schema(
type: String,
trim: true,
},
sizes: {
type: [Number],
validate: {
validator: function (v) {
return Array.isArray(v) && v.every(size => Number.isInteger(size));
},
message: 'Sizes must be an array of integers',
},
default: [],
},
tags: {
type: [String],
default: [],
validate: {
validator: function (v) {
return Array.isArray(v) && v.every(tag => typeof tag === 'string');
},
message: 'Tags must be an array of strings',
},
},
ratings: {
averageRating: {
type: Number,
Expand Down
49 changes: 27 additions & 22 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 19 additions & 15 deletions backend/scripts/products/generateProducts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { faker } = require('@faker-js/faker');
const fs = require('node:fs');
const existingData = require('./products.json');

// Array of possible colors
const colors = [
Expand All @@ -14,17 +15,19 @@ const colors = [
'Black',
'White',
];
const sizes = [38, 39, 40, 42, 44];

// Function to create a product
function createProduct() {

const generateProductFromJson = (jsonData) => {
return {
name: faker.commerce.productName(),
description: faker.lorem.paragraph(),
price: Number.parseFloat(faker.commerce.price()),
category: faker.commerce.department(),
name: jsonData.product_name || faker.commerce.productName(),
description: jsonData.meta_description || faker.lorem.paragraph(),
price: jsonData.marked_price || Number.parseFloat(faker.number.int({ min: 1200, max: 5600 })),
discounted_price: jsonData.discounted_price || Number.parseFloat(faker.number.int({ min: 50, max: 4000 })),
category: jsonData.brand_tag || faker.commerce.department(),
stock: faker.number.int({ min: 0, max: 100 }),
imageUrl: `https://via.placeholder.com/150?text=${faker.commerce.productName()}`,
brand: faker.company.name(),
imageUrl: jsonData.img_link || `https://via.placeholder.com/150?text=${faker.commerce.productName()}`,
brand: jsonData.brand_tag || faker.company.name(),
weight: Number.parseFloat((Math.random() * 10 + 1).toFixed(2)),
dimensions: {
length: Number.parseFloat(faker.number.int({ min: 1, max: 100 })),
Expand All @@ -33,23 +36,24 @@ function createProduct() {
},
material: faker.commerce.productMaterial(),
color: colors[Math.floor(Math.random() * colors.length)],
sizes: sizes.filter(() => Math.random() < 0.5), // Random selection of sizes
tags: jsonData.tags || faker.commerce.productAdjective().split(' '), // Generating some random words as tags
ratings: {
averageRating: Number.parseFloat(
faker.number.int({ min: 1, max: 5, precision: 0.1 })
),
numberOfReviews: faker.number.int({ min: 0, max: 500 }),
averageRating: jsonData.rating || Number.parseFloat(faker.number.int({ min: 1, max: 5, precision: 0.1 })),
numberOfReviews: jsonData.rating_count || faker.number.int({ min: 0, max: 500 }),
},
isActive: faker.datatype.boolean(),
createdAt: faker.date.past(),
updatedAt: faker.date.past(),
};
}
};

// Generate an array of 200 products
const products = Array.from({ length: 1000 }, createProduct);
const products = existingData.map(generateProductFromJson);
// const products = Array.from({ length: 1000 }, createProduct);

// Write the JSON to a file
fs.writeFile('products.json', JSON.stringify(products, null, 2), (err) => {
fs.writeFile('generatedProducts.json', JSON.stringify(products, null, 2), (err) => {
if (err) throw err;
console.log('products.json has been saved!');
});
Loading

0 comments on commit b177945

Please sign in to comment.