ppetzold / nestjs-paginate

Pagination and filtering helper method for TypeORM repositories or query builders using Nest.js framework :book::paperclip:
MIT License
448 stars 100 forks source link

Remove the host & protocol part of the links section using the `origin` property #961

Open samislam opened 3 months ago

samislam commented 3 months ago

I wanted to perform this and I thought it's gonna work:

 const dbEntries = await paginate(query, this.clientsRepo, {
      sortableColumns: getColumns(this.clientsRepo, true).names,
      select: getColumns(this.clientsRepo, true).names,
      origin: '', //  👈
    })

But it didn't, I wanted to change the links.cuurent origin, from:

 "links": {
        "current": "http://localhost:3001/clients?page=1&limit=20&sortBy=accountType:ASC&select=username,accountType"
    }

to

 "links": {
        "current": "/clients?page=1&limit=20&sortBy=accountType:ASC&select=username,accountType"
    }

But it doesn't work, I also tried to put "/", but it resulted in double slashes as follows:

 "links": {
        "current": "//clients?page=1&limit=20&sortBy=accountType:ASC&select=username,accountType"
    }

I think this is because the library somewhere in its code checks on the property if it exists by some approach like this:

if(!!origin) { /* do the `origin` logic */ }

I think it should handle this case by something like this:

if(origin == "" ||  !!origin) { /* do the `origin` logic */ }
Helveg commented 3 months ago

I like origin '/' more as a notation for this than ''. We'd love to see a PR for this with a test that verifies this works as expected :)