Skip to content

Commit

Permalink
Fixes PR #502 (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
grunch authored May 16, 2024
1 parent d68ffd3 commit 04319f9
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
11 changes: 8 additions & 3 deletions bot/modules/orders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ const ordersActions = require('../../ordersActions');

const commands = require('./commands');
const messages = require('./messages');
const { tooManyPendingOrdersMessage } = require('../../messages');
const {
tooManyPendingOrdersMessage,
notOrdersMessage,
} = require('../../messages');
const {
takeOrderActionValidation,
takeOrderValidation,
Expand Down Expand Up @@ -54,8 +57,10 @@ exports.configure = bot => {

bot.command('listorders', userMiddleware, async ctx => {
try {
const orders = await ordersActions.getOrders(ctx, ctx.user);
if (!orders) return false;
const orders = await ordersActions.getOrders(ctx.user);
if (orders && orders.length === 0) {
return await notOrdersMessage(ctx);
}

const { text, extra } = await messages.listOrdersResponse(
orders,
Expand Down
10 changes: 2 additions & 8 deletions bot/ordersActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const getOrder = async (ctx, user, orderId) => {
}
};

const getOrders = async (ctx, user, status) => {
const getOrders = async (user, status) => {
try {
const where = {
$and: [
Expand All @@ -249,14 +249,8 @@ const getOrders = async (ctx, user, status) => {
];
where.$and.push({ $or });
}
const orders = await Order.find(where);

if (orders.length === 0) {
await messages.notOrdersMessage(ctx);
return false;
}

return orders;
return await Order.find(where);
} catch (error) {
logger.error(error);
}
Expand Down
10 changes: 6 additions & 4 deletions bot/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,15 @@ const initialize = (botToken: string, options: Partial<Telegraf.Options<MainCont
// pending orders are the ones that are not taken by another user
bot.command('cancelall', userMiddleware, async (ctx: MainContext) => {
try {
const pending_orders = await ordersActions.getOrders(ctx, ctx.user, 'PENDING');
const seller_orders = await ordersActions.getOrders(ctx, ctx.user, 'WAITING_BUYER_INVOICE');
const buyer_orders = await ordersActions.getOrders(ctx, ctx.user, 'WAITING_PAYMENT');
const pending_orders = await ordersActions.getOrders(ctx.user, 'PENDING');
const seller_orders = await ordersActions.getOrders(ctx.user, 'WAITING_BUYER_INVOICE');
const buyer_orders = await ordersActions.getOrders(ctx.user, 'WAITING_PAYMENT');

const orders = [...pending_orders, ...seller_orders, ...buyer_orders]

if (!orders) return;
if (orders.length === 0) {
return await messages.notOrdersMessage(ctx);
};

for (const order of orders) {

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 04319f9

Please sign in to comment.