Conversation
WalkthroughThis update introduces a generic repository pattern for Mongoose models, adding a Changes
Sequence Diagram(s)sequenceDiagram
participant App
participant Repository
participant MongooseModel
App->>Repository: Call CRUD or paginate method
Repository->>MongooseModel: Execute DB operation (create, find, update, delete, paginate)
MongooseModel-->>Repository: Return result
Repository-->>App: Return result
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (21)
src/connection.ts (2)
1-1: Fix type import for ConnectionThe
Connectionimport should use a type-only import as flagged by ESLint since it's only used as a type.-import mongoose, { Connection } from 'mongoose'; +import mongoose, { type Connection } from 'mongoose';🧰 Tools
🪛 ESLint
[error] 1-1: Import "Connection" is only used as types.
(@typescript-eslint/consistent-type-imports)
7-7: Fix typo in commentThere's a missing space between "constructor" and "to".
- // Private constructorto prevent direct instantiation + // Private constructor to prevent direct instantiationsrc/databaseManager.ts (1)
1-4: Fix type importsESLint flags that these imports are only used as types and should use the
typekeyword.-import { Snowflake } from 'discord.js'; -import mongoose, { Connection } from 'mongoose'; +import type { Snowflake } from 'discord.js'; +import mongoose, { type Connection } from 'mongoose'; -import { IChannel, IGuildMember, IHeatMap, IMemberActivity, IRawInfo, IRole } from './interfaces'; +import type { IChannel, IGuildMember, IHeatMap, IMemberActivity, IRawInfo, IRole } from './interfaces';🧰 Tools
🪛 ESLint
[error] 1-1: All imports in the declaration are only used as types. Use
import type.(@typescript-eslint/consistent-type-imports)
[error] 2-2: Import "Connection" is only used as types.
(@typescript-eslint/consistent-type-imports)
[error] 4-4: All imports in the declaration are only used as types. Use
import type.(@typescript-eslint/consistent-type-imports)
src/repositories/heatMap.repository.ts (1)
1-4: Useimport typefor type-only importsThe
Modelfrom 'mongoose' andIHeatMapfrom '../interfaces' are only used as types in this file. Follow TypeScript best practices by using theimport typesyntax for these imports:-import { Model } from 'mongoose'; +import type { Model } from 'mongoose'; import { BaseRepository } from './base.repository'; -import { IHeatMap } from '../interfaces'; +import type { IHeatMap } from '../interfaces'; import HeatMap from '../models/HeatMap.model';This helps with tree-shaking and makes the distinction between runtime dependencies and type dependencies clearer.
🧰 Tools
🪛 ESLint
[error] 1-1: All imports in the declaration are only used as types. Use
import type.(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use
import type.(@typescript-eslint/consistent-type-imports)
src/repositories/role.repository.ts (1)
1-4: Useimport typefor type-only importsThe
Modelfrom 'mongoose' andIRolefrom '../interfaces' are only used as types in this file. Follow TypeScript best practices by using theimport typesyntax for these imports:-import { Model } from 'mongoose'; +import type { Model } from 'mongoose'; import { BaseRepository } from './base.repository'; -import { IRole } from '../interfaces'; +import type { IRole } from '../interfaces'; import Role from '../models/Role.model';This follows TypeScript best practices and satisfies the ESLint rule requirements.
🧰 Tools
🪛 ESLint
[error] 1-1: All imports in the declaration are only used as types. Use
import type.(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use
import type.(@typescript-eslint/consistent-type-imports)
src/repositories/user.repository.ts (1)
1-4: Useimport typefor type-only importsThe
Modelfrom 'mongoose' andIUserfrom '../interfaces' are only used as types in this file. Follow TypeScript best practices by using theimport typesyntax for these imports:-import { Model } from 'mongoose'; +import type { Model } from 'mongoose'; import { BaseRepository } from './base.repository'; -import { IUser } from '../interfaces'; +import type { IUser } from '../interfaces'; import User from '../models/User.model';This change will satisfy the ESLint rules and maintain consistency throughout the codebase.
🧰 Tools
🪛 ESLint
[error] 1-1: All imports in the declaration are only used as types. Use
import type.(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use
import type.(@typescript-eslint/consistent-type-imports)
src/repositories/rawInfo.repository.ts (1)
1-3: Useimport typefor type-only importsThe
Modelfrom mongoose andIRawInfoare only used as types in this file. Consider usingimport typesyntax to improve tree-shaking and compilation output.-import { Model } from 'mongoose'; +import type { Model } from 'mongoose'; import { BaseRepository } from './base.repository'; -import { IRawInfo } from '../interfaces'; +import type { IRawInfo } from '../interfaces'; import RawInfo from '../models/RawInfo.model';🧰 Tools
🪛 ESLint
[error] 1-1: All imports in the declaration are only used as types. Use
import type.(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use
import type.(@typescript-eslint/consistent-type-imports)
src/repositories/guildMember.repository.ts (1)
1-3: Useimport typefor type-only importsThe
Modelfrom mongoose andIGuildMemberare only used as types in this file. Consider usingimport typesyntax to improve tree-shaking and compilation output.-import { Model } from 'mongoose'; +import type { Model } from 'mongoose'; import { BaseRepository } from './base.repository'; -import { IGuildMember } from '../interfaces'; +import type { IGuildMember } from '../interfaces'; import GuildMember from '../models/GuildMember.model';🧰 Tools
🪛 ESLint
[error] 1-1: All imports in the declaration are only used as types. Use
import type.(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use
import type.(@typescript-eslint/consistent-type-imports)
src/repositories/announcement.repository.ts (1)
1-3: Useimport typefor type-only importsThe
Modelfrom mongoose andIAnnouncementare only used as types in this file. Consider usingimport typesyntax to improve tree-shaking and compilation output.-import { Model } from 'mongoose'; +import type { Model } from 'mongoose'; import { BaseRepository } from './base.repository'; -import { IAnnouncement } from '../interfaces'; +import type { IAnnouncement } from '../interfaces'; import Announcement from '../models/Announcement.model';🧰 Tools
🪛 ESLint
[error] 1-1: All imports in the declaration are only used as types. Use
import type.(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use
import type.(@typescript-eslint/consistent-type-imports)
src/repositories/base.repository.ts (9)
1-1: Update the file comment path to match actual path.The file comment indicates
src/db/repositories/base.repository.tsbut the actual file path issrc/repositories/base.repository.ts.-// src/db/repositories/base.repository.ts +// src/repositories/base.repository.ts
2-2: Useimport typefor type-only imports.As indicated by the static analysis tool, consider using
import typefor type-only imports to improve bundle size and follow TypeScript best practices.-import { FilterQuery, LeanDocument, Model, PopulateOptions, ProjectionType, QueryOptions, UpdateQuery } from 'mongoose'; +import type { FilterQuery, LeanDocument, Model, PopulateOptions, ProjectionType, QueryOptions, UpdateQuery } from 'mongoose';🧰 Tools
🪛 ESLint
[error] 2-2: All imports in the declaration are only used as types. Use
import type.(@typescript-eslint/consistent-type-imports)
14-16: Remove redundantawaitwith return.When returning a Promise directly, the
awaitkeyword is redundant since the calling function is alreadyasync.- async create(doc: Partial<T>): Promise<T> { - return await this.model.create(doc); + async create(doc: Partial<T>): Promise<T> { + return this.model.create(doc);
18-20: Remove redundantawaitwith return.Same issue as in the
createmethod. Theawaitis unnecessary when directly returning a Promise.- async createMany(docs: Array<Partial<T>>): Promise<T[]> { - return await this.model.insertMany(docs); + async createMany(docs: Array<Partial<T>>): Promise<T[]> { + return this.model.insertMany(docs);
22-24: Remove redundantawaitwith return.Same issue as in previous methods.
- async findById(id: string, projection?: ProjectionType<T>, options?: QueryOptions): Promise<T | null> { - return await this.model.findById(id, projection, options); + async findById(id: string, projection?: ProjectionType<T>, options?: QueryOptions): Promise<T | null> { + return this.model.findById(id, projection, options);
26-28: Remove redundantawaitwith return.Same issue as in previous methods.
- async find(filter: FilterQuery<T>, projection?: ProjectionType<T>, options?: QueryOptions): Promise<T[]> { - return await this.model.find(filter, projection, options); + async find(filter: FilterQuery<T>, projection?: ProjectionType<T>, options?: QueryOptions): Promise<T[]> { + return this.model.find(filter, projection, options);
30-36: Remove redundantawaitwith return.Same issue as in previous methods.
- async updateOne( - filter: FilterQuery<T>, - update: UpdateQuery<T>, - options?: QueryOptions, - ): Promise<{ acknowledged: boolean; modifiedCount: number; upsertedId: unknown }> { - return await this.model.updateOne(filter, update, options); + async updateOne( + filter: FilterQuery<T>, + update: UpdateQuery<T>, + options?: QueryOptions, + ): Promise<{ acknowledged: boolean; modifiedCount: number; upsertedId: unknown }> { + return this.model.updateOne(filter, update, options);
38-40: Remove redundantawaitwith return.Same issue as in previous methods.
- async deleteOne(filter: FilterQuery<T>): Promise<{ deletedCount?: number }> { - return await this.model.deleteOne(filter); + async deleteOne(filter: FilterQuery<T>): Promise<{ deletedCount?: number }> { + return this.model.deleteOne(filter);
42-44: Remove redundantawaitwith return.Same issue as in previous methods.
- async deleteMany(filter: FilterQuery<T>): Promise<{ deletedCount?: number }> { - return await this.model.deleteMany(filter); + async deleteMany(filter: FilterQuery<T>): Promise<{ deletedCount?: number }> { + return this.model.deleteMany(filter);src/repositories/memberActivity.repository.ts (3)
1-1: Useimport typefor type-only imports.Model is only used as a type in the constructor parameter, not as a value.
-import { Model } from 'mongoose'; +import type { Model } from 'mongoose';🧰 Tools
🪛 ESLint
[error] 1-1: All imports in the declaration are only used as types. Use
import type.(@typescript-eslint/consistent-type-imports)
3-3: Useimport typefor interface imports.IMemberActivity is only used as a type, not as a value.
-import { IMemberActivity } from '../interfaces'; +import type { IMemberActivity } from '../interfaces';🧰 Tools
🪛 ESLint
[error] 3-3: All imports in the declaration are only used as types. Use
import type.(@typescript-eslint/consistent-type-imports)
6-10: Add documentation to the repository class.The repository class lacks any documentation explaining its purpose or any specific methods it might offer beyond those inherited from BaseRepository.
+/** + * Repository for managing member activity data. + * Extends the base repository with IMemberActivity type. + */ export class MemberActivityRepository extends BaseRepository<IMemberActivity> { constructor(model: Model<IMemberActivity> = MemberActivity) { super(model); } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (20)
CHANGELOG.md(0 hunks)README.md(2 hunks)src/connection.ts(1 hunks)src/databaseManager.ts(1 hunks)src/index.ts(1 hunks)src/repositories/announcement.repository.ts(1 hunks)src/repositories/base.repository.ts(1 hunks)src/repositories/channel.repository.ts(1 hunks)src/repositories/community.repository.ts(1 hunks)src/repositories/guildMember.repository.ts(1 hunks)src/repositories/heatMap.repository.ts(1 hunks)src/repositories/index.ts(1 hunks)src/repositories/memberActivity.repository.ts(1 hunks)src/repositories/module.repository.ts(1 hunks)src/repositories/platform.repository.ts(1 hunks)src/repositories/rawInfo.repository.ts(1 hunks)src/repositories/role.repository.ts(1 hunks)src/repositories/token.repository.ts(1 hunks)src/repositories/user.repository.ts(1 hunks)src/service/index.ts(0 hunks)
💤 Files with no reviewable changes (2)
- CHANGELOG.md
- src/service/index.ts
🧰 Additional context used
🧬 Code Graph Analysis (10)
src/repositories/platform.repository.ts (4)
src/repositories/index.ts (2)
BaseRepository(16-16)platformRepository(26-26)src/repositories/base.repository.ts (1)
BaseRepository(11-58)src/interfaces/Platfrom.interface.ts (1)
IPlatform(4-10)src/models/index.ts (1)
Platform(23-23)
src/repositories/announcement.repository.ts (2)
src/repositories/base.repository.ts (1)
BaseRepository(11-58)src/interfaces/Announcement.interface.ts (1)
IAnnouncement(18-31)
src/repositories/community.repository.ts (2)
src/repositories/base.repository.ts (1)
BaseRepository(11-58)src/interfaces/Community.interface.ts (1)
ICommunity(14-21)
src/repositories/token.repository.ts (2)
src/repositories/base.repository.ts (1)
BaseRepository(11-58)src/interfaces/Token.interface.ts (1)
IToken(4-11)
src/repositories/module.repository.ts (4)
src/repositories/index.ts (2)
BaseRepository(16-16)moduleRepository(28-28)src/repositories/base.repository.ts (1)
BaseRepository(11-58)src/interfaces/Module.interface.ts (1)
IModule(5-16)src/models/index.ts (1)
Module(25-25)
src/repositories/channel.repository.ts (4)
src/repositories/index.ts (2)
BaseRepository(16-16)channelRepository(23-23)src/repositories/base.repository.ts (1)
BaseRepository(11-58)src/interfaces/Channel.interface.ts (1)
IChannel(11-18)src/models/index.ts (1)
Channel(20-20)
src/repositories/user.repository.ts (2)
src/repositories/base.repository.ts (1)
BaseRepository(11-58)src/interfaces/User.interface.ts (1)
IUser(9-13)
src/repositories/memberActivity.repository.ts (4)
src/repositories/index.ts (2)
BaseRepository(16-16)memberActivityRepository(21-21)src/repositories/base.repository.ts (1)
BaseRepository(11-58)src/interfaces/MemberActivity.interface.ts (1)
IMemberActivity(3-25)src/models/index.ts (1)
MemberActivity(18-18)
src/repositories/role.repository.ts (4)
src/repositories/index.ts (2)
BaseRepository(16-16)roleRepository(24-24)src/repositories/base.repository.ts (1)
BaseRepository(11-58)src/interfaces/Role.interface.ts (1)
IRole(4-9)src/models/index.ts (1)
Role(21-21)
src/repositories/rawInfo.repository.ts (4)
src/repositories/index.ts (2)
BaseRepository(16-16)rawInfoRepository(20-20)src/repositories/base.repository.ts (1)
BaseRepository(11-58)src/interfaces/RawInfo.interface.ts (1)
IRawInfo(4-19)src/models/index.ts (1)
RawInfo(17-17)
🪛 ESLint
src/repositories/platform.repository.ts
[error] 1-1: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
src/connection.ts
[error] 1-1: Import "Connection" is only used as types.
(@typescript-eslint/consistent-type-imports)
src/repositories/announcement.repository.ts
[error] 1-1: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
src/repositories/community.repository.ts
[error] 1-1: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
src/repositories/token.repository.ts
[error] 1-1: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
src/repositories/module.repository.ts
[error] 1-1: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
src/repositories/channel.repository.ts
[error] 1-1: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
src/repositories/user.repository.ts
[error] 1-1: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
src/databaseManager.ts
[error] 1-1: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
[error] 2-2: Import "Connection" is only used as types.
(@typescript-eslint/consistent-type-imports)
[error] 4-4: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
src/repositories/guildMember.repository.ts
[error] 1-1: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
src/repositories/heatMap.repository.ts
[error] 1-1: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
src/repositories/memberActivity.repository.ts
[error] 1-1: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
src/repositories/base.repository.ts
[error] 2-2: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
src/repositories/role.repository.ts
[error] 1-1: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
src/repositories/rawInfo.repository.ts
[error] 1-1: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
[error] 3-3: All imports in the declaration are only used as types. Use import type.
(@typescript-eslint/consistent-type-imports)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: ci / build-push / Build + Push Image
🔇 Additional comments (25)
README.md (1)
88-88: Appropriate spacing additionThis blank line addition improves readability by properly separating the Module interface section from the Heatmap interface section.
src/index.ts (1)
5-7: Good organization of exportsThe new exports provide direct access to database functionality and the newly introduced repositories. This is a good architectural change that aligns with the repository pattern being introduced.
src/databaseManager.ts (1)
5-12: Well-organized schema importsThe reordering of schema imports improves code organization by grouping related schemas together, which is a good practice.
src/repositories/token.repository.ts (2)
6-10: Looks good - clean implementation of repository patternThe TokenRepository class properly extends the BaseRepository with the correct interface type, and allows for dependency injection of a different model if needed. This follows good software design principles.
12-13: Good approach providing both named and default exportsExporting both the instance and the default provides flexibility for consumers of this module.
src/repositories/module.repository.ts (2)
6-10: Implementation follows the repository pattern correctlyThe ModuleRepository class correctly extends BaseRepository with the IModule interface type, and the dependency injection pattern is implemented properly.
12-13: Consistent export patternThe export pattern is consistent with other repository classes, providing both a named singleton export and a default export.
src/repositories/community.repository.ts (2)
6-10: Clean implementation of the repository patternThe CommunityRepository implementation follows the same clean pattern as the other repositories, correctly extending BaseRepository with the proper interface type.
12-13: Export pattern is consistentThe exports follow the same pattern as other repository modules, which is good for maintaining consistency across the codebase.
src/repositories/channel.repository.ts (2)
6-10: Implementation aligns with repository design patternThe ChannelRepository properly extends BaseRepository with the correct interface type, and follows the same pattern used consistently across all repository classes.
12-13: Export approach is consistentProviding both a named export for the singleton instance and a default export maintains consistency with the other repository modules.
src/repositories/heatMap.repository.ts (2)
6-10: LGTM: Repository class implementation is cleanThe implementation correctly extends BaseRepository with the appropriate generic type parameter and passes the model to the base constructor. This pattern is well-structured and allows for easy dependency injection for testing.
12-13: LGTM: Consistent export patternExporting both a named and default instance of the repository follows a consistent pattern, providing flexibility for different import styles.
src/repositories/role.repository.ts (1)
6-13: LGTM: Repository implementation and exports are well-structuredThe implementation follows a consistent repository pattern, extending the BaseRepository with proper type parameters and providing both named and default exports of the repository instance. This is a clean approach that maintains consistency across the codebase.
src/repositories/platform.repository.ts (1)
6-13: LGTM: Repository implementation and exports are consistentThe implementation follows the same consistent repository pattern as other repositories, extending the BaseRepository with proper type parameters and providing both named and default exports of the repository instance.
src/repositories/user.repository.ts (1)
6-13: LGTM: User repository follows the established patternThe implementation follows the same clean and consistent repository pattern as the other repositories, extending BaseRepository with proper type parameters and providing both named and default exports of the repository instance.
src/repositories/rawInfo.repository.ts (2)
6-10: LGTM! Repository pattern implementation is cleanThe RawInfoRepository correctly extends the BaseRepository with the appropriate type parameter and passes the model to the base class.
12-13: LGTM! Singleton instance export provides convenient accessExporting both named and default exports provides flexibility for consumers of this module.
src/repositories/guildMember.repository.ts (2)
6-10: LGTM! Repository pattern implementation is cleanThe GuildMemberRepository correctly extends the BaseRepository with the appropriate type parameter and passes the model to the base class.
12-13: LGTM! Singleton instance export provides convenient accessExporting both named and default exports provides flexibility for consumers of this module.
src/repositories/index.ts (2)
1-14: LGTM! Well-organized importsThe imports are structured in a logical manner, starting with the base repository class followed by all specialized repository instances.
15-29: LGTM! Effective centralization of repository exportsThis export pattern provides a single entry point for all repository functionality, which simplifies imports in consumer code.
src/repositories/announcement.repository.ts (2)
6-10: LGTM! Repository pattern implementation is cleanThe AnnouncementRepository correctly extends the BaseRepository with the appropriate type parameter and passes the model to the base class.
12-13: LGTM! Singleton instance export provides convenient accessExporting both named and default exports provides flexibility for consumers of this module.
src/repositories/memberActivity.repository.ts (1)
12-13: LGTM: Repository instance export pattern is consistent.The pattern of exporting a singleton instance both as a named export and default export is consistent with the repository pattern being implemented.
Summary by CodeRabbit
New Features
Refactor
Chores