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 committed Oct 25, 2023
1 parent 890e24b commit d07838e
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 @@ -210,7 +210,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 @@ -284,7 +284,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 @@ -396,7 +396,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 @@ -453,7 +453,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 @@ -471,7 +471,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 @@ -495,7 +495,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 @@ -557,7 +557,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 @@ -601,7 +601,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 @@ -68,7 +68,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 @@ -88,7 +88,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 @@ -475,7 +475,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 @@ -499,7 +499,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 @@ -524,7 +524,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 d07838e

Please sign in to comment.