ibrohm commited on
Commit
c23d5cf
Β·
1 Parent(s): 090858a

Refactor order flow to In-Store Pickup model (remove address, update statuses)

Browse files
Files changed (1) hide show
  1. bot/bot.js +9 -9
bot/bot.js CHANGED
@@ -439,8 +439,8 @@ if (process.env.BOT_TOKEN && process.env.BOT_TOKEN !== 'YOUR_TELEGRAM_BOT_TOKEN'
439
  for (const o of orders) {
440
  let productsText = "";
441
  o.products.forEach(p => { productsText += `β€” ${p.name} (${p.quantity} ta) \n`; });
442
- let statusEmoji = o.status === 'Kutilmoqda' ? '⏳' : o.status === 'Yetkazildi' ? 'βœ…' : '🚚';
443
- const msg = `🧾 *ID:* \`${o._id}\`\nπŸ‘€ Mijoz: *${o.customerName}*\nπŸ“ž Tel: ${o.phone}\nπŸ“ Manz.: ${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
  }
@@ -460,9 +460,9 @@ if (process.env.BOT_TOKEN && process.env.BOT_TOKEN !== 'YOUR_TELEGRAM_BOT_TOKEN'
460
  const orderId = ctx.match[2];
461
 
462
  let newStatus = 'Kutilmoqda';
463
- if (action === 'accept') newStatus = 'Qabul qilindi';
464
- if (action === 'ship') newStatus = 'Yo\'lga chiqdi';
465
- if (action === 'deliver') newStatus = 'Yetkazildi';
466
  if (action === 'cancel') newStatus = 'Bekor qilindi';
467
 
468
  try {
@@ -1046,7 +1046,7 @@ if (process.env.BOT_TOKEN && process.env.BOT_TOKEN !== 'YOUR_TELEGRAM_BOT_TOKEN'
1046
  productsText += `β€” ${p.name} (${p.quantity} ta) x ${formatPrice(p.price)}\n`;
1047
  });
1048
 
1049
- const statusEmoji = order.status === 'Kutilmoqda' ? '⏳' : order.status === 'Yetkazildi' ? 'βœ…' : '🚚';
1050
  const msg = `🧾 *TOPILDI β€” ID:* \`${order._id}\`\n${thinLine}\n` +
1051
  `πŸ‘€ Mijoz: *${order.customerName}*\nπŸ“ž Tel: ${order.phone}\n\nπŸ“ *Tovarlar:*\n${productsText}\n` +
1052
  `πŸ’° *Jami summa:* ${formatPrice(order.totalAmount)} so'm\n\n` +
@@ -1418,11 +1418,11 @@ const orderStatusButtonsForNotify = (orderId, currentStatus) => {
1418
  const s = (label, status) => currentStatus === status ? `βœ… ${label}` : label;
1419
  return Markup.inlineKeyboard([
1420
  [
1421
- Markup.button.callback(s('πŸ“₯ Qabul', 'Qabul qilindi'), `order_status_accept_${orderId}`),
1422
- Markup.button.callback(s('🚚 Yo\'lda', 'Yo\'lga chiqdi'), `order_status_ship_${orderId}`)
1423
  ],
1424
  [
1425
- Markup.button.callback(s('🏁 Yetkazildi', 'Yetkazildi'), `order_status_deliver_${orderId}`),
1426
  Markup.button.callback(s('❌ Bekor', 'Bekor qilindi'), `order_status_cancel_${orderId}`)
1427
  ]
1428
  ]);
 
439
  for (const o of orders) {
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
  }
 
460
  const orderId = ctx.match[2];
461
 
462
  let newStatus = 'Kutilmoqda';
463
+ if (action === 'accept') newStatus = 'Yig\'ilmoqda';
464
+ if (action === 'ship') newStatus = 'Olib ketishga tayyor';
465
+ if (action === 'deliver') newStatus = 'Xaridorga topshirildi';
466
  if (action === 'cancel') newStatus = 'Bekor qilindi';
467
 
468
  try {
 
1046
  productsText += `β€” ${p.name} (${p.quantity} ta) x ${formatPrice(p.price)}\n`;
1047
  });
1048
 
1049
+ const statusEmoji = order.status === 'Kutilmoqda' ? '⏳' : order.status === 'Xaridorga topshirildi' ? 'βœ…' : order.status === 'Olib ketishga tayyor' ? 'πŸ›' : 'πŸ“₯';
1050
  const msg = `🧾 *TOPILDI β€” ID:* \`${order._id}\`\n${thinLine}\n` +
1051
  `πŸ‘€ Mijoz: *${order.customerName}*\nπŸ“ž Tel: ${order.phone}\n\nπŸ“ *Tovarlar:*\n${productsText}\n` +
1052
  `πŸ’° *Jami summa:* ${formatPrice(order.totalAmount)} so'm\n\n` +
 
1418
  const s = (label, status) => currentStatus === status ? `βœ… ${label}` : label;
1419
  return Markup.inlineKeyboard([
1420
  [
1421
+ Markup.button.callback(s('πŸ“₯ Yig\'ish', 'Yig\'ilmoqda'), `order_status_accept_${orderId}`),
1422
+ Markup.button.callback(s('πŸ› Tayyor', 'Olib ketishga tayyor'), `order_status_ship_${orderId}`)
1423
  ],
1424
  [
1425
+ Markup.button.callback(s('βœ… Topshirildi', 'Xaridorga topshirildi'), `order_status_deliver_${orderId}`),
1426
  Markup.button.callback(s('❌ Bekor', 'Bekor qilindi'), `order_status_cancel_${orderId}`)
1427
  ]
1428
  ]);