Skip to content
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

add the ability to import the paginate options #68

Open
itszaki01 opened this issue Jan 3, 2025 · 0 comments
Open

add the ability to import the paginate options #68

itszaki01 opened this issue Jan 3, 2025 · 0 comments

Comments

@itszaki01
Copy link

itszaki01 commented Jan 3, 2025

import { paginate } from "mongoose-paginate-v2";

the example above is from mongoose-paginate-v2 I can import the paginate to set global options across all the schemas, but in "mongoose-aggregate-paginate-v2" it's not included so I need to add paginate options to every schema manually please I hope that can be added to make work more perfect

// Here is full example

import { Module, OnModuleInit } from "@nestjs/common";
import { InjectConnection, MongooseModule } from "@nestjs/mongoose";
import { Connection } from "mongoose";
import { EnviromentsClass } from "src/utils/enviromentsClass";
import * as mongooseAggregatePaginate from "mongoose-aggregate-paginate-v2";
import * as paginateall from "mongoose-paginate-v2";
import { paginate } from "mongoose-paginate-v2";

import { paginate } from "mongoose-aggregate-paginate-v2" // not found


@Module({
    imports: [
        MongooseModule.forRootAsync({
            useFactory: () => {
                return {
                    uri: EnviromentsClass.DB_URI,
                    connectionFactory: (connection: Connection) => {
                        const customLabels = {
                            totalDocs: "total_docs",
                            docs: "docs",
                            limit: "limit",
                            page: "current_page",
                            nextPage: "next",
                            prevPage: "prev",
                            totalPages: "total_pages",
                        };

                        // Config pagination plugin
                        paginate.options = {
                            customLabels,
                        };

                
                        //Inject Plugins
                        connection.plugin(paginateall);
                        connection.plugin(mongooseAggregatePaginate);

                        return connection;
                    },
                };
            },
        }),
    ],
})
export class MongoModule implements OnModuleInit {
    constructor(@InjectConnection() private readonly connection: Connection) {}

    onModuleInit() {
        // mongoose.set('debug',true)
        console.log("Mongoose connected successfully");
    }
}

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

No branches or pull requests

1 participant