ibrohm commited on
Commit
f37235c
Β·
1 Parent(s): acb1bd4

Refactor: Change address to comment to reflect in-store pickup model + Code cleanup

Browse files
Files changed (3) hide show
  1. bot/bot.js +2 -17
  2. index.js +4 -4
  3. models/Order.js +2 -2
bot/bot.js CHANGED
@@ -440,7 +440,7 @@ if (process.env.BOT_TOKEN && process.env.BOT_TOKEN !== 'YOUR_TELEGRAM_BOT_TOKEN'
440
  let productsText = "";
441
  o.products.forEach(p => { productsText += `β€” ${p.name} (${p.quantity} ta) \n`; });
442
  let statusEmoji = o.status === 'Kutilmoqda' ? '⏳' : o.status === 'Xaridorga topshirildi' ? 'βœ…' : o.status === 'Olib ketishga tayyor' ? 'πŸ›' : 'πŸ“₯';
443
- const msg = `🧾 *ID:* \`${o._id}\`\nπŸ‘€ Mijoz: *${o.customerName}*\nπŸ“ž Tel: ${o.phone}\nπŸ“ Izoh: ${o.address}\n\nπŸ“ *Tovarlar:*\n${productsText}\nπŸ’° *Jami:* ${formatPrice(o.totalAmount)} so'm\nπŸ“Œ *Holati:* ${statusEmoji} ${o.status}\nπŸ•’ Vaqt: ${formatDate(o.createdAt)}`;
444
 
445
  await ctx.reply(msg, { parse_mode: 'Markdown', ...orderStatusButtonsForNotify(o._id, o.status) });
446
  }
@@ -540,7 +540,7 @@ if (process.env.BOT_TOKEN && process.env.BOT_TOKEN !== 'YOUR_TELEGRAM_BOT_TOKEN'
540
  `Quyidagi bo'limlar orqali do'konni to'liq boshqarasiz:\n\n` +
541
  `πŸ“¦ *Tovarlar* - Tahrirlash, O'chirish va Rasm o'zgartirish.\n` +
542
  `πŸ“ *Kategoriyalar* - Guruhlar yaratish, nomini o'zgartirish.\n` +
543
- `πŸ“‹ *Buyurtmalar* - Holatini (qabul, yo'lda) tekshirish.\n` +
544
  `πŸ” *Qidirish* - Ismi bilan izlab topib tahrirlash.\n` +
545
  `πŸ“Š *Statistika* - Tushumlar va statistika.`;
546
  ctx.reply(msg, { parse_mode: 'Markdown' });
@@ -1212,21 +1212,6 @@ if (process.env.BOT_TOKEN && process.env.BOT_TOKEN !== 'YOUR_TELEGRAM_BOT_TOKEN'
1212
  return;
1213
  }
1214
 
1215
- // AI Banner (eski usul backup)
1216
- if (state.step === 'ai_banner_prompt') {
1217
- try {
1218
- await ctx.reply('🧠 Gemini orqali prompt tayyorlanmoqda...');
1219
- const finalPrompt = await enhancePromptWithGemini(text);
1220
- appState[userId] = { step: 'ai_generating', lastPrompt: text, finalPrompt };
1221
- await generateAIBannerVariants(ctx, finalPrompt, text);
1222
- } catch (e) {
1223
- console.error("ai_banner_prompt error:", e);
1224
- ctx.reply('❌ Kechirasiz, tarmoqda xatolik yuz berdi. Iltimos qayta urining.', getMainMenu());
1225
- delete appState[userId];
1226
- }
1227
- return;
1228
- }
1229
-
1230
  // Qidiruv
1231
  if (state.step === 'searching_product') {
1232
  try {
 
440
  let productsText = "";
441
  o.products.forEach(p => { productsText += `β€” ${p.name} (${p.quantity} ta) \n`; });
442
  let statusEmoji = o.status === 'Kutilmoqda' ? '⏳' : o.status === 'Xaridorga topshirildi' ? 'βœ…' : o.status === 'Olib ketishga tayyor' ? 'πŸ›' : 'πŸ“₯';
443
+ const msg = `🧾 *ID:* \`${o._id}\`\nπŸ‘€ Mijoz: *${o.customerName}*\nπŸ“ž Tel: ${o.phone}\nπŸ“ Izoh: ${o.comment}\n\nπŸ“ *Tovarlar:*\n${productsText}\nπŸ’° *Jami:* ${formatPrice(o.totalAmount)} so'm\nπŸ“Œ *Holati:* ${statusEmoji} ${o.status}\nπŸ•’ Vaqt: ${formatDate(o.createdAt)}`;
444
 
445
  await ctx.reply(msg, { parse_mode: 'Markdown', ...orderStatusButtonsForNotify(o._id, o.status) });
446
  }
 
540
  `Quyidagi bo'limlar orqali do'konni to'liq boshqarasiz:\n\n` +
541
  `πŸ“¦ *Tovarlar* - Tahrirlash, O'chirish va Rasm o'zgartirish.\n` +
542
  `πŸ“ *Kategoriyalar* - Guruhlar yaratish, nomini o'zgartirish.\n` +
543
+ `πŸ“‹ *Buyurtmalar* - Holatini (yig'ilmoqda, tayyor) tasdiqlash.\n` +
544
  `πŸ” *Qidirish* - Ismi bilan izlab topib tahrirlash.\n` +
545
  `πŸ“Š *Statistika* - Tushumlar va statistika.`;
546
  ctx.reply(msg, { parse_mode: 'Markdown' });
 
1212
  return;
1213
  }
1214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1215
  // Qidiruv
1216
  if (state.step === 'searching_product') {
1217
  try {
index.js CHANGED
@@ -159,10 +159,10 @@ app.post('/api/validate-cart', async (req, res) => {
159
 
160
  // Yangi buyurtma yaratish
161
  app.post('/api/orders', async (req, res) => {
162
- const { customerName, phone, address, products, totalAmount } = req.body;
163
 
164
  // ── Validatsiya ──
165
- if (!customerName || !phone || !address) {
166
  return res.status(400).json({ message: 'Barcha maydonlarni to\'ldiring' });
167
  }
168
  if (!products || !Array.isArray(products) || products.length === 0) {
@@ -186,7 +186,7 @@ app.post('/api/orders', async (req, res) => {
186
  const order = new Order({
187
  customerName,
188
  phone,
189
- address,
190
  products,
191
  totalAmount
192
  });
@@ -200,7 +200,7 @@ app.post('/api/orders', async (req, res) => {
200
  productsText += `β€” ${p.name}${sizeStr} (${p.quantity} x ${Number(p.price).toLocaleString()}) \n`;
201
  });
202
 
203
- const msg = `πŸ“¦ *YANGI BUYURTMA!*\n\nπŸ‘€ Mijoz: ${customerName}\nπŸ“ž Tel: ${phone}\nπŸ“ Manzil: ${address}\n\nπŸ“ Tovarlar:\n${productsText}\nπŸ’° Umumiy: ${Number(totalAmount).toLocaleString()} so'm`;
204
 
205
  await notifyAdmin(msg, createdOrder._id.toString());
206
 
 
159
 
160
  // Yangi buyurtma yaratish
161
  app.post('/api/orders', async (req, res) => {
162
+ const { customerName, phone, comment, products, totalAmount } = req.body;
163
 
164
  // ── Validatsiya ──
165
+ if (!customerName || !phone || !comment) {
166
  return res.status(400).json({ message: 'Barcha maydonlarni to\'ldiring' });
167
  }
168
  if (!products || !Array.isArray(products) || products.length === 0) {
 
186
  const order = new Order({
187
  customerName,
188
  phone,
189
+ comment,
190
  products,
191
  totalAmount
192
  });
 
200
  productsText += `β€” ${p.name}${sizeStr} (${p.quantity} x ${Number(p.price).toLocaleString()}) \n`;
201
  });
202
 
203
+ const msg = `πŸ“¦ *YANGI BUYURTMA!*\n\nπŸ‘€ Mijoz: ${customerName}\nπŸ“ž Tel: ${phone}\nπŸ“ Izoh: ${comment}\n\nπŸ“ Tovarlar:\n${productsText}\nπŸ’° Umumiy: ${Number(totalAmount).toLocaleString()} so'm`;
204
 
205
  await notifyAdmin(msg, createdOrder._id.toString());
206
 
models/Order.js CHANGED
@@ -5,7 +5,7 @@ const orderSchema = mongoose.Schema(
5
  userId: { type: String, required: false },
6
  customerName: { type: String, required: true },
7
  phone: { type: String, required: true },
8
- address: { type: String, required: true },
9
  products: [
10
  {
11
  productId: { type: mongoose.Schema.Types.ObjectId, ref: 'Product', required: true },
@@ -16,7 +16,7 @@ const orderSchema = mongoose.Schema(
16
  }
17
  ],
18
  totalAmount: { type: Number, required: true },
19
- status: { type: String, default: 'Kutilmoqda' } // Kutilmoqda, Yo'lga chiqdi, Yetkazildi
20
  },
21
  {
22
  timestamps: true,
 
5
  userId: { type: String, required: false },
6
  customerName: { type: String, required: true },
7
  phone: { type: String, required: true },
8
+ comment: { type: String, required: true },
9
  products: [
10
  {
11
  productId: { type: mongoose.Schema.Types.ObjectId, ref: 'Product', required: true },
 
16
  }
17
  ],
18
  totalAmount: { type: Number, required: true },
19
+ status: { type: String, default: 'Kutilmoqda' } // Kutilmoqda, Yig'ilmoqda, Olib ketishga tayyor, Xaridorga topshirildi, Bekor qilindi
20
  },
21
  {
22
  timestamps: true,