Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

194
Views
How do I do this in typescript/adonis?

I found an example on bitbucket of paginating the results of a query, but it was written in java script, and I'm having a little trouble declaring the types.

and getting this error on this line

const pagination:TPagination = usersResults.toJSON()

The type '{ meta: any; data: ModelObject[]; }' does not have the following properties of type

        ***sample code****
          async index ({ view, params, request, response }) {
            const page = params.page || 1
            const search = request.input('search') || ''
            const employees = await Employee.query()
                                            .where('name', 'LIKE', '%' + search + '%')
                                            .paginate(page, 10)
            const pagination = employees.toJSON()
            pagination.route = 'employees.pagination'
            if(pagination.lastPage < page && page != 1) {
              response.route(pagination.route, { page: 1 }, null, true)
            }
            else {
              pagination.offset = (pagination.page - 1) * pagination.perPage
              pagination.search = search
              return view.render('employees.index', { employees: pagination })
            }
          }

        }
         ***my code***
        public async searchByName ({request,params, response}: HttpContextContract) {   
                interface TPagination {
                    route: string;
                    lastPage: number;
                    offset:number;
                    search:string;
                    page:number;
                    perPage:number;
                    [key: string]: any;
                    meta: any;
                    data: ModelObject[];

                           
                } 
                try {
                    const page = params.page || 1
                    const search = request.input('search') || ''
                    const usersResults = await User.query()
                                                    .where('name', 'LIKE', '%' + search + '%')
                                                    .orWhere('cns','LIKE','%'+   search +'%')
                                                    .paginate(page, 10)
                    const pagination:TPagination = usersResults.toJSON()
                    pagination.route = 'pagination.users'
                    if(pagination.lastPage < page && page != 1) {
                        response.redirect().toRoute(pagination.route, { page: 1 })
                    }
                    else {
                      pagination.offset = (pagination.page - 1) * pagination.perPage
                      pagination.search = search
                    }

                } catch {
                    return response.status(400).json('{"error":"Usuário não encontrado!"}');
                }
            
            }   
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!