Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes PR #502 #528

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading