Skip to content

Commit ff72fca

Browse files
committed
fix(validations): fix named export
As community may sometimes be null, I edited the isDisputeSolver function to accept null, so we don't have to do a null check over it. ``` bot/validations.ts:97:38 - error TS2345: Argument of type '(ICommunity & { _id: ObjectId; }) | null' is not assignable to parameter of type 'ICommunity'. Type 'null' is not assignable to type 'ICommunity'. 97 const isSolver = isDisputeSolver(community, user); ~~~~~~~~~ Found 1 error in bot/validations.ts:97 ```
1 parent d9e4720 commit ff72fca

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

bot/validations.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { IOrder } from "../models/order";
66
import { Telegraf } from "telegraf";
77

88
const { parsePaymentRequest } = require('invoices');
9-
const { ObjectId } = require('mongoose').Types;
9+
import { Types } from 'mongoose';
1010
import * as messages from './messages';
1111
import { Order, User, Community } from '../models';
1212
import { isIso4217, isDisputeSolver } from '../util';
@@ -94,7 +94,6 @@ const validateAdmin = async (ctx: MainContext, id?: string) => {
9494
if (user.default_community_id)
9595
community = await Community.findOne({ _id: user.default_community_id });
9696

97-
if (community === null) throw Error("Community was not found in DB");
9897
const isSolver = isDisputeSolver(community, user);
9998

10099
if (!user.admin && !isSolver)
@@ -593,7 +592,7 @@ const validateParams = async (ctx: MainContext, paramNumber: number, errOutputSt
593592

594593
const validateObjectId = async (ctx: MainContext, id: string) => {
595594
try {
596-
if (!ObjectId.isValid(id)) {
595+
if (!Types.ObjectId.isValid(id)) {
597596
await messages.notValidIdMessage(ctx);
598597
return false;
599598
}
@@ -647,7 +646,7 @@ const isBannedFromCommunity = async (user: UserDocument, communityId: string) =>
647646
}
648647
};
649648

650-
module.exports = {
649+
export {
651650
validateSellOrder,
652651
validateBuyOrder,
653652
validateUser,

util/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ const getDetailedOrder = (i18n: I18nContext, order: IOrder, buyer: UserDocument,
382382
};
383383

384384
// We need to know if this user is a dispute solver for this community
385-
const isDisputeSolver = (community: ICommunity, user: UserDocument) => {
385+
const isDisputeSolver = (community: ICommunity | null, user: UserDocument) => {
386386
if (!community || !user) {
387387
return false;
388388
}

0 commit comments

Comments
 (0)