Deploy Bot commited on
Commit
0876dd4
Β·
1 Parent(s): 1253e7a

Fix_Category_Count_And_Add_Nav_Buttons

Browse files
src/controllers/userController.js CHANGED
@@ -132,11 +132,13 @@ exports.showCategories = async (ctx) => {
132
  for (const c of categories) {
133
  // Find all subcategories for this root
134
  const subCats = await Category.find({ parent: c.id });
 
135
  const subCatIds = subCats.map(sub => sub.id);
136
 
137
  // Count products in subcategories (and directly in root if any)
 
138
  const count = await Product.countDocuments({
139
- category: { $in: [...subCatIds, c.id] }
140
  });
141
 
142
  buttons.push([Markup.button.callback(`${c.name} (${count})`, `cat_${c.id}`)]);
@@ -164,7 +166,8 @@ exports.showSubCategories = async (ctx, parentId) => {
164
 
165
  const buttons = [];
166
  for (const c of subCats) {
167
- const count = await Product.countDocuments({ category: c.id });
 
168
  buttons.push([Markup.button.callback(`${c.name} (${count})`, `cat_${c.id}`)]);
169
  }
170
 
 
132
  for (const c of categories) {
133
  // Find all subcategories for this root
134
  const subCats = await Category.find({ parent: c.id });
135
+ const subCatNames = subCats.map(sub => sub.name); // Use Names because Product stores Category Name
136
  const subCatIds = subCats.map(sub => sub.id);
137
 
138
  // Count products in subcategories (and directly in root if any)
139
+ // Products are saved with Category 'name' (string) not ID.
140
  const count = await Product.countDocuments({
141
+ category: { $in: [...subCatNames, c.name] }
142
  });
143
 
144
  buttons.push([Markup.button.callback(`${c.name} (${count})`, `cat_${c.id}`)]);
 
166
 
167
  const buttons = [];
168
  for (const c of subCats) {
169
+ // Count by Name
170
+ const count = await Product.countDocuments({ category: c.name });
171
  buttons.push([Markup.button.callback(`${c.name} (${count})`, `cat_${c.id}`)]);
172
  }
173
 
src/scenes/admin/broadcast.js CHANGED
@@ -17,6 +17,11 @@ const broadcastScene = new Scenes.WizardScene(
17
  return;
18
  }
19
 
 
 
 
 
 
20
  ctx.wizard.state.message = ctx.message; // Save the message object
21
 
22
  // Show Preview (Forward copy)
@@ -25,6 +30,7 @@ const broadcastScene = new Scenes.WizardScene(
25
 
26
  ctx.reply("Yuborishni tasdiqlaysizmi?", Markup.inlineKeyboard([
27
  Markup.button.callback("βœ… Yuborish", "confirm_send"),
 
28
  Markup.button.callback("❌ Bekor qilish", "cancel_send")
29
  ]));
30
  return ctx.wizard.next();
@@ -38,6 +44,10 @@ const broadcastScene = new Scenes.WizardScene(
38
  ctx.scene.leave();
39
  userController.start(ctx, "Reklama bekor qilindi.");
40
  return;
 
 
 
 
41
  } else if (action === 'confirm_send') {
42
  await ctx.deleteMessage();
43
  ctx.reply("πŸš€ Xabar yuborilmoqda...");
 
17
  return;
18
  }
19
 
20
+ if (ctx.message && ctx.message.text === '⬅️ Ortga') {
21
+ ctx.reply("πŸ“’ Reklama xabarini yuboring (Matn, Rasm yoki Video):", Markup.keyboard([['❌ Bekor qilish']]).resize());
22
+ return ctx.wizard.back();
23
+ }
24
+
25
  ctx.wizard.state.message = ctx.message; // Save the message object
26
 
27
  // Show Preview (Forward copy)
 
30
 
31
  ctx.reply("Yuborishni tasdiqlaysizmi?", Markup.inlineKeyboard([
32
  Markup.button.callback("βœ… Yuborish", "confirm_send"),
33
+ Markup.button.callback("⬅️ O'zgartirish", "back_to_start"),
34
  Markup.button.callback("❌ Bekor qilish", "cancel_send")
35
  ]));
36
  return ctx.wizard.next();
 
44
  ctx.scene.leave();
45
  userController.start(ctx, "Reklama bekor qilindi.");
46
  return;
47
+ } else if (action === 'back_to_start') {
48
+ ctx.deleteMessage();
49
+ ctx.reply("πŸ“’ Reklama xabarini yuboring (Matn, Rasm yoki Video):", Markup.keyboard([['❌ Bekor qilish']]).resize());
50
+ return ctx.wizard.back();
51
  } else if (action === 'confirm_send') {
52
  await ctx.deleteMessage();
53
  ctx.reply("πŸš€ Xabar yuborilmoqda...");
src/scenes/admin/settings.js CHANGED
@@ -42,7 +42,7 @@ const settingsScene = new Scenes.WizardScene(
42
  ctx.wizard.state.addressText = ctx.message.text;
43
  ctx.reply("πŸ“ Endi lokatsiyasini yuboring (Pastdagi tugma yoki attachment orqali):", Markup.keyboard([
44
  [Markup.button.locationRequest("πŸ“ Lokatsiya yuborish")],
45
- ['❌ Bekor qilish']
46
  ]).resize());
47
  return ctx.wizard.next();
48
  },
@@ -54,6 +54,10 @@ const settingsScene = new Scenes.WizardScene(
54
  return;
55
  }
56
 
 
 
 
 
57
  if (!ctx.message.location) {
58
  return ctx.reply("πŸ“ Iltimos, lokatsiya yuboring.");
59
  }
 
42
  ctx.wizard.state.addressText = ctx.message.text;
43
  ctx.reply("πŸ“ Endi lokatsiyasini yuboring (Pastdagi tugma yoki attachment orqali):", Markup.keyboard([
44
  [Markup.button.locationRequest("πŸ“ Lokatsiya yuborish")],
45
+ ['⬅️ Ortga', '❌ Bekor qilish']
46
  ]).resize());
47
  return ctx.wizard.next();
48
  },
 
54
  return;
55
  }
56
 
57
+ if (ctx.message.text === '⬅️ Ortga') {
58
+ ctx.reply("πŸ“ Yangi manzil matnini kiriting:", Markup.keyboard([['❌ Bekor qilish']]).resize());
59
+ return ctx.wizard.back(); // Go back to Step 3
60
+ }
61
  if (!ctx.message.location) {
62
  return ctx.reply("πŸ“ Iltimos, lokatsiya yuboring.");
63
  }