Skip to content

Commit

Permalink
refactor: removes 'orders' field from the ICommunity interface
Browse files Browse the repository at this point in the history
The 'orders' field is not part of the Mongoose document, but rather it's something that's calculated on-the-fly
as part of the response to the `/findcomms` command for each community. Converting the mongoose document to a
plain object gets rid of the TSC errors without having to introduce an 'orders' field to the ICommunity interface.

This solution is preferred as the ICommunity interface should ideally mirror what's stored in the database.
  • Loading branch information
bilthon committed Nov 21, 2024
1 parent 7540d8a commit 1eff73a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
5 changes: 3 additions & 2 deletions bot/modules/community/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ async function findCommunities(currency) {
});
const orderCount = await getOrderCountByCommunity();
return communities.map(comm => {
comm.orders = orderCount[comm.id] || 0;
return comm;
const plainCommunity = comm.toObject();
plainCommunity.orders = orderCount[comm.id] || 0;
return plainCommunity;
});
}

Expand Down
1 change: 0 additions & 1 deletion models/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ export interface ICommunity extends Document {
order_channels: Types.DocumentArray<IOrderChannel>;
fee: number;
earnings: number;
orders: number;
orders_to_redeem: number;
dispute_channel: string;
solvers: Types.DocumentArray<IUsernameId>;
Expand Down

0 comments on commit 1eff73a

Please sign in to comment.