This commit is contained in:
NotII
2025-03-10 17:39:37 +00:00
parent c08df8919d
commit 20d5559832
69 changed files with 7676 additions and 78 deletions

View File

@@ -0,0 +1,55 @@
import mongoose from 'mongoose';
import dotenv from 'dotenv';
import Product from '../models/Product.model.js';
import logger from './logger.js';
// Load environment variables
dotenv.config();
// Connect to MongoDB
mongoose.connect(process.env.MONGO_URI)
.then(() => logger.info('MongoDB connected'))
.catch(err => {
logger.error('MongoDB connection error:', err);
process.exit(1);
});
async function disableStockTrackingForAllProducts() {
try {
logger.info('Disabling stock tracking for all products...');
const result = await Product.updateMany(
{}, // Empty filter matches all documents
{
stockTracking: false,
stockStatus: "in_stock" // Set a default status
}
);
logger.info(`Stock tracking disabled for ${result.modifiedCount} products out of ${result.matchedCount} total products`);
return result;
} catch (error) {
logger.error('Error disabling stock tracking:', error);
throw error;
} finally {
// Close database connection
mongoose.connection.close();
logger.info('Database connection closed');
}
}
// Execute the function if this script is run directly
if (process.argv[1].includes('disableStockTracking.js')) {
disableStockTrackingForAllProducts()
.then(() => {
logger.info('Script completed successfully');
process.exit(0);
})
.catch(err => {
logger.error('Script failed:', err);
process.exit(1);
});
}
export default disableStockTrackingForAllProducts;