From 1eff73a77ae2e5ba07dee64f39284531756233dd Mon Sep 17 00:00:00 2001 From: bilthon Date: Thu, 21 Nov 2024 14:20:12 -0500 Subject: [PATCH] refactor: removes 'orders' field from the ICommunity interface 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. --- bot/modules/community/commands.js | 5 +++-- models/community.ts | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bot/modules/community/commands.js b/bot/modules/community/commands.js index 1876914b..47e6f997 100644 --- a/bot/modules/community/commands.js +++ b/bot/modules/community/commands.js @@ -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; }); } diff --git a/models/community.ts b/models/community.ts index a5410fdf..09e34908 100644 --- a/models/community.ts +++ b/models/community.ts @@ -41,7 +41,6 @@ export interface ICommunity extends Document { order_channels: Types.DocumentArray; fee: number; earnings: number; - orders: number; orders_to_redeem: number; dispute_channel: string; solvers: Types.DocumentArray;