Skip to content

Commit

Permalink
fix(validations): fix named export
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
Mersho committed Nov 1, 2023
1 parent d9e4720 commit ff72fca
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
7 changes: 3 additions & 4 deletions bot/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { IOrder } from "../models/order";
import { Telegraf } from "telegraf";

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

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

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

const validateObjectId = async (ctx: MainContext, id: string) => {
try {
if (!ObjectId.isValid(id)) {
if (!Types.ObjectId.isValid(id)) {
await messages.notValidIdMessage(ctx);
return false;
}
Expand Down Expand Up @@ -647,7 +646,7 @@ const isBannedFromCommunity = async (user: UserDocument, communityId: string) =>
}
};

module.exports = {
export {
validateSellOrder,
validateBuyOrder,
validateUser,
Expand Down
2 changes: 1 addition & 1 deletion util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ const getDetailedOrder = (i18n: I18nContext, order: IOrder, buyer: UserDocument,
};

// We need to know if this user is a dispute solver for this community
const isDisputeSolver = (community: ICommunity, user: UserDocument) => {
const isDisputeSolver = (community: ICommunity | null, user: UserDocument) => {
if (!community || !user) {
return false;
}
Expand Down

0 comments on commit ff72fca

Please sign in to comment.