Skip to content

Conversation

@Luquitasjeffrey
Copy link
Collaborator

@Luquitasjeffrey Luquitasjeffrey commented Jan 19, 2026

PR for issue #655
Continuation of the PR #687

Summary by CodeRabbit

  • Dependencies

    • Upgraded the database library to a newer major version for improved stability and features.
  • Refactor

    • Modernized data-access and deletion calls for more predictable behavior.
    • Strengthened public type definitions and index creation safety for increased reliability.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 19, 2026

Walkthrough

This PR updates Mongoose to v8, replaces deprecated query/deletion APIs (count → countDocuments, remove/delete → deleteOne), adds explicit .exec() on a query, extends TypeScript model interfaces with _id (and optional orders), refines index helper types, and updates Schema generics.

Changes

Cohort / File(s) Summary
Count → countDocuments
bot/modules/community/actions.ts, bot/modules/dispute/actions.ts, bot/modules/dispute/commands.ts, jobs/communities.ts
Replaced .count(...) calls with .countDocuments(...) while preserving predicates and control flow.
Deletion API changes (deleteOne)
bot/modules/community/commands.ts, jobs/check_solvers.ts, jobs/communities.ts, jobs/delete_published_orders.ts
Replaced document-level .remove() / .delete() calls with .deleteOne() for deletions.
Query exec added
bot/ordersActions.ts
Added .exec() to Order.findOne(where) to ensure an executed promise is returned.
Comparator fix
bot/modules/community/commands.ts
Adjusted community sorting to (a.orders ?? 0) - (b.orders ?? 0) to handle undefined orders.
Model typings: _id and orders
models/community.ts, models/order.ts, models/user.ts
Added _id: string to ICommunity/IOrder/UserDocument; added optional orders?: number to ICommunity.
Schema generic update
models/order.ts
Updated schema instantiation to new Schema<IOrder, mongoose.Model<IOrder>>({...}).
Index helper and SafeIndexOptions
models/indexes.ts
Introduced SafeIndexOptions (requires name, optional unique), added pre-check for existing indexes and adjusted createIndexSafely behavior/logging.
Dependency bump
package.json
Upgraded mongoose from 6.13.6 to ^8.17.1.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • grunch
  • Catrya

Poem

🐰
I hopped through fields of docs and rows,
Swapped old counts where new code grows,
Deleted safe, and exec'd the find,
Types now show the _id behind,
A twitch, a nibble — DB glows. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately and clearly describes the main change: updating Mongoose from version 6.13.6 to 8.17.1, which is the primary objective evident from the package.json changes and all related code updates.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
models/community.ts (1)

37-55: Avoid overriding Document._id as string

Document already defines _id as Types.ObjectId. Overriding it to string masks the actual type and creates inconsistency with how MongoDB stores IDs natively. Use Types.ObjectId to reflect the actual stored type and align with the base interface.

💡 Suggested type adjustment
-export interface ICommunity extends Document {
-  _id: string;
+export interface ICommunity extends Document {
+  _id: Types.ObjectId;
   name: string;
   creator_id: string;
   group: string;
   order_channels: Types.DocumentArray<IOrderChannel>;
   fee: number;
   earnings: number;
   orders_to_redeem: number;
   dispute_channel: string;
   solvers: Types.DocumentArray<IUsernameId>;
   banned_users: Types.DocumentArray<IUsernameId>;
   public: boolean;
   currencies: Array<string>;
   created_at: Date;
   nostr_public_key: string;
   warning_messages_count: number;
   language: string;
   orders?: number;
 }
🤖 Fix all issues with AI agents
In `@models/order.ts`:
- Line 4: The IOrder interface currently types _id as string which mismatches
MongoDB ObjectId; update the _id declaration in the IOrder interface to use
mongoose.Types.ObjectId instead of string (or remove the override so the
Document-provided type is used), and if you need string IDs in API output add a
toJSON transform or convert _id.toString() at the serialization boundary; look
for the IOrder interface and its _id field in models/order.ts to apply this
change.

In `@package.json`:
- Line 28: package.json was bumped to "mongoose": "^8.17.1" so run npm install
to update lockfile and node_modules, then ensure all deprecated Mongoose APIs
were migrated: replace any usage of Model.count(...) with
Model.countDocuments(...), and replace Model.remove(...) with
Model.deleteOne(...) or Model.deleteMany(...) as appropriate; run the test suite
and fix any type or runtime errors caused by the upgrade (check call sites of
count/countDocuments and remove/deleteOne) before committing.
🧹 Nitpick comments (2)
bot/ordersActions.ts (1)

302-302: Inconsistent use of .exec() across queries.

Adding .exec() is valid but optional in Mongoose 8.x since queries are already thenables. However, Order.find(where) at line 340 and other findOne calls in the codebase (e.g., bot/start.ts:583) don't use .exec(). Consider either removing .exec() here for consistency, or adding it uniformly across all query calls.

bot/modules/community/actions.ts (1)

63-65: Minor formatting inconsistency.

Missing space after if keyword on line 63. Per coding guidelines, Prettier formatting should be applied.

🔧 Suggested fix
-  if(community === null)
+  if (community === null)

@knocte
Copy link
Collaborator

knocte commented Jan 20, 2026

@Luquitasjeffrey please don't merge until CI is green.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants