Spaces:
Paused
Paused
Deploy Bot commited on
Commit ·
bfde415
1
Parent(s): 6517b12
Fix: Add DB Self-Healing and CastError Validation
Browse files- src/controllers/adminController.js +3 -0
- src/database/db.js +14 -1
src/controllers/adminController.js
CHANGED
|
@@ -104,6 +104,9 @@ exports.viewOrder = async (ctx, orderId) => {
|
|
| 104 |
try {
|
| 105 |
const i18n = ctx.i18n;
|
| 106 |
const id = parseInt(orderId);
|
|
|
|
|
|
|
|
|
|
| 107 |
const order = await Order.findOne({ id: id });
|
| 108 |
|
| 109 |
if (!order) return ctx.answerCbQuery("Buyurtma topilmadi."); // Low Priority to localize this tiny string fallback
|
|
|
|
| 104 |
try {
|
| 105 |
const i18n = ctx.i18n;
|
| 106 |
const id = parseInt(orderId);
|
| 107 |
+
|
| 108 |
+
if (isNaN(id)) return ctx.answerCbQuery("❌ Invalid Order ID");
|
| 109 |
+
|
| 110 |
const order = await Order.findOne({ id: id });
|
| 111 |
|
| 112 |
if (!order) return ctx.answerCbQuery("Buyurtma topilmadi."); // Low Priority to localize this tiny string fallback
|
src/database/db.js
CHANGED
|
@@ -1,10 +1,23 @@
|
|
| 1 |
const mongoose = require('mongoose');
|
| 2 |
-
const config = require('../config');
|
| 3 |
|
| 4 |
const connectDB = async () => {
|
| 5 |
try {
|
| 6 |
await mongoose.connect(process.env.MONGO_URI);
|
| 7 |
console.log('✅ MongoDB ulandi');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
} catch (err) {
|
| 9 |
console.error('❌ MongoDB ulanishda xatolik:', err);
|
| 10 |
process.exit(1);
|
|
|
|
| 1 |
const mongoose = require('mongoose');
|
|
|
|
| 2 |
|
| 3 |
const connectDB = async () => {
|
| 4 |
try {
|
| 5 |
await mongoose.connect(process.env.MONGO_URI);
|
| 6 |
console.log('✅ MongoDB ulandi');
|
| 7 |
+
|
| 8 |
+
// SELF-HEALING: Drop obsolete index 'orderId_1' if it exists to prevent E11000 error
|
| 9 |
+
try {
|
| 10 |
+
const collection = mongoose.connection.collection('orders');
|
| 11 |
+
const indexes = await collection.indexes();
|
| 12 |
+
const obsoleteIndex = indexes.find(idx => idx.name === 'orderId_1');
|
| 13 |
+
if (obsoleteIndex) {
|
| 14 |
+
console.log("⚠️ Found obsolete index 'orderId_1'. Dropping...");
|
| 15 |
+
await collection.dropIndex('orderId_1');
|
| 16 |
+
console.log("✅ Obsolete index 'orderId_1' dropped successfully.");
|
| 17 |
+
}
|
| 18 |
+
} catch (dbErr) {
|
| 19 |
+
console.error("⚠️ Index Check Error (Non-fatal):", dbErr.message);
|
| 20 |
+
}
|
| 21 |
} catch (err) {
|
| 22 |
console.error('❌ MongoDB ulanishda xatolik:', err);
|
| 23 |
process.exit(1);
|