-
Notifications
You must be signed in to change notification settings - Fork 4
201 extend mongolib #202
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
201 extend mongolib #202
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| export * from './models'; | ||
| export * from './models/schemas'; | ||
| export * from './interfaces'; | ||
| export * from './service'; | ||
| export * from './config/enums'; | ||
| export * from './databaseManager'; | ||
| export * from './connection'; | ||
| export * from './repositories'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Model } from 'mongoose'; | ||
| import { BaseRepository } from './base.repository'; | ||
| import { IAnnouncement } from '../interfaces'; | ||
| import Announcement from '../models/Announcement.model'; | ||
|
|
||
| export class AnnouncementRepository extends BaseRepository<IAnnouncement> { | ||
| constructor(model: Model<IAnnouncement> = Announcement) { | ||
| super(model); | ||
| } | ||
| } | ||
|
|
||
| export const announcementRepository = new AnnouncementRepository(); | ||
| export default announcementRepository; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // src/db/repositories/base.repository.ts | ||
| import { FilterQuery, LeanDocument, Model, PopulateOptions, ProjectionType, QueryOptions, UpdateQuery } from 'mongoose'; | ||
|
|
||
| export interface PaginateOptions { | ||
| page?: number; | ||
| limit?: number; | ||
| sortBy?: string; | ||
| populate?: string | PopulateOptions | Array<string | PopulateOptions>; | ||
| } | ||
|
|
||
| export class BaseRepository<T> { | ||
| constructor(private readonly model: Model<T>) {} | ||
|
|
||
| async create(doc: Partial<T>): Promise<T> { | ||
| return await this.model.create(doc); | ||
| } | ||
|
|
||
| async createMany(docs: Array<Partial<T>>): Promise<T[]> { | ||
| return await this.model.insertMany(docs); | ||
| } | ||
|
|
||
| async findById(id: string, projection?: ProjectionType<T>, options?: QueryOptions): Promise<T | null> { | ||
| return await this.model.findById(id, projection, options); | ||
| } | ||
|
|
||
| async find(filter: FilterQuery<T>, projection?: ProjectionType<T>, options?: QueryOptions): Promise<T[]> { | ||
| return await this.model.find(filter, projection, options); | ||
| } | ||
|
|
||
| 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 deleteOne(filter: FilterQuery<T>): Promise<{ deletedCount?: number }> { | ||
| return await this.model.deleteOne(filter); | ||
| } | ||
|
|
||
| async deleteMany(filter: FilterQuery<T>): Promise<{ deletedCount?: number }> { | ||
| return await this.model.deleteMany(filter); | ||
| } | ||
|
|
||
| async paginate( | ||
| filter: FilterQuery<T>, | ||
| options: PaginateOptions, | ||
| ): Promise<{ | ||
| results: Array<LeanDocument<T>>; | ||
| page: number; | ||
| limit: number; | ||
| totalPages: number; | ||
| totalResults: number; | ||
| }> { | ||
| return (this.model as any).paginate(filter, options); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Model } from 'mongoose'; | ||
| import { BaseRepository } from './base.repository'; | ||
| import { IChannel } from '../interfaces'; | ||
| import Channel from '../models/Channel.model'; | ||
Behzad-rabiei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export class ChannelRepository extends BaseRepository<IChannel> { | ||
| constructor(model: Model<IChannel> = Channel) { | ||
| super(model); | ||
| } | ||
| } | ||
|
|
||
| export const channelRepository = new ChannelRepository(); | ||
| export default channelRepository; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Model } from 'mongoose'; | ||
| import { BaseRepository } from './base.repository'; | ||
| import { ICommunity } from '../interfaces'; | ||
| import Community from '../models/Community.model'; | ||
Behzad-rabiei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export class CommunityRepository extends BaseRepository<ICommunity> { | ||
| constructor(model: Model<ICommunity> = Community) { | ||
| super(model); | ||
| } | ||
| } | ||
|
|
||
| export const communityRepository = new CommunityRepository(); | ||
| export default communityRepository; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Model } from 'mongoose'; | ||
| import { BaseRepository } from './base.repository'; | ||
| import { IGuildMember } from '../interfaces'; | ||
| import GuildMember from '../models/GuildMember.model'; | ||
|
|
||
| export class GuildMemberRepository extends BaseRepository<IGuildMember> { | ||
| constructor(model: Model<IGuildMember> = GuildMember) { | ||
| super(model); | ||
| } | ||
| } | ||
|
|
||
| export const guildMemberRepository = new GuildMemberRepository(); | ||
| export default guildMemberRepository; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Model } from 'mongoose'; | ||
| import { BaseRepository } from './base.repository'; | ||
| import { IHeatMap } from '../interfaces'; | ||
| import HeatMap from '../models/HeatMap.model'; | ||
|
|
||
| export class HeatMapRepository extends BaseRepository<IHeatMap> { | ||
| constructor(model: Model<IHeatMap> = HeatMap) { | ||
| super(model); | ||
| } | ||
| } | ||
|
|
||
| export const heatMapRepository = new HeatMapRepository(); | ||
| export default heatMapRepository; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { BaseRepository } from './base.repository'; | ||
| import userRepository from './user.repository'; | ||
| import tokenRepository from './token.repository'; | ||
| import heatMapRepository from './heatMap.repository'; | ||
| import rawInfoRepository from './rawInfo.repository'; | ||
| import memberActivityRepository from './memberActivity.repository'; | ||
| import guildMemberRepository from './guildMember.repository'; | ||
| import channelRepository from './channel.repository'; | ||
| import roleRepository from './role.repository'; | ||
| import communityRepository from './community.repository'; | ||
| import platformRepository from './platform.repository'; | ||
| import announcementRepository from './announcement.repository'; | ||
| import moduleRepository from './module.repository'; | ||
|
|
||
| export { | ||
| BaseRepository, | ||
| userRepository, | ||
| tokenRepository, | ||
| heatMapRepository, | ||
| rawInfoRepository, | ||
| memberActivityRepository, | ||
| guildMemberRepository, | ||
| channelRepository, | ||
| roleRepository, | ||
| communityRepository, | ||
| platformRepository, | ||
| announcementRepository, | ||
| moduleRepository, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Model } from 'mongoose'; | ||
| import { BaseRepository } from './base.repository'; | ||
| import { IMemberActivity } from '../interfaces'; | ||
| import MemberActivity from '../models/memberActivity.model'; | ||
|
|
||
| export class MemberActivityRepository extends BaseRepository<IMemberActivity> { | ||
| constructor(model: Model<IMemberActivity> = MemberActivity) { | ||
| super(model); | ||
| } | ||
| } | ||
|
|
||
| export const memberActivityRepository = new MemberActivityRepository(); | ||
| export default memberActivityRepository; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Model } from 'mongoose'; | ||
| import { BaseRepository } from './base.repository'; | ||
| import { IModule } from '../interfaces'; | ||
| import Module from '../models/Module.model'; | ||
Behzad-rabiei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export class ModuleRepository extends BaseRepository<IModule> { | ||
| constructor(model: Model<IModule> = Module) { | ||
| super(model); | ||
| } | ||
| } | ||
|
|
||
| export const moduleRepository = new ModuleRepository(); | ||
| export default moduleRepository; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Model } from 'mongoose'; | ||
| import { BaseRepository } from './base.repository'; | ||
| import { IPlatform } from '../interfaces'; | ||
| import Platform from '../models/Platfrom.model'; | ||
Behzad-rabiei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export class PlatformRepository extends BaseRepository<IPlatform> { | ||
| constructor(model: Model<IPlatform> = Platform) { | ||
| super(model); | ||
| } | ||
| } | ||
|
|
||
| export const platformRepository = new PlatformRepository(); | ||
| export default platformRepository; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Model } from 'mongoose'; | ||
| import { BaseRepository } from './base.repository'; | ||
| import { IRawInfo } from '../interfaces'; | ||
| import RawInfo from '../models/RawInfo.model'; | ||
|
|
||
| export class RawInfoRepository extends BaseRepository<IRawInfo> { | ||
| constructor(model: Model<IRawInfo> = RawInfo) { | ||
| super(model); | ||
| } | ||
| } | ||
|
|
||
| export const rawInfoRepository = new RawInfoRepository(); | ||
| export default rawInfoRepository; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Model } from 'mongoose'; | ||
| import { BaseRepository } from './base.repository'; | ||
| import { IRole } from '../interfaces'; | ||
| import Role from '../models/Role.model'; | ||
|
|
||
| export class RoleRepository extends BaseRepository<IRole> { | ||
| constructor(model: Model<IRole> = Role) { | ||
| super(model); | ||
| } | ||
| } | ||
|
|
||
| export const roleRepository = new RoleRepository(); | ||
| export default roleRepository; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Model } from 'mongoose'; | ||
| import { BaseRepository } from './base.repository'; | ||
| import { IToken } from '../interfaces'; | ||
| import Token from '../models/Token.model'; | ||
Behzad-rabiei marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export class TokenRepository extends BaseRepository<IToken> { | ||
| constructor(model: Model<IToken> = Token) { | ||
| super(model); | ||
| } | ||
| } | ||
|
|
||
| export const tokenRepository = new TokenRepository(); | ||
| export default tokenRepository; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Model } from 'mongoose'; | ||
| import { BaseRepository } from './base.repository'; | ||
| import { IUser } from '../interfaces'; | ||
| import User from '../models/User.model'; | ||
|
|
||
| export class UserRepository extends BaseRepository<IUser> { | ||
| constructor(model: Model<IUser> = User) { | ||
| super(model); | ||
| } | ||
| } | ||
|
|
||
| export const userRepository = new UserRepository(); | ||
| export default userRepository; |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.