Skip to content

Commit

Permalink
refactor: correcting a bad practice
Browse files Browse the repository at this point in the history
  • Loading branch information
Mersho authored and webwarrior-ws committed Aug 26, 2024
1 parent ba9ac8b commit eabf549
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions bot/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ const initialize = (botToken: string, options: Partial<Telegraf.Options<MainCont
const [val] = await validateParams(ctx, 2, '\\<_on/off_\\>');
if (!val) return;
let config = await Config.findOne();
if (!config) {
if (config === null) {
config = new Config();
}
config.maintenance = false;
Expand Down Expand Up @@ -327,7 +327,7 @@ const initialize = (botToken: string, options: Partial<Telegraf.Options<MainCont
if (!(await validateObjectId(ctx, orderId))) return;
const order = await Order.findOne({ _id: orderId });

if (!order) return;
if (order === null) return;

// We look for a dispute for this order
const dispute = await Dispute.findOne({ order_id: order._id });
Expand Down Expand Up @@ -465,7 +465,7 @@ const initialize = (botToken: string, options: Partial<Telegraf.Options<MainCont
if (!(await validateObjectId(ctx, orderId))) return;

const order = await Order.findOne({ _id: orderId });
if (!order) return;
if (order === null) return;

// Check if the order status is already PAID_HOLD_INVOICE
if (order.status === 'PAID_HOLD_INVOICE') {
Expand Down Expand Up @@ -529,7 +529,7 @@ const initialize = (botToken: string, options: Partial<Telegraf.Options<MainCont
if (!(await validateObjectId(ctx, orderId))) return;
const order = await Order.findOne({ _id: orderId });

if (!order) return;
if (order === null) return;

const buyer = await User.findOne({ _id: order.buyer_id });
const seller = await User.findOne({ _id: order.seller_id });
Expand All @@ -547,7 +547,7 @@ const initialize = (botToken: string, options: Partial<Telegraf.Options<MainCont
if (!(await validateObjectId(ctx, orderId))) return;
const order = await Order.findOne({ _id: orderId });

if (!order) return;
if (order === null) return;
if (!order.hash) return;

const invoice = await getInvoice({ hash: order.hash });
Expand All @@ -571,7 +571,7 @@ const initialize = (botToken: string, options: Partial<Telegraf.Options<MainCont

const order = await Order.findOne({ hash });

if (!order) return;
if (order === null) return;
await subscribeInvoice(bot, hash, true);
ctx.reply(`hash resubscribed`);
} catch (error: any) {
Expand Down Expand Up @@ -641,7 +641,7 @@ const initialize = (botToken: string, options: Partial<Telegraf.Options<MainCont
const user = await User.findOne({
$or: [{ username }, { tg_id: username }],
});
if (!user) {
if (user === null) {
await messages.notFoundUserMessage(ctx);
return;
}
Expand Down Expand Up @@ -685,7 +685,7 @@ const initialize = (botToken: string, options: Partial<Telegraf.Options<MainCont
const user = await User.findOne({
$or: [{ username }, { tg_id: username }],
});
if (!user) {
if (user === null) {
await messages.notFoundUserMessage(ctx);
return;
}
Expand Down
10 changes: 5 additions & 5 deletions bot/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const validateSuperAdmin = async (ctx: MainContext, id?: string) => {
const user = await User.findOne({ tg_id: tgUserId });
// If the user never started the bot we can't send messages
// to that user, so we do nothing
if (!user) return;
if (user === null) return;

if (!user.admin) return await messages.notAuthorized(ctx, tgUserId.toString());

Expand All @@ -90,7 +90,7 @@ const validateAdmin = async (ctx: MainContext, id?: string) => {
const user = await User.findOne({ tg_id: tgUserId });
// If the user never started the bot we can't send messages
// to that user, so we do nothing
if (!user) return;
if (user === null) return;

let community = null;
if (user.default_community_id)
Expand Down Expand Up @@ -511,7 +511,7 @@ const validateReleaseOrder = async (ctx: MainContext, user: UserDocument, orderI
}
order = await Order.findOne(where);

if (!order) {
if (order === null) {
await messages.notActiveOrderMessage(ctx);
return false;
}
Expand All @@ -535,7 +535,7 @@ const validateDisputeOrder = async (ctx: MainContext, user: UserDocument, orderI

const order = await Order.findOne(where);

if (!order) {
if (order === null) {
await messages.notActiveOrderMessage(ctx);
return false;
}
Expand All @@ -560,7 +560,7 @@ const validateFiatSentOrder = async (ctx: MainContext, user: UserDocument, order
where._id = orderId;
}
const order = await Order.findOne(where);
if (!order) {
if (order === null) {
await messages.notActiveOrderMessage(ctx);
return false;
}
Expand Down

0 comments on commit eabf549

Please sign in to comment.